forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Add node maintenance window controller #7
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
Open
ujjwal-devzy
wants to merge
1
commit into
master
Choose a base branch
from
feat/node-maintenance-windows
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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,74 @@ | ||
| /* | ||
| Copyright 2025 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 nodemaintenance | ||
|
|
||
| import "sync" | ||
|
|
||
| // concurrencyLimiter bounds how many nodes may be under active maintenance | ||
| // (cordoned + draining) at the same time, cluster-wide. It is safe for | ||
| // concurrent use. | ||
| type concurrencyLimiter struct { | ||
| mu sync.Mutex | ||
| tokens chan struct{} | ||
| } | ||
|
|
||
| // newConcurrencyLimiter returns a limiter that allows up to max concurrent | ||
| // holders. | ||
| func newConcurrencyLimiter(max int) *concurrencyLimiter { | ||
| if max < 0 { | ||
| max = 0 | ||
| } | ||
| return &concurrencyLimiter{tokens: make(chan struct{}, max)} | ||
| } | ||
|
|
||
| // TryAcquire attempts to claim a slot without blocking. It returns false if | ||
| // the limiter is already at capacity. | ||
| func (l *concurrencyLimiter) TryAcquire() bool { | ||
| l.mu.Lock() | ||
| tokens := l.tokens | ||
| l.mu.Unlock() | ||
|
|
||
| select { | ||
| case tokens <- struct{}{}: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // Release frees a previously-acquired slot. | ||
| func (l *concurrencyLimiter) Release() { | ||
| l.mu.Lock() | ||
| tokens := l.tokens | ||
| l.mu.Unlock() | ||
|
|
||
| select { | ||
| case <-tokens: | ||
| default: | ||
| } | ||
| } | ||
|
|
||
| // Resize changes the limiter's capacity to max, for example after the | ||
| // maintenance policy ConfigMap is edited. | ||
| func (l *concurrencyLimiter) Resize(max int) { | ||
| if max < 0 { | ||
| max = 0 | ||
| } | ||
| l.mu.Lock() | ||
| defer l.mu.Unlock() | ||
| l.tokens = make(chan struct{}, max) | ||
| } |
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,105 @@ | ||
| /* | ||
| Copyright 2025 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 nodemaintenance | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestConcurrencyLimiter_AcquireUpToCapacity(t *testing.T) { | ||
| l := newConcurrencyLimiter(2) | ||
|
|
||
| if !l.TryAcquire() { | ||
| t.Fatal("first TryAcquire() = false, want true") | ||
| } | ||
| if !l.TryAcquire() { | ||
| t.Fatal("second TryAcquire() = false, want true") | ||
| } | ||
| if l.TryAcquire() { | ||
| t.Fatal("third TryAcquire() = true, want false (at capacity)") | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_ReleaseFreesASlot(t *testing.T) { | ||
| l := newConcurrencyLimiter(1) | ||
|
|
||
| if !l.TryAcquire() { | ||
| t.Fatal("TryAcquire() = false, want true") | ||
| } | ||
| if l.TryAcquire() { | ||
| t.Fatal("TryAcquire() while full = true, want false") | ||
| } | ||
|
|
||
| l.Release() | ||
|
|
||
| if !l.TryAcquire() { | ||
| t.Fatal("TryAcquire() after Release() = false, want true") | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_ZeroCapacityNeverAcquires(t *testing.T) { | ||
| l := newConcurrencyLimiter(0) | ||
| if l.TryAcquire() { | ||
| t.Fatal("TryAcquire() on a zero-capacity limiter = true, want false") | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_NegativeCapacityClampsToZero(t *testing.T) { | ||
| l := newConcurrencyLimiter(-3) | ||
| if l.TryAcquire() { | ||
| t.Fatal("TryAcquire() on a negative-capacity limiter = true, want false") | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_ResizeUp(t *testing.T) { | ||
| l := newConcurrencyLimiter(1) | ||
| if !l.TryAcquire() { | ||
| t.Fatal("TryAcquire() = false, want true") | ||
| } | ||
|
|
||
| l.Resize(3) | ||
|
|
||
| acquired := 0 | ||
| for i := 0; i < 3; i++ { | ||
| if l.TryAcquire() { | ||
| acquired++ | ||
| } | ||
| } | ||
| if acquired != 3 { | ||
| t.Errorf("acquired %d slots after resizing to 3, want 3", acquired) | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_ResizeDown(t *testing.T) { | ||
| l := newConcurrencyLimiter(5) | ||
| l.Resize(1) | ||
|
|
||
| if !l.TryAcquire() { | ||
| t.Fatal("first TryAcquire() after shrinking = false, want true") | ||
| } | ||
| if l.TryAcquire() { | ||
| t.Fatal("second TryAcquire() after shrinking to 1 = true, want false") | ||
| } | ||
| } | ||
|
|
||
| func TestConcurrencyLimiter_ReleaseWithoutAcquireIsSafe(t *testing.T) { | ||
| l := newConcurrencyLimiter(1) | ||
| // Should not panic or block. | ||
| l.Release() | ||
|
|
||
| if !l.TryAcquire() { | ||
| t.Fatal("TryAcquire() after a spurious Release() = false, want true") | ||
| } | ||
| } |
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.
🟡 Medium
NodeMaintenance controller is added to the always-registered set without feature-gate or disabled-by-default
The new controller is registered alongside long-established controllers (outside the
// feature gatedblock) and its descriptor does not setrequiredFeatureGatesorisDisabledByDefault. In kube-controller-manager, this typically means it will run by default when--controllers=*(or default controller set) is used.Given this controller cordons/drains nodes, default-enabling is a high-impact behavior change if clusters have (or later add) the triggering annotations/configmap. Consider marking it feature-gated or disabled-by-default until the feature is GA.
Concrete mitigation (minimum): disable by default in the descriptor:
🛠️ Code Suggestions
func newNodeMaintenanceControllerDescriptor() *ControllerDescriptor { return &ControllerDescriptor{ name: names.NodeMaintenanceController, - aliases: []string{"node-maintenance"}, + // Consider gating/alpha rollout; at minimum don't auto-enable. + isDisabledByDefault: true, + aliases: []string{"node-maintenance"}, constructor: newNodeMaintenanceController, } }🤖 AI Fix Prompt - Copy this into your AI coding agent
🔧 Fix in IDE — opens your editor with the fix prompt ready:
↑ Back to Summary