From 255e9c24b66e69eecab030ad25aa63f6595d3bac Mon Sep 17 00:00:00 2001 From: AbdelrahmanElawady Date: Tue, 30 Apr 2024 21:52:47 +0300 Subject: [PATCH] Remove unused flag and continue on error Signed-off-by: AbdelrahmanElawady --- pkg/KubeArmorOperator/cmd/snitch-cmd/main.go | 1 - pkg/KubeArmorOperator/hook/crio.go | 10 ++++++---- pkg/KubeArmorOperator/hook/main.go | 2 -- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/KubeArmorOperator/cmd/snitch-cmd/main.go b/pkg/KubeArmorOperator/cmd/snitch-cmd/main.go index 3771c637d1..7390ba6db8 100644 --- a/pkg/KubeArmorOperator/cmd/snitch-cmd/main.go +++ b/pkg/KubeArmorOperator/cmd/snitch-cmd/main.go @@ -198,7 +198,6 @@ func applyCRIOHook(socket string) error { "/usr/share/kubearmor/hook", "--runtime-socket", socket, - "--k8s", }, }, When: hooks.When{Always: &always}, diff --git a/pkg/KubeArmorOperator/hook/crio.go b/pkg/KubeArmorOperator/hook/crio.go index c26727ec54..301420b22c 100644 --- a/pkg/KubeArmorOperator/hook/crio.go +++ b/pkg/KubeArmorOperator/hook/crio.go @@ -6,6 +6,7 @@ package main import ( "context" "encoding/json" + "log" "github.com/kubearmor/KubeArmor/KubeArmor/types" "github.com/opencontainers/runtime-spec/specs-go" @@ -53,7 +54,8 @@ func (h *crioHandler) listContainers(ctx context.Context) ([]types.Container, er for _, container := range containersList.GetContainers() { c, err := h.getContainer(ctx, container.GetId()) if err != nil { - return nil, err + log.Printf("failed to get container %q: %s", container.GetId(), err.Error()) + continue } containers = append(containers, c) } @@ -84,11 +86,11 @@ func containerFromContainerStatus(status *runtime.ContainerStatus, info string) container.NamespaceName = "Unknown" container.EndPointName = "Unknown" - containerLables := status.Labels - if val, ok := containerLables["io.kubernetes.pod.namespace"]; ok { + containerLabels := status.Labels + if val, ok := containerLabels["io.kubernetes.pod.namespace"]; ok { container.NamespaceName = val } - if val, ok := containerLables["io.kubernetes.pod.name"]; ok { + if val, ok := containerLabels["io.kubernetes.pod.name"]; ok { container.EndPointName = val } diff --git a/pkg/KubeArmorOperator/hook/main.go b/pkg/KubeArmorOperator/hook/main.go index 7adb47fd7e..5b6503976c 100644 --- a/pkg/KubeArmorOperator/hook/main.go +++ b/pkg/KubeArmorOperator/hook/main.go @@ -25,14 +25,12 @@ import ( var ( kubeArmorSocket string runtimeSocket string - k8s bool detached bool ) func main() { flag.StringVar(&kubeArmorSocket, "kubearmor-socket", "/var/run/kubearmor/ka.sock", "KubeArmor socket") flag.StringVar(&runtimeSocket, "runtime-socket", "", "container runtime socket") - flag.BoolVar(&k8s, "k8s", false, "kubernetes environment") flag.BoolVar(&detached, "detached", false, "run detached") flag.Parse()