-
Notifications
You must be signed in to change notification settings - Fork 42.5k
Kubelet: Add alpha-2 stage implementation for UserNamespacesHostNetworkSupport feature gate #135828
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
HirazawaUi
wants to merge
1
commit into
kubernetes:master
Choose a base branch
from
HirazawaUi:5607-alpha-2-stage
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
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
68 changes: 68 additions & 0 deletions
68
...s/nodedeclaredfeatures/features/usernamespaceshostnetwork/user_namespaces_host_network.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,68 @@ | ||
| /* | ||
| 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 usernamespaceshostnetwork | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/util/version" | ||
| "k8s.io/component-helpers/nodedeclaredfeatures" | ||
| ) | ||
|
|
||
| // Ensure the feature struct implements the unified Feature interface. | ||
| var _ nodedeclaredfeatures.Feature = &userNamespacesHostNetworkFeature{} | ||
|
|
||
| const ( | ||
| // UserNamespacesHostNetworkSupportFeatureGate is the feature gate name. | ||
| UserNamespacesHostNetworkSupportFeatureGate = "UserNamespacesHostNetworkSupport" | ||
| // UserNamespacesHostNetworkSupport is the declared feature name. | ||
| UserNamespacesHostNetworkSupport = "UserNamespacesHostNetworkSupport" | ||
| ) | ||
|
|
||
| // Feature is the implementation of the `UserNamespacesHostNetworkSupport` feature. | ||
| var Feature = &userNamespacesHostNetworkFeature{} | ||
|
|
||
| type userNamespacesHostNetworkFeature struct{} | ||
|
|
||
| func (f *userNamespacesHostNetworkFeature) Name() string { | ||
| return UserNamespacesHostNetworkSupport | ||
| } | ||
|
|
||
| func (f *userNamespacesHostNetworkFeature) Discover(cfg *nodedeclaredfeatures.NodeConfiguration) bool { | ||
| // This feature requires both the feature gate to be enabled AND | ||
| // runtime-level support for user namespaces with host network. | ||
| if !cfg.FeatureGates.Enabled(UserNamespacesHostNetworkSupportFeatureGate) { | ||
| return false | ||
| } | ||
|
|
||
| return cfg.RuntimeFeatures.UserNamespacesHostNetwork | ||
| } | ||
|
|
||
| func (f *userNamespacesHostNetworkFeature) InferForScheduling(podInfo *nodedeclaredfeatures.PodInfo) bool { | ||
| // A pod needs this feature if it uses both host network AND user namespaces. | ||
| if podInfo.Spec.HostNetwork && podInfo.Spec.HostUsers != nil && !*podInfo.Spec.HostUsers { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (f *userNamespacesHostNetworkFeature) InferForUpdate(oldPodInfo, newPodInfo *nodedeclaredfeatures.PodInfo) bool { | ||
| // HostNetwork and HostUsers fields are immutable, so no update inference is needed. | ||
| return false | ||
| } | ||
|
|
||
| func (f *userNamespacesHostNetworkFeature) MaxVersion() *version.Version { | ||
| return nil | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
...edeclaredfeatures/features/usernamespaceshostnetwork/user_namespaces_host_network_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,91 @@ | ||
| /* | ||
| 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 usernamespaceshostnetwork | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "k8s.io/component-helpers/nodedeclaredfeatures" | ||
| test "k8s.io/component-helpers/nodedeclaredfeatures/testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestDiscoverFeature(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| featureGate bool | ||
| runtimeFeatures nodedeclaredfeatures.RuntimeFeatures | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "feature gate disabled", | ||
| featureGate: false, | ||
| runtimeFeatures: nodedeclaredfeatures.RuntimeFeatures{ | ||
| UserNamespacesHostNetwork: true, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "feature gate enabled but no runtime support", | ||
| featureGate: true, | ||
| runtimeFeatures: nodedeclaredfeatures.RuntimeFeatures{ | ||
| UserNamespacesHostNetwork: false, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "feature gate enabled and runtime supports it", | ||
| featureGate: true, | ||
| runtimeFeatures: nodedeclaredfeatures.RuntimeFeatures{ | ||
| UserNamespacesHostNetwork: true, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "runtime support is on", | ||
| featureGate: true, | ||
| runtimeFeatures: nodedeclaredfeatures.RuntimeFeatures{ | ||
| UserNamespacesHostNetwork: true, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "runtime support is off", | ||
| featureGate: true, | ||
| runtimeFeatures: nodedeclaredfeatures.RuntimeFeatures{ | ||
| UserNamespacesHostNetwork: false, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| mockFG := test.NewMockFeatureGate(t) | ||
| mockFG.EXPECT().Enabled(UserNamespacesHostNetworkSupportFeatureGate).Return(tt.featureGate) | ||
|
|
||
| cfg := &nodedeclaredfeatures.NodeConfiguration{ | ||
| FeatureGates: mockFG, | ||
| RuntimeFeatures: tt.runtimeFeatures, | ||
| } | ||
|
|
||
| result := Feature.Discover(cfg) | ||
| assert.Equal(t, tt.expected, result) | ||
| }) | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.