From 253baede48340402de96f834e7901389271e5d67 Mon Sep 17 00:00:00 2001 From: Shreya2005-2005 Date: Sun, 10 May 2026 05:09:28 +0000 Subject: [PATCH] refactor: extract bootstrapAnnotationKey helper function Duplicate fmt.Sprintf format string existed in isBootstrapCompleted and markBootstrapCompleted. Extract into bootstrapAnnotationKey(ruleName) to prevent silent divergence if one is updated independently. Fixes #232 Signed-off-by: Shreya2005-2005 --- internal/controller/node_controller.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/controller/node_controller.go b/internal/controller/node_controller.go index 9dc596a..046365f 100644 --- a/internal/controller/node_controller.go +++ b/internal/controller/node_controller.go @@ -317,6 +317,12 @@ func (r *RuleReadinessController) removeTaintBySpec(ctx context.Context, node *c } // Bootstrap completion tracking. +// bootstrapAnnotationKey returns the annotation key used to track bootstrap +// completion for a given rule. +func bootstrapAnnotationKey(ruleName string) string { + return fmt.Sprintf("readiness.k8s.io/bootstrap-completed-%s", ruleName) +} + func (r *RuleReadinessController) isBootstrapCompleted(ctx context.Context, nodeName, ruleName string) bool { // Check node annotation node := &corev1.Node{} @@ -324,7 +330,7 @@ func (r *RuleReadinessController) isBootstrapCompleted(ctx context.Context, node return false } - annotationKey := fmt.Sprintf("readiness.k8s.io/bootstrap-completed-%s", ruleName) + annotationKey := bootstrapAnnotationKey(ruleName) _, exists := node.Annotations[annotationKey] return exists } @@ -332,7 +338,7 @@ func (r *RuleReadinessController) isBootstrapCompleted(ctx context.Context, node func (r *RuleReadinessController) markBootstrapCompleted(ctx context.Context, nodeName, ruleName string) { log := ctrl.LoggerFrom(ctx) - annotationKey := fmt.Sprintf("readiness.k8s.io/bootstrap-completed-%s", ruleName) + annotationKey := bootstrapAnnotationKey(ruleName) marked := false // retry to handle conflict with concurrent node updates