Skip to content

Commit

Permalink
Update label and add debug print statement for KubeArmor pods
Browse files Browse the repository at this point in the history
Signed-off-by: Ishaan Jain <ishaan454@gmail.com>

added print statement stating that function checks all pods with kubearmor-app label

Signed-off-by: Ishaan Jain <ishaan454@gmail.com>
  • Loading branch information
Ishaanj18 committed Jul 23, 2024
1 parent b626440 commit cd32c2b
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,40 @@ func Collect(c *k8s.Client, o Options) error {
// KubeArmor Pod
errs.Go(func() error {
pods, err := c.K8sClientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
LabelSelector: "kubearmor-app=kubearmor",
LabelSelector: "kubearmor-app",
})

if err != nil {
fmt.Printf("kubearmor pod not found. (possible if kubearmor is running in process mode)\n")
return nil
} else {
fmt.Print("Checking all pods labeled with kubearmor-app\n")
}

for _, p := range pods.Items {
// KubeArmor Logs
fmt.Printf("getting logs from %s\n", p.Name)

v := c.K8sClientset.CoreV1().Pods(p.Namespace).GetLogs(p.Name, &corev1.PodLogOptions{})
s, err := v.Stream(context.Background())
if err != nil {
fmt.Printf("failed getting logs from pod=%s err=%s\n", p.Name, err)
continue
}
defer func() {
if err := s.Close(); err != nil {
kg.Warnf("Error closing io stream %s\n", err)
// Iterate over containers in the pod
for _, container := range p.Spec.Containers {

// KubeArmor Logs
fmt.Printf("getting logs from pod=%s container=%s\n", p.Name, container.Name)
v := c.K8sClientset.CoreV1().Pods(p.Namespace).GetLogs(p.Name, &corev1.PodLogOptions{Container: container.Name})
s, err := v.Stream(context.Background())
if err != nil {
fmt.Printf("failed getting logs from pod=%s err=%s\n", p.Name, err)
continue
}
defer func() {
if err := s.Close(); err != nil {
kg.Warnf("Error closing io stream %s\n", err)
}
}()
var logs bytes.Buffer
if _, err = io.Copy(&logs, s); err != nil {
return err
}
if err := writeToFile(path.Join(d, "ka-pod-"+p.Name+"-log.txt"), logs.String()); err != nil {
return err
}
}()
var logs bytes.Buffer
if _, err = io.Copy(&logs, s); err != nil {
return err
}
if err := writeToFile(path.Join(d, "ka-pod-"+p.Name+"-log.txt"), logs.String()); err != nil {
return err
}

// KubeArmor Describe
Expand Down Expand Up @@ -173,7 +179,7 @@ func Collect(c *k8s.Client, o Options) error {
return nil
})

// AppArmor Gzip
// AppArmor GzipS
errs.Go(func() error {
if err := copyFromPod("/etc/apparmor.d", d, c); err != nil {
return err
Expand Down

0 comments on commit cd32c2b

Please sign in to comment.