Skip to content

Commit 73b8011

Browse files
authored
Merge pull request kubernetes#75499 from marccarre/issues/74246-more-decl-kubeadm-cli-args
Add ability to configure kubeadm's ignored pre-flight errors via InitConfiguration and JoinConfiguration
2 parents ba0abd0 + 7e2b4aa commit 73b8011

File tree

20 files changed

+331
-53
lines changed

20 files changed

+331
-53
lines changed

cmd/kubeadm/app/apis/kubeadm/fuzzer/fuzzer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
3232
fuzzClusterConfiguration,
3333
fuzzComponentConfigs,
3434
fuzzDNS,
35+
fuzzNodeRegistration,
3536
fuzzLocalEtcd,
3637
fuzzNetworking,
3738
fuzzJoinConfiguration,
@@ -87,6 +88,13 @@ func fuzzInitConfiguration(obj *kubeadm.InitConfiguration, c fuzz.Continue) {
8788
obj.CertificateKey = ""
8889
}
8990

91+
func fuzzNodeRegistration(obj *kubeadm.NodeRegistrationOptions, c fuzz.Continue) {
92+
c.FuzzNoCustom(obj)
93+
94+
// Pinning values for fields that get defaults if fuzz value is empty string or nil (thus making the round trip test fail)
95+
obj.IgnorePreflightErrors = nil
96+
}
97+
9098
func fuzzClusterConfiguration(obj *kubeadm.ClusterConfiguration, c fuzz.Continue) {
9199
c.FuzzNoCustom(obj)
92100

cmd/kubeadm/app/apis/kubeadm/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ type NodeRegistrationOptions struct {
229229
// kubeadm writes at runtime for the kubelet to source. This overrides the generic base-level configuration in the kubelet-config-1.X ConfigMap
230230
// Flags have higher priority when parsing. These values are local and specific to the node kubeadm is executing on.
231231
KubeletExtraArgs map[string]string
232+
233+
// IgnorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
234+
IgnorePreflightErrors []string
232235
}
233236

234237
// Networking contains elements describing cluster's networking configuration.

cmd/kubeadm/app/apis/kubeadm/v1beta1/conversion.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,15 @@ func Convert_kubeadm_JoinControlPlane_To_v1beta1_JoinControlPlane(in *kubeadm.Jo
4545

4646
return nil
4747
}
48+
49+
func Convert_kubeadm_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in *kubeadm.NodeRegistrationOptions, out *NodeRegistrationOptions, s conversion.Scope) error {
50+
if err := autoConvert_kubeadm_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in, out, s); err != nil {
51+
return err
52+
}
53+
54+
if len(in.IgnorePreflightErrors) > 0 {
55+
return errors.New("ignorePreflightErrors field is not supported by v1beta1 config format")
56+
}
57+
58+
return nil
59+
}

cmd/kubeadm/app/apis/kubeadm/v1beta1/conversion_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func TestInternalToVersionedInitConfigurationConversion(t *testing.T) {
3737
},
3838
expectedError: true,
3939
},
40+
"ignorePreflightErrors set causes an error": {
41+
in: kubeadm.InitConfiguration{
42+
NodeRegistration: kubeadm.NodeRegistrationOptions{
43+
IgnorePreflightErrors: []string{"SomeUndesirableError"},
44+
},
45+
},
46+
expectedError: true,
47+
},
4048
}
4149
for name, tc := range testcases {
4250
t.Run(name, func(t *testing.T) {
@@ -51,6 +59,66 @@ func TestInternalToVersionedInitConfigurationConversion(t *testing.T) {
5159
}
5260
}
5361

62+
func TestInternalToVersionedJoinConfigurationConversion(t *testing.T) {
63+
testcases := map[string]struct {
64+
in kubeadm.JoinConfiguration
65+
expectedError bool
66+
}{
67+
"conversion succeeds": {
68+
in: kubeadm.JoinConfiguration{},
69+
expectedError: false,
70+
},
71+
"ignorePreflightErrors set causes an error": {
72+
in: kubeadm.JoinConfiguration{
73+
NodeRegistration: kubeadm.NodeRegistrationOptions{
74+
IgnorePreflightErrors: []string{"SomeUndesirableError"},
75+
},
76+
},
77+
expectedError: true,
78+
},
79+
}
80+
for name, tc := range testcases {
81+
t.Run(name, func(t *testing.T) {
82+
versioned := &JoinConfiguration{}
83+
err := Convert_kubeadm_JoinConfiguration_To_v1beta1_JoinConfiguration(&tc.in, versioned, nil)
84+
if err == nil && tc.expectedError {
85+
t.Error("unexpected success")
86+
} else if err != nil && !tc.expectedError {
87+
t.Errorf("unexpected error: %v", err)
88+
}
89+
})
90+
}
91+
}
92+
93+
func TestInternalToVersionedNodeRegistrationOptionsConversion(t *testing.T) {
94+
testcases := map[string]struct {
95+
in kubeadm.NodeRegistrationOptions
96+
expectedError bool
97+
}{
98+
"conversion succeeds": {
99+
in: kubeadm.NodeRegistrationOptions{},
100+
expectedError: false,
101+
},
102+
"ignorePreflightErrors set causes an error": {
103+
in: kubeadm.NodeRegistrationOptions{
104+
IgnorePreflightErrors: []string{"SomeUndesirableError"},
105+
},
106+
expectedError: true,
107+
},
108+
}
109+
for name, tc := range testcases {
110+
t.Run(name, func(t *testing.T) {
111+
versioned := &NodeRegistrationOptions{}
112+
err := Convert_kubeadm_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(&tc.in, versioned, nil)
113+
if err == nil && tc.expectedError {
114+
t.Error("unexpected success")
115+
} else if err != nil && !tc.expectedError {
116+
t.Errorf("unexpected error: %v", err)
117+
}
118+
})
119+
}
120+
}
121+
54122
func TestInternalToVersionedJoinControlPlaneConversion(t *testing.T) {
55123
testcases := map[string]struct {
56124
in kubeadm.JoinControlPlane

cmd/kubeadm/app/apis/kubeadm/v1beta1/zz_generated.conversion.go

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

cmd/kubeadm/app/apis/kubeadm/v1beta2/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ type NodeRegistrationOptions struct {
215215
// kubeadm writes at runtime for the kubelet to source. This overrides the generic base-level configuration in the kubelet-config-1.X ConfigMap
216216
// Flags have higher priority when parsing. These values are local and specific to the node kubeadm is executing on.
217217
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
218+
219+
// IgnorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
220+
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
218221
}
219222

220223
// Networking contains elements describing cluster's networking configuration

cmd/kubeadm/app/apis/kubeadm/v1beta2/zz_generated.conversion.go

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

cmd/kubeadm/app/apis/kubeadm/v1beta2/zz_generated.deepcopy.go

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

cmd/kubeadm/app/apis/kubeadm/validation/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ go_test(
3434
"//cmd/kubeadm/app/apis/kubeadm/v1beta2:go_default_library",
3535
"//pkg/proxy/apis/config:go_default_library",
3636
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
37+
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
3738
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
3839
"//vendor/github.com/spf13/pflag:go_default_library",
3940
"//vendor/k8s.io/utils/pointer:go_default_library",

cmd/kubeadm/app/apis/kubeadm/validation/validation.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,25 @@ func ValidateAPIEndpoint(c *kubeadm.APIEndpoint, fldPath *field.Path) field.Erro
463463
return allErrs
464464
}
465465

466-
// ValidateIgnorePreflightErrors validates duplicates in ignore-preflight-errors flag.
467-
func ValidateIgnorePreflightErrors(ignorePreflightErrors []string) (sets.String, error) {
466+
// ValidateIgnorePreflightErrors validates duplicates in:
467+
// - ignore-preflight-errors flag and
468+
// - ignorePreflightErrors field in {Init,Join}Configuration files.
469+
func ValidateIgnorePreflightErrors(ignorePreflightErrorsFromCLI, ignorePreflightErrorsFromConfigFile []string) (sets.String, error) {
468470
ignoreErrors := sets.NewString()
469471
allErrs := field.ErrorList{}
470472

471-
for _, item := range ignorePreflightErrors {
473+
for _, item := range ignorePreflightErrorsFromConfigFile {
474+
ignoreErrors.Insert(strings.ToLower(item)) // parameters are case insensitive
475+
}
476+
477+
if ignoreErrors.Has("all") {
478+
// "all" is forbidden in config files. Administrators should use an
479+
// explicit list of errors they want to ignore, as it can be risky to
480+
// mask all errors in such a way. Hence, we return an error:
481+
allErrs = append(allErrs, field.Invalid(field.NewPath("ignorePreflightErrors"), "all", "'all' cannot be used in configuration file"))
482+
}
483+
484+
for _, item := range ignorePreflightErrorsFromCLI {
472485
ignoreErrors.Insert(strings.ToLower(item)) // parameters are case insensitive
473486
}
474487

0 commit comments

Comments
 (0)