Skip to content

Commit 1b40b8c

Browse files
authored
[cluster agent][autoscaling] fix target hash check (#44910)
### What does this PR do? Fixes behavior if a target NodePool is not found in the cluster for an inferred NodePool ### Motivation Fix unintended behavior when patching nodepools ### Describe how you validated your changes In a test cluster pointing to staging, made sure inferred NodePools could be patched properly ### Additional Notes Co-authored-by: celene <[email protected]>
1 parent 0e29828 commit 1b40b8c

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pkg/clusteragent/autoscaling/cluster/controller.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ func (c *Controller) syncNodePool(ctx context.Context, name string, nodePool *ka
153153
log.Errorf("Error converting Target NodePool: %v", err)
154154
return autoscaling.Requeue
155155
}
156-
}
157156

158-
// Only create or update if there is no TargetHash (i.e. it is fully Datadog-managed), or if the TargetHash has not changed
159-
if !checkTargetHash(npi, targetNp) {
160-
log.Infof("NodePool: %s TargetHash (%s) has changed since recommendation was generated; no action will be applied.", npi.Name(), npi.TargetHash())
161-
return autoscaling.NoRequeue
157+
// Only create or update if the TargetHash has not changed
158+
if npi.TargetHash() != targetNp.GetAnnotations()[model.KarpenterNodePoolHashAnnotationKey] {
159+
log.Infof("NodePool: %s TargetHash (%s) has changed since recommendation was generated; no action will be applied.", npi.Name(), npi.TargetHash())
160+
return autoscaling.NoRequeue
161+
}
162162
}
163163

164164
if nodePool == nil {
@@ -190,13 +190,6 @@ func (c *Controller) syncNodePool(ctx context.Context, name string, nodePool *ka
190190
return autoscaling.NoRequeue
191191
}
192192

193-
func checkTargetHash(npi model.NodePoolInternal, targetNp *karpenterv1.NodePool) bool {
194-
if targetNp == nil {
195-
return false
196-
}
197-
return npi.TargetHash() == "" || npi.TargetHash() == targetNp.GetAnnotations()[model.KarpenterNodePoolHashAnnotationKey]
198-
}
199-
200193
func (c *Controller) createNodePool(ctx context.Context, npi model.NodePoolInternal, knp *karpenterv1.NodePool) error {
201194
log.Infof("Creating NodePool: %s", npi.Name())
202195

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fix small bug in Cluster Autoscaling when checking Target Hash value.

0 commit comments

Comments
 (0)