-
Notifications
You must be signed in to change notification settings - Fork 57
fix(controller): handle long rule names in bootstrap annotation keys #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kubernetes-prow
merged 1 commit into
kubernetes-sigs:main
from
vishnukothakapu:fix-annotation-key-length
Jul 7, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| Copyright The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| ) | ||
|
|
||
| func TestBootstrapAnnotationKey(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| uid := types.UID("550e8400-e29b-41d4-a716-446655440000") | ||
| key := bootstrapAnnotationKey(uid) | ||
| g.Expect(key).To(Equal("readiness.k8s.io/bootstrap-completed-550e8400-e29b-41d4-a716-446655440000")) | ||
| } | ||
|
|
||
| func TestBootstrapAnnotationValue(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| t.Run("encodes rule name as JSON", func(t *testing.T) { | ||
| val := bootstrapAnnotationValue("my-rule") | ||
| g.Expect(val).To(Equal(`{"rule-name":"my-rule"}`)) | ||
| }) | ||
|
|
||
| t.Run("handles long rule names", func(t *testing.T) { | ||
| longName := "my-very-long-rule-name-that-exceeds-the-63-character-annotation-key-limit-strictly" | ||
| val := bootstrapAnnotationValue(longName) | ||
| g.Expect(val).To(ContainSubstring(longName)) | ||
| }) | ||
| } | ||
|
|
||
| func TestLegacyBootstrapAnnotationKey(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| key := legacyBootstrapAnnotationKey("my-rule") | ||
| g.Expect(key).To(Equal("readiness.k8s.io/bootstrap-completed-my-rule")) | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
internal/controller/node_controller_reproduction_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| Copyright The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
| "k8s.io/client-go/tools/record" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
|
||
| nodereadinessiov1alpha1 "sigs.k8s.io/node-readiness-controller/api/v1alpha1" | ||
| ) | ||
|
|
||
| var _ = Describe("Node Controller Reproduction", func() { | ||
| Context("when reconciling a node with a very long rule name", func() { | ||
| var ( | ||
| ctx context.Context | ||
| readinessController *RuleReadinessController | ||
| nodeReconciler *NodeReconciler | ||
| fakeClientset *fake.Clientset | ||
| node *corev1.Node | ||
| rule *nodereadinessiov1alpha1.NodeReadinessRule | ||
| longRuleName = "my-very-long-rule-name-that-exceeds-the-annotation-key-limit-strictly" | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ctx = context.Background() | ||
|
|
||
| fakeClientset = fake.NewSimpleClientset() | ||
| readinessController = &RuleReadinessController{ | ||
| Client: k8sClient, | ||
| Scheme: k8sClient.Scheme(), | ||
| clientset: fakeClientset, | ||
| ruleCache: make(map[string]*nodereadinessiov1alpha1.NodeReadinessRule), | ||
| EventRecorder: record.NewFakeRecorder(10), | ||
| } | ||
|
|
||
| nodeReconciler = &NodeReconciler{ | ||
| Client: k8sClient, | ||
| Scheme: k8sClient.Scheme(), | ||
| Controller: readinessController, | ||
| } | ||
|
|
||
| node = &corev1.Node{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "repro-node", | ||
| Labels: map[string]string{"env": "repro"}, | ||
| }, | ||
| Status: corev1.NodeStatus{ | ||
| Conditions: []corev1.NodeCondition{ | ||
| {Type: "ReproCondition", Status: corev1.ConditionTrue}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| rule = &nodereadinessiov1alpha1.NodeReadinessRule{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: longRuleName, | ||
| }, | ||
| Spec: nodereadinessiov1alpha1.NodeReadinessRuleSpec{ | ||
| Conditions: []nodereadinessiov1alpha1.ConditionRequirement{ | ||
| {Type: "ReproCondition", RequiredStatus: corev1.ConditionTrue}, | ||
| }, | ||
| Taint: corev1.Taint{ | ||
| Key: "readiness.k8s.io/repro-taint", | ||
| Effect: corev1.TaintEffectNoSchedule, | ||
| }, | ||
| NodeSelector: metav1.LabelSelector{ | ||
| MatchLabels: map[string]string{"env": "repro"}, | ||
| }, | ||
| EnforcementMode: nodereadinessiov1alpha1.EnforcementModeBootstrapOnly, | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| JustBeforeEach(func() { | ||
| Expect(k8sClient.Create(ctx, node)).To(Succeed()) | ||
| Expect(k8sClient.Create(ctx, rule)).To(Succeed()) | ||
| readinessController.updateRuleCache(ctx, rule) | ||
| }) | ||
|
|
||
| AfterEach(func() { | ||
| _ = k8sClient.Delete(ctx, node) | ||
| updatedRule := &nodereadinessiov1alpha1.NodeReadinessRule{} | ||
| if err := k8sClient.Get(ctx, types.NamespacedName{Name: longRuleName}, updatedRule); err == nil { | ||
| updatedRule.Finalizers = nil | ||
| _ = k8sClient.Update(ctx, updatedRule) | ||
| _ = k8sClient.Delete(ctx, updatedRule) | ||
| } | ||
| readinessController.removeRuleFromCache(ctx, longRuleName) | ||
| }) | ||
|
|
||
| It("should successfully mark bootstrap completed using the UID-based annotation key for long rule names", func() { | ||
| // Trigger reconciliation | ||
| _, err := nodeReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Name: "repro-node"}}) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| recheckedNode := &corev1.Node{} | ||
| Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "repro-node"}, recheckedNode)).To(Succeed()) | ||
|
|
||
| // The bootstrap annotation key uses the rule's UID as the suffix, | ||
| // so even very long rule names never violate the 63-char key limit. | ||
| uidKey := bootstrapAnnotationKey(rule.GetUID()) | ||
| Expect(recheckedNode.Annotations).To(HaveKey(uidKey), | ||
| "UID-based bootstrap annotation should be present on the node") | ||
|
|
||
| // The annotation value should contain the full rule name for readability. | ||
| Expect(recheckedNode.Annotations[uidKey]).To(ContainSubstring(longRuleName), | ||
| "annotation value should contain the full rule name for human readability") | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker: Should we make this a generic rule annotation instead of being bootstrap specific? This would let us reuse it for other properties later, like showing a rule's dryRun status.
cc @ajaysundark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Not opposed to making it generic. Wanted to flag one thing, if reconciles ever run concurrently, a single annotation could cause read-modify-write races. If we go generic, we'd need to be careful there. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree to not increase the scope for this change. We can handle this as a bug fix for now.
I think scoped annotation with readiness.k8s.io prefix will scale better than global/single metadata.. let us discuss the other use cases individually.