Skip to content

Commit

Permalink
support NodeRegistrationOptions.IgnorePreflightErrors
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jul 9, 2021
1 parent 37c862b commit 675248a
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 18 deletions.
20 changes: 20 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,23 @@ func Convert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in *k
// ClusterConfiguration.UseHyperKubeImage was removed in kubeadm v1alpha4 API
return kubeadmbootstrapv1beta1.Convert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in, out, s)
}

func Convert_v1alpha4_InitConfiguration_To_v1beta1_InitConfiguration(in *kubeadmbootstrapv1alpha4.InitConfiguration, out *kubeadmbootstrapv1beta1.InitConfiguration, s apiconversion.Scope) error {
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return kubeadmbootstrapv1beta1.Convert_v1alpha4_InitConfiguration_To_v1beta1_InitConfiguration(in, out, s)
}

func Convert_v1beta1_InitConfiguration_To_v1alpha4_InitConfiguration(in *kubeadmbootstrapv1beta1.InitConfiguration, out *kubeadmbootstrapv1alpha4.InitConfiguration, s apiconversion.Scope) error {
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return kubeadmbootstrapv1beta1.Convert_v1beta1_InitConfiguration_To_v1alpha4_InitConfiguration(in, out, s)
}

func Convert_v1alpha4_JoinConfiguration_To_v1beta1_JoinConfiguration(in *kubeadmbootstrapv1alpha4.JoinConfiguration, out *kubeadmbootstrapv1beta1.JoinConfiguration, s apiconversion.Scope) error {
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return kubeadmbootstrapv1beta1.Convert_v1alpha4_JoinConfiguration_To_v1beta1_JoinConfiguration(in, out, s)
}

func Convert_v1beta1_JoinConfiguration_To_v1alpha4_JoinConfiguration(in *kubeadmbootstrapv1beta1.JoinConfiguration, out *kubeadmbootstrapv1alpha4.JoinConfiguration, s apiconversion.Scope) error {
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return kubeadmbootstrapv1beta1.Convert_v1beta1_JoinConfiguration_To_v1alpha4_JoinConfiguration(in, out, s)
}
10 changes: 10 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
kubeadmbootstrapv1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)
Expand All @@ -45,6 +46,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
KubeadmConfigStatusFuzzer,
dnsFuzzer,
clusterConfigurationFuzzer,
kubeadmNodeRegistrationOptionsFuzzer,
}
}

Expand All @@ -68,3 +70,11 @@ func clusterConfigurationFuzzer(obj *v1beta1.ClusterConfiguration, c fuzz.Contin
// ClusterConfiguration.UseHyperKubeImage has been removed in v1alpha4, so setting it to false in order to avoid v1beta1 --> v1alpha4 --> v1beta1 round trip errors.
obj.UseHyperKubeImage = false
}

func kubeadmNodeRegistrationOptionsFuzzer(obj *kubeadmbootstrapv1alpha4.NodeRegistrationOptions, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API, so setting it to nil in order to avoid
// v1alpha4 --> v1beta1 -> v1alpha4 round trip errors.
obj.IgnorePreflightErrors = nil
}
60 changes: 56 additions & 4 deletions bootstrap/kubeadm/api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bootstrap/kubeadm/api/v1alpha4/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ type NodeRegistrationOptions struct {
// Flags have higher priority when parsing. These values are local and specific to the node kubeadm is executing on.
// +optional
KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`

// IgnorePreflightErrors provides a slice of pre-flight errors to be ignored when the current node is registered.
// +optional
IgnorePreflightErrors []string `json:"ignorePreflightErrors,omitempty"`
}

// Networking contains elements describing cluster's networking configuration.
Expand Down
106 changes: 102 additions & 4 deletions bootstrap/kubeadm/types/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ func TestMarshalClusterConfigurationForVersion(t *testing.T) {
"scheduler: {}\n",
wantErr: false,
},
{
name: "Generates a v1beta3 kubeadm configuration",
args: args{
capiObj: &bootstrapv1.ClusterConfiguration{},
version: semver.MustParse("1.22.0"),
},
want: "apiServer: {}\n" +
"apiVersion: kubeadm.k8s.io/v1beta3\n" + "" +
"controllerManager: {}\n" +
"dns: {}\n" +
"etcd: {}\n" +
"kind: ClusterConfiguration\n" +
"networking: {}\n" +
"scheduler: {}\n",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -211,6 +227,14 @@ func TestMarshalClusterStatusForVersion(t *testing.T) {
"kind: ClusterStatus\n",
wantErr: false,
},
{
name: "Fails generating a v1beta3 kubeadm status",
args: args{
capiObj: &bootstrapv1.ClusterStatus{},
version: semver.MustParse("1.22.0"),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -255,13 +279,38 @@ func TestMarshalInitConfigurationForVersion(t *testing.T) {
{
name: "Generates a v1beta2 kubeadm configuration",
args: args{
capiObj: &bootstrapv1.InitConfiguration{},
capiObj: &bootstrapv1.InitConfiguration{
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
IgnorePreflightErrors: []string{"some-preflight-check"},
},
},
version: semver.MustParse("1.15.0"),
},
want: "apiVersion: kubeadm.k8s.io/v1beta2\n" +
"kind: InitConfiguration\n" +
"localAPIEndpoint: {}\n" +
"nodeRegistration: {}\n",
"nodeRegistration:\n" +
" ignorePreflightErrors:\n" +
" - some-preflight-check\n",
wantErr: false,
},
{
name: "Generates a v1beta3 kubeadm configuration",
args: args{
capiObj: &bootstrapv1.InitConfiguration{
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
IgnorePreflightErrors: []string{"some-preflight-check"},
},
},
version: semver.MustParse("1.22.0"),
},
want: "apiVersion: kubeadm.k8s.io/v1beta3\n" +
"kind: InitConfiguration\n" +
"localAPIEndpoint: {}\n" +
"nodeRegistration:\n" +
" ignorePreflightErrors:\n" +
" - some-preflight-check\n" +
" taints: null\n",
wantErr: false,
},
}
Expand Down Expand Up @@ -306,13 +355,38 @@ func TestMarshalJoinConfigurationForVersion(t *testing.T) {
{
name: "Generates a v1beta2 kubeadm configuration",
args: args{
capiObj: &bootstrapv1.JoinConfiguration{},
capiObj: &bootstrapv1.JoinConfiguration{
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
IgnorePreflightErrors: []string{"some-preflight-check"},
},
},
version: semver.MustParse("1.15.0"),
},
want: "apiVersion: kubeadm.k8s.io/v1beta2\n" + "" +
"discovery: {}\n" +
"kind: JoinConfiguration\n" +
"nodeRegistration: {}\n",
"nodeRegistration:\n" +
" ignorePreflightErrors:\n" +
" - some-preflight-check\n",
wantErr: false,
},
{
name: "Generates a v1beta3 kubeadm configuration",
args: args{
capiObj: &bootstrapv1.JoinConfiguration{
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
IgnorePreflightErrors: []string{"some-preflight-check"},
},
},
version: semver.MustParse("1.22.0"),
},
want: "apiVersion: kubeadm.k8s.io/v1beta3\n" + "" +
"discovery: {}\n" +
"kind: JoinConfiguration\n" +
"nodeRegistration:\n" +
" ignorePreflightErrors:\n" +
" - some-preflight-check\n" +
" taints: null\n",
wantErr: false,
},
}
Expand Down Expand Up @@ -371,6 +445,21 @@ func TestUnmarshalClusterConfiguration(t *testing.T) {
want: &bootstrapv1.ClusterConfiguration{},
wantErr: false,
},
{
name: "Parses a v1beta3 kubeadm configuration",
args: args{
yaml: "apiServer: {}\n" +
"apiVersion: kubeadm.k8s.io/v1beta3\n" + "" +
"controllerManager: {}\n" +
"dns: {}\n" +
"etcd: {}\n" +
"kind: ClusterConfiguration\n" +
"networking: {}\n" +
"scheduler: {}\n",
},
want: &bootstrapv1.ClusterConfiguration{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -417,6 +506,15 @@ func TestUnmarshalClusterStatus(t *testing.T) {
want: &bootstrapv1.ClusterStatus{},
wantErr: false,
},
{
name: "Fails parsing a v1beta3 kubeadm configuration",
args: args{
yaml: "apiEndpoints: null\n" +
"apiVersion: kubeadm.k8s.io/v1beta3\n" + "" +
"kind: ClusterStatus\n",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/kubeadm/types/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
v1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand Down Expand Up @@ -79,3 +80,8 @@ func Convert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in *C
// ClusterConfiguration.UseHyperKubeImage was removed in kubeadm v1alpha4 API
return autoConvert_v1beta1_ClusterConfiguration_To_v1alpha4_ClusterConfiguration(in, out, s)
}

func Convert_v1alpha4_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in *v1alpha4.NodeRegistrationOptions, out *NodeRegistrationOptions, s apimachineryconversion.Scope) error {
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return autoConvert_v1alpha4_NodeRegistrationOptions_To_v1beta1_NodeRegistrationOptions(in, out, s)
}
10 changes: 10 additions & 0 deletions bootstrap/kubeadm/types/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
kubeadmbootstrapv1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

Expand Down Expand Up @@ -61,6 +62,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
dnsFuzzer,
clusterConfigurationFuzzer,
kubeadmNodeRegistrationOptionsFuzzer,
}
}

Expand All @@ -77,3 +79,11 @@ func clusterConfigurationFuzzer(obj *ClusterConfiguration, c fuzz.Continue) {
// ClusterConfiguration.UseHyperKubeImage has been removed in v1alpha4, so setting it to false in order to avoid v1beta1 --> v1alpha4 --> v1beta1 round trip errors.
obj.UseHyperKubeImage = false
}

func kubeadmNodeRegistrationOptionsFuzzer(obj *kubeadmbootstrapv1alpha4.NodeRegistrationOptions, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API, so setting it to nil in order to avoid
// v1alpha4 --> v1beta1 -> v1alpha4 round trip errors.
obj.IgnorePreflightErrors = nil
}
8 changes: 2 additions & 6 deletions bootstrap/kubeadm/types/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 675248a

Please sign in to comment.