Skip to content

Commit 4467dd3

Browse files
authored
Merge pull request kubernetes#130028 from AkihiroSuda/subids-per-pod
kubelet: config: add userNamespaces.idsPerPod
2 parents f1c634f + 09fdae4 commit 4467dd3

File tree

16 files changed

+303
-61
lines changed

16 files changed

+303
-61
lines changed

api/api-rules/violation_exceptions.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ API rule violation: names_match,k8s.io/kube-proxy/config/v1alpha1,KubeProxyConfi
261261
API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,IPTablesDropBit
262262
API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,IPTablesMasqueradeBit
263263
API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,ResolverConfig
264+
API rule violation: names_match,k8s.io/kubelet/config/v1beta1,UserNamespaces,IDsPerPod
264265
API rule violation: names_match,k8s.io/metrics/pkg/apis/custom_metrics/v1beta1,MetricValue,WindowSeconds
265266
API rule violation: names_match,k8s.io/metrics/pkg/apis/external_metrics/v1beta1,ExternalMetricValue,WindowSeconds
266267
API rule violation: streaming_list_type_proto_tags,k8s.io/apimachinery/pkg/apis/meta/v1beta1,PartialObjectMetadataList,Items

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubelet/apis/config/helpers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,6 @@ var (
306306
"LocalStorageCapacityIsolation",
307307
"FailCgroupV1",
308308
"CrashLoopBackOff.MaxContainerRestartPeriod",
309+
"UserNamespaces.IDsPerPod",
309310
)
310311
)

pkg/kubelet/apis/config/types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ type KubeletConfiguration struct {
541541
// +featureGate=KubeletCrashLoopBackoffMax
542542
// +optional
543543
CrashLoopBackOff CrashLoopBackOffConfig
544+
545+
// UserNamespaces contains User Namespace configurations.
546+
// +featureGate=UserNamespaceSupport
547+
// +optional
548+
UserNamespaces *UserNamespaces
544549
}
545550

546551
// KubeletAuthorizationMode denotes the authorization mode for the kubelet
@@ -878,3 +883,17 @@ type ImagePullSecret struct {
878883
// content of the secret specified by the UID/Namespace/Name coordinates.
879884
CredentialHash string
880885
}
886+
887+
// UserNamespaces contains User Namespace configurations.
888+
type UserNamespaces struct {
889+
// IDsPerPod is the mapping length of UIDs and GIDs.
890+
// The length must be a multiple of 65536, and must be less than 1<<32.
891+
// On non-linux such as windows, only null / absent is allowed.
892+
//
893+
// Changing the value may require recreating all containers on the node.
894+
//
895+
// Default: 65536
896+
// +featureGate=UserNamespaceSupport
897+
// +optional
898+
IDsPerPod *int64
899+
}

pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubelet/apis/config/validation/validation_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ package validation
2121

2222
import (
2323
"fmt"
24+
"math"
2425

2526
libcontainercgroups "github.com/opencontainers/cgroups"
2627
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
2728
"k8s.io/utils/ptr"
2829
)
2930

31+
const userNsUnitLength = 65536
32+
3033
// validateKubeletOSConfiguration validates os specific kubelet configuration and returns an error if it is invalid.
3134
func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) error {
3235
isCgroup1 := !libcontainercgroups.IsCgroup2UnifiedMode()
@@ -38,5 +41,20 @@ func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) erro
3841
return fmt.Errorf("invalid configuration: singleProcessOOMKill must not be explicitly set to false when using cgroup v1")
3942
}
4043

44+
if userNs := kc.UserNamespaces; userNs != nil {
45+
if idsPerPod := userNs.IDsPerPod; idsPerPod != nil {
46+
if *idsPerPod < userNsUnitLength {
47+
return fmt.Errorf("invalid configuration: userNamespaces.idsPerPod must not be less than %d", userNsUnitLength)
48+
}
49+
if *idsPerPod%userNsUnitLength != 0 {
50+
return fmt.Errorf("invalid configuration: userNamespaces.idsPerPod must be a multiple of %d", userNsUnitLength)
51+
}
52+
if *idsPerPod > math.MaxUint32 {
53+
// int64() is needed for 32-bit targets
54+
return fmt.Errorf("invalid configuration: userNamespaces.idsPerPod must not be more than %d", int64(math.MaxUint32))
55+
}
56+
}
57+
}
58+
4159
return nil
4260
}

pkg/kubelet/apis/config/validation/validation_others.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) erro
3131
return fmt.Errorf("invalid configuration: singleProcessOOMKill is only supported on linux")
3232
}
3333

34+
if kc.UserNamespaces != nil {
35+
return fmt.Errorf("invalid configuration: userNamespaces is only supported on linux")
36+
}
37+
3438
return nil
3539
}

pkg/kubelet/apis/config/validation/validation_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ func validateKubeletOSConfiguration(kc *kubeletconfig.KubeletConfiguration) erro
4646
klog.Warningf(message, "EnforceNodeAllocatable", "--enforce-node-allocatable", kc.EnforceNodeAllocatable)
4747
}
4848

49+
if kc.UserNamespaces != nil {
50+
return fmt.Errorf("invalid configuration: userNamespaces is not supported on Windows")
51+
}
52+
4953
return nil
5054
}

pkg/kubelet/apis/config/zz_generated.deepcopy.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubelet/config/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ const (
3030
KubeletPluginsDirSELinuxLabel = "system_u:object_r:container_file_t:s0"
3131
KubeletContainersSharedSELinuxLabel = "system_u:object_r:container_file_t:s0"
3232
DefaultKubeletCheckpointsDirName = "checkpoints"
33+
DefaultKubeletUserNamespacesIDsPerPod = 65536
3334
)

0 commit comments

Comments
 (0)