-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Add validation of kubelet and kube-proxy configuration in kubeadm. #56280
Changes from all commits
737c0ec
845a10f
da971d8
1e26acf
cf97d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ import ( | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/constants" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/features" | ||
kubeletscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme" | ||
kubeletconfigv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1alpha1" | ||
kubeproxyscheme "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/scheme" | ||
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1" | ||
|
@@ -110,7 +112,9 @@ func SetDefaults_MasterConfiguration(obj *MasterConfiguration) { | |
} | ||
|
||
SetDefaultsEtcdSelfHosted(obj) | ||
SetDefaults_KubeletConfiguration(obj) | ||
if features.Enabled(obj.FeatureGates, features.DynamicKubeletConfig) { | ||
SetDefaults_KubeletConfiguration(obj) | ||
} | ||
SetDefaults_ProxyConfiguration(obj) | ||
} | ||
|
||
|
@@ -200,4 +204,9 @@ func SetDefaults_KubeletConfiguration(obj *MasterConfiguration) { | |
if obj.KubeletConfiguration.BaseConfig.CAdvisorPort == nil { | ||
obj.KubeletConfiguration.BaseConfig.CAdvisorPort = utilpointer.Int32Ptr(0) | ||
} | ||
|
||
scheme, _, _ := kubeletscheme.NewSchemeAndCodecs() | ||
if scheme != nil { | ||
scheme.Default(obj.KubeletConfiguration.BaseConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,9 @@ import ( | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" | ||
kubeletconfigv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1alpha1" | ||
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1" | ||
"k8s.io/kubernetes/pkg/util/pointer" | ||
utilpointer "k8s.io/kubernetes/pkg/util/pointer" | ||
) | ||
|
||
func TestValidateTokenDiscovery(t *testing.T) { | ||
|
@@ -337,10 +338,25 @@ func TestValidateMasterConfiguration(t *testing.T) { | |
}, | ||
KubeProxy: kubeadm.KubeProxy{ | ||
Config: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{ | ||
BindAddress: "192.168.59.103", | ||
HealthzBindAddress: "0.0.0.0:10256", | ||
MetricsBindAddress: "127.0.0.1:10249", | ||
ClusterCIDR: "192.168.59.0/24", | ||
UDPIdleTimeout: metav1.Duration{Duration: 1 * time.Second}, | ||
ConfigSyncPeriod: metav1.Duration{Duration: 1 * time.Second}, | ||
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{ | ||
MasqueradeAll: true, | ||
SyncPeriod: metav1.Duration{Duration: 5 * time.Second}, | ||
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, | ||
}, | ||
IPVS: kubeproxyconfigv1alpha1.KubeProxyIPVSConfiguration{ | ||
SyncPeriod: metav1.Duration{Duration: 10 * time.Second}, | ||
MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second}, | ||
}, | ||
Conntrack: kubeproxyconfigv1alpha1.KubeProxyConntrackConfiguration{ | ||
Max: pointer.Int32Ptr(2), | ||
MaxPerCore: pointer.Int32Ptr(1), | ||
Min: pointer.Int32Ptr(1), | ||
Max: utilpointer.Int32Ptr(2), | ||
MaxPerCore: utilpointer.Int32Ptr(1), | ||
Min: utilpointer.Int32Ptr(1), | ||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, | ||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, | ||
}, | ||
|
@@ -361,6 +377,32 @@ func TestValidateMasterConfiguration(t *testing.T) { | |
AdvertiseAddress: "1:2:3::4", | ||
BindPort: 3446, | ||
}, | ||
KubeProxy: kubeadm.KubeProxy{ | ||
Config: &kubeproxyconfigv1alpha1.KubeProxyConfiguration{ | ||
BindAddress: "192.168.59.103", | ||
HealthzBindAddress: "0.0.0.0:10256", | ||
MetricsBindAddress: "127.0.0.1:10249", | ||
ClusterCIDR: "192.168.59.0/24", | ||
UDPIdleTimeout: metav1.Duration{Duration: 1 * time.Second}, | ||
ConfigSyncPeriod: metav1.Duration{Duration: 1 * time.Second}, | ||
IPTables: kubeproxyconfigv1alpha1.KubeProxyIPTablesConfiguration{ | ||
MasqueradeAll: true, | ||
SyncPeriod: metav1.Duration{Duration: 5 * time.Second}, | ||
MinSyncPeriod: metav1.Duration{Duration: 2 * time.Second}, | ||
}, | ||
IPVS: kubeproxyconfigv1alpha1.KubeProxyIPVSConfiguration{ | ||
SyncPeriod: metav1.Duration{Duration: 10 * time.Second}, | ||
MinSyncPeriod: metav1.Duration{Duration: 5 * time.Second}, | ||
}, | ||
Conntrack: kubeproxyconfigv1alpha1.KubeProxyConntrackConfiguration{ | ||
Max: utilpointer.Int32Ptr(2), | ||
MaxPerCore: utilpointer.Int32Ptr(1), | ||
Min: utilpointer.Int32Ptr(1), | ||
TCPEstablishedTimeout: &metav1.Duration{Duration: 5 * time.Second}, | ||
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5 * time.Second}, | ||
}, | ||
}, | ||
}, | ||
AuthorizationModes: []string{"Node", "RBAC"}, | ||
Networking: kubeadm.Networking{ | ||
ServiceSubnet: "2001:db8::1/98", | ||
|
@@ -502,3 +544,65 @@ func TestValidateIgnorePreflightErrors(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestValidateKubeletConfiguration(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: the test case is mainly stolen from the original test case of kubelet validation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's ok I guess :) |
||
successCase := &kubeadm.KubeletConfiguration{ | ||
BaseConfig: &kubeletconfigv1alpha1.KubeletConfiguration{ | ||
CgroupsPerQOS: utilpointer.BoolPtr(true), | ||
EnforceNodeAllocatable: []string{"pods", "system-reserved", "kube-reserved"}, | ||
SystemCgroups: "", | ||
CgroupRoot: "", | ||
CAdvisorPort: utilpointer.Int32Ptr(0), | ||
EventBurst: 10, | ||
EventRecordQPS: utilpointer.Int32Ptr(5), | ||
HealthzPort: utilpointer.Int32Ptr(10248), | ||
ImageGCHighThresholdPercent: utilpointer.Int32Ptr(85), | ||
ImageGCLowThresholdPercent: utilpointer.Int32Ptr(80), | ||
IPTablesDropBit: utilpointer.Int32Ptr(15), | ||
IPTablesMasqueradeBit: utilpointer.Int32Ptr(14), | ||
KubeAPIBurst: 10, | ||
KubeAPIQPS: utilpointer.Int32Ptr(5), | ||
MaxOpenFiles: 1000000, | ||
MaxPods: 110, | ||
OOMScoreAdj: utilpointer.Int32Ptr(-999), | ||
PodsPerCore: 100, | ||
Port: 65535, | ||
ReadOnlyPort: utilpointer.Int32Ptr(0), | ||
RegistryBurst: 10, | ||
RegistryPullQPS: utilpointer.Int32Ptr(5), | ||
}, | ||
} | ||
if allErrors := ValidateKubeletConfiguration(successCase, nil); len(allErrors) != 0 { | ||
t.Errorf("failed ValidateKubeletConfiguration: expect no errors but got %v", allErrors) | ||
} | ||
|
||
errorCase := &kubeadm.KubeletConfiguration{ | ||
BaseConfig: &kubeletconfigv1alpha1.KubeletConfiguration{ | ||
CgroupsPerQOS: utilpointer.BoolPtr(false), | ||
EnforceNodeAllocatable: []string{"pods", "system-reserved", "kube-reserved", "illegal-key"}, | ||
SystemCgroups: "/", | ||
CgroupRoot: "", | ||
CAdvisorPort: utilpointer.Int32Ptr(-10), | ||
EventBurst: -10, | ||
EventRecordQPS: utilpointer.Int32Ptr(-10), | ||
HealthzPort: utilpointer.Int32Ptr(-10), | ||
ImageGCHighThresholdPercent: utilpointer.Int32Ptr(101), | ||
ImageGCLowThresholdPercent: utilpointer.Int32Ptr(101), | ||
IPTablesDropBit: utilpointer.Int32Ptr(-10), | ||
IPTablesMasqueradeBit: utilpointer.Int32Ptr(-10), | ||
KubeAPIBurst: -10, | ||
KubeAPIQPS: utilpointer.Int32Ptr(-10), | ||
MaxOpenFiles: -10, | ||
MaxPods: -10, | ||
OOMScoreAdj: utilpointer.Int32Ptr(-1001), | ||
PodsPerCore: -10, | ||
Port: 0, | ||
ReadOnlyPort: utilpointer.Int32Ptr(-10), | ||
RegistryBurst: -10, | ||
RegistryPullQPS: utilpointer.Int32Ptr(-10), | ||
}, | ||
} | ||
if allErrors := ValidateKubeletConfiguration(errorCase, nil); len(allErrors) == 0 { | ||
t.Errorf("failed ValidateKubeletConfiguration: expect errors but got no error") | ||
} | ||
} |
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.
👍