Skip to content

Commit

Permalink
Fix daemonset calculation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Feb 6, 2025
1 parent 204531a commit 0df35a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/state/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ func (c *Cluster) UpdateDaemonSet(ctx context.Context, daemonset *appsv1.DaemonS
if len(pods.Items) == 0 {
return nil
}
pod := &pods.Items[0]
var pod *corev1.Pod
for _, p := range pods.Items {
if metav1.IsControlledBy(&p, daemonset) && p.CreationTimestamp.After(pod.CreationTimestamp.Time) {
if metav1.IsControlledBy(&p, daemonset) && (pod == nil || p.CreationTimestamp.After(pod.CreationTimestamp.Time)) {
pod = &p
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/controllers/state/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,22 @@ var _ = Describe("DaemonSet Controller", func() {

Expect(cluster.GetDaemonSetPod(daemonset)).To(BeNil())
})
It("should only return daemonset pods from the daemonset cache", func() {
daemonset := test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
ResourceRequirements: corev1.ResourceRequirements{Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("1"), corev1.ResourceMemory: resource.MustParse("1Gi")}},
}},
)
ExpectApplied(ctx, env.Client, daemonset)
otherPods := test.Pods(1000, test.PodOptions{
ObjectMeta: metav1.ObjectMeta{
Namespace: daemonset.Namespace,
},
})
ExpectApplied(ctx, env.Client, lo.Map(otherPods, func(p *corev1.Pod, _ int) client.Object { return p })...)
ExpectReconcileSucceeded(ctx, daemonsetController, client.ObjectKeyFromObject(daemonset))
Expect(cluster.GetDaemonSetPod(daemonset)).To(BeNil())
})
})

var _ = Describe("Consolidated State", func() {
Expand Down

0 comments on commit 0df35a3

Please sign in to comment.