@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/samber/lo"
25
25
corev1 "k8s.io/api/core/v1"
26
+ "k8s.io/apimachinery/pkg/api/equality"
26
27
"k8s.io/apimachinery/pkg/types"
27
28
"k8s.io/apimachinery/pkg/util/intstr"
28
29
@@ -120,10 +121,18 @@ func (c *Controller) Reconcile(ctx context.Context, node *corev1.Node) (reconcil
120
121
if err := c .annotateTerminationGracePeriod (ctx , nodeClaim ); err != nil {
121
122
return reconcile.Result {}, client .IgnoreNotFound (err )
122
123
}
124
+
125
+ return c .deleteNodeClaim (ctx , nodeClaim , node , unhealthyNodeCondition )
126
+ }
127
+
128
+ // deleteNodeClaim removes the NodeClaim from the api-server
129
+ func (c * Controller ) deleteNodeClaim (ctx context.Context , nodeClaim * v1.NodeClaim , node * corev1.Node , unhealthyNodeCondition * corev1.NodeCondition ) (reconcile.Result , error ) {
130
+ if ! nodeClaim .DeletionTimestamp .IsZero () {
131
+ return reconcile.Result {}, nil
132
+ }
123
133
if err := c .kubeClient .Delete (ctx , nodeClaim ); err != nil {
124
134
return reconcile.Result {}, client .IgnoreNotFound (err )
125
135
}
126
-
127
136
// The deletion timestamp has successfully been set for the Node, update relevant metrics.
128
137
log .FromContext (ctx ).V (1 ).Info ("deleting unhealthy node" )
129
138
metrics .NodeClaimsDisruptedTotal .Inc (map [string ]string {
@@ -155,11 +164,22 @@ func (c *Controller) findUnhealthyConditions(node *corev1.Node) (nc *corev1.Node
155
164
}
156
165
157
166
func (c * Controller ) annotateTerminationGracePeriod (ctx context.Context , nodeClaim * v1.NodeClaim ) error {
167
+ if expirationTimeString , exists := nodeClaim .ObjectMeta .Annotations [v1 .NodeClaimTerminationTimestampAnnotationKey ]; exists {
168
+ expirationTime , err := time .Parse (time .RFC3339 , expirationTimeString )
169
+ if err == nil && expirationTime .Before (c .clock .Now ()) {
170
+ return nil
171
+ }
172
+ }
173
+
158
174
stored := nodeClaim .DeepCopy ()
159
- nodeClaim .ObjectMeta .Annotations = lo .Assign (nodeClaim .ObjectMeta .Annotations , map [string ]string {v1 .NodeClaimTerminationTimestampAnnotationKey : c .clock .Now ().Format (time .RFC3339 )})
175
+ terminationTime := c .clock .Now ().Format (time .RFC3339 )
176
+ nodeClaim .ObjectMeta .Annotations = lo .Assign (nodeClaim .ObjectMeta .Annotations , map [string ]string {v1 .NodeClaimTerminationTimestampAnnotationKey : terminationTime })
160
177
161
- if err := c .kubeClient .Patch (ctx , nodeClaim , client .MergeFrom (stored )); err != nil {
162
- return err
178
+ if ! equality .Semantic .DeepEqual (stored , nodeClaim ) {
179
+ if err := c .kubeClient .Patch (ctx , nodeClaim , client .MergeFrom (stored )); err != nil {
180
+ return err
181
+ }
182
+ log .FromContext (ctx ).WithValues (v1 .NodeClaimTerminationTimestampAnnotationKey , terminationTime ).Info ("annotated nodeclaim" )
163
183
}
164
184
165
185
return nil
0 commit comments