diff --git a/pkg/controllers/disruption/suite_test.go b/pkg/controllers/disruption/suite_test.go index 116a6c2e84..6c0708218a 100644 --- a/pkg/controllers/disruption/suite_test.go +++ b/pkg/controllers/disruption/suite_test.go @@ -1492,7 +1492,7 @@ var _ = Describe("Candidate Filtering", func() { Expect(cluster.Nodes()).To(HaveLen(1)) _, err := disruption.NewCandidate(ctx, env.Client, recorder, fakeClock, cluster.Nodes()[0], pdbLimits, nodePoolMap, nodePoolInstanceTypeMap, queue, disruption.GracefulDisruptionClass) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("state node doesn't contain both a node and a nodeclaim")) + Expect(err.Error()).To(Equal("state node does not have a nodeclaim representation")) }) It("should not consider candidate that has just a NodeClaim representation", func() { nodeClaim, _ := test.NodeClaimAndNode(v1.NodeClaim{ @@ -1511,7 +1511,7 @@ var _ = Describe("Candidate Filtering", func() { Expect(cluster.Nodes()).To(HaveLen(1)) _, err := disruption.NewCandidate(ctx, env.Client, recorder, fakeClock, cluster.Nodes()[0], pdbLimits, nodePoolMap, nodePoolInstanceTypeMap, queue, disruption.GracefulDisruptionClass) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("state node doesn't contain both a node and a nodeclaim")) + Expect(err.Error()).To(Equal("state node does not have a node representation")) }) It("should not consider candidates that are nominated", func() { nodeClaim, node := test.NodeClaimAndNode(v1.NodeClaim{ diff --git a/pkg/controllers/disruption/types.go b/pkg/controllers/disruption/types.go index 4d4f201754..d98e2fe243 100644 --- a/pkg/controllers/disruption/types.go +++ b/pkg/controllers/disruption/types.go @@ -72,7 +72,10 @@ func NewCandidate(ctx context.Context, kubeClient client.Client, recorder events var err error var pods []*corev1.Pod if err = node.ValidateNodeDisruptable(ctx, kubeClient); err != nil { - recorder.Publish(disruptionevents.Blocked(node.Node, node.NodeClaim, err.Error())...) + // Only emit an event if the NodeClaim is not nil, ensuring that we only emit events for Karpenter-managed nodes + if node.NodeClaim != nil { + recorder.Publish(disruptionevents.Blocked(node.Node, node.NodeClaim, err.Error())...) + } return nil, err } // If the orchestration queue is already considering a candidate we want to disrupt, don't consider it a candidate. diff --git a/pkg/controllers/state/statenode.go b/pkg/controllers/state/statenode.go index 1809ccc1c6..b70e127b30 100644 --- a/pkg/controllers/state/statenode.go +++ b/pkg/controllers/state/statenode.go @@ -189,8 +189,11 @@ func (in *StateNode) Pods(ctx context.Context, kubeClient client.Client) ([]*cor // //nolint:gocyclo func (in *StateNode) ValidateNodeDisruptable(ctx context.Context, kubeClient client.Client) error { - if in.Node == nil || in.NodeClaim == nil { - return fmt.Errorf("state node doesn't contain both a node and a nodeclaim") + if in.NodeClaim == nil { + return fmt.Errorf("state node does not have a nodeclaim representation") + } + if in.Node == nil { + return fmt.Errorf("state node does not have a node representation") } if !in.Initialized() { return fmt.Errorf("state node isn't initialized")