Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in listing daemonset pods #18

Closed
andrewtengson opened this issue Jul 25, 2024 · 0 comments · Fixed by #19
Closed

Bug in listing daemonset pods #18

andrewtengson opened this issue Jul 25, 2024 · 0 comments · Fixed by #19
Assignees
Labels
bug Something isn't working

Comments

@andrewtengson
Copy link

In https://github.com/pelotech/nidhogg/blob/main/pkg/nidhogg/handler.go#L256, there's a bug in the pod matching loop where the address of the loop variable is being appended to the matchingPods slice. This results in all elements of matchingPods pointing to the same memory location (the last processed pod), rather than distinct pods.

Possible fix is to copy the pod to a new variable before appending it to the list:

  matchingPods := make([]*corev1.Pod, 0)
  for _, pod := range pods.Items {
    for _, owner := range pod.OwnerReferences {
      if owner.Name == ds.Name && pod.Spec.NodeName == nodeName {
        p := pod
        matchingPods = append(matchingPods, &p)
      }
    }
  }

See: https://stackoverflow.com/questions/45967305/copying-the-address-of-a-loop-variable-in-go

@scoquelin scoquelin self-assigned this Aug 6, 2024
@chomatdam chomatdam added the bug Something isn't working label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants