@@ -56,6 +56,59 @@ var _ = Describe("NodeClaim/Drift", func() {
56
56
// NodeClaims are required to be launched before they can be evaluated for drift
57
57
nodeClaim .StatusConditions ().MarkTrue (v1beta1 .Launched )
58
58
})
59
+ Context ("Metrics" , func () {
60
+ It ("should fire a karpenter_nodeclaims_drifted metric when drifted" , func () {
61
+ cp .Drifted = "CloudProviderDrifted"
62
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
63
+ ExpectReconcileSucceeded (ctx , nodeClaimDisruptionController , client .ObjectKeyFromObject (nodeClaim ))
64
+
65
+ nodeClaim = ExpectExists (ctx , env .Client , nodeClaim )
66
+ Expect (nodeClaim .StatusConditions ().GetCondition (v1beta1 .Drifted ).IsTrue ()).To (BeTrue ())
67
+ metric , found := FindMetricWithLabelValues ("karpenter_nodeclaims_drifted" , map [string ]string {
68
+ "type" : "CloudProviderDrifted" ,
69
+ "nodepool" : nodePool .Name ,
70
+ })
71
+ Expect (found ).To (BeTrue ())
72
+ Expect (metric .GetCounter ().GetValue ()).To (BeNumerically ("==" , 1 ))
73
+ })
74
+ It ("should pass-through the correct drifted type value through the karpenter_nodeclaims_drifted metric" , func () {
75
+ cp .Drifted = "drifted"
76
+ nodePool .Spec .Template .Spec .Requirements = []v1.NodeSelectorRequirement {
77
+ {
78
+ Key : v1 .LabelInstanceTypeStable ,
79
+ Operator : v1 .NodeSelectorOpDoesNotExist ,
80
+ },
81
+ }
82
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
83
+ ExpectReconcileSucceeded (ctx , nodeClaimDisruptionController , client .ObjectKeyFromObject (nodeClaim ))
84
+
85
+ nodeClaim = ExpectExists (ctx , env .Client , nodeClaim )
86
+ Expect (nodeClaim .StatusConditions ().GetCondition (v1beta1 .Drifted ).IsTrue ()).To (BeTrue ())
87
+ Expect (nodeClaim .StatusConditions ().GetCondition (v1beta1 .Drifted ).Reason ).To (Equal (string (disruption .RequirementsDrifted )))
88
+
89
+ metric , found := FindMetricWithLabelValues ("karpenter_nodeclaims_drifted" , map [string ]string {
90
+ "type" : "RequirementsDrifted" ,
91
+ "nodepool" : nodePool .Name ,
92
+ })
93
+ Expect (found ).To (BeTrue ())
94
+ Expect (metric .GetCounter ().GetValue ()).To (BeNumerically ("==" , 1 ))
95
+ })
96
+ It ("should fire a karpenter_nodeclaims_disrupted metric when drifted" , func () {
97
+ cp .Drifted = "drifted"
98
+ ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
99
+ ExpectReconcileSucceeded (ctx , nodeClaimDisruptionController , client .ObjectKeyFromObject (nodeClaim ))
100
+
101
+ nodeClaim = ExpectExists (ctx , env .Client , nodeClaim )
102
+ Expect (nodeClaim .StatusConditions ().GetCondition (v1beta1 .Drifted ).IsTrue ()).To (BeTrue ())
103
+
104
+ metric , found := FindMetricWithLabelValues ("karpenter_nodeclaims_disrupted" , map [string ]string {
105
+ "type" : "drift" ,
106
+ "nodepool" : nodePool .Name ,
107
+ })
108
+ Expect (found ).To (BeTrue ())
109
+ Expect (metric .GetCounter ().GetValue ()).To (BeNumerically ("==" , 1 ))
110
+ })
111
+ })
59
112
It ("should detect drift" , func () {
60
113
cp .Drifted = "drifted"
61
114
ExpectApplied (ctx , env .Client , nodePool , nodeClaim )
0 commit comments