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 Aug 2, 2021
1 parent 5aac303 commit 2f96785
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 40 deletions.
99 changes: 95 additions & 4 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,55 @@ import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
kubeadmbootstrapv1alpha4 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha4"
kubeadmbootstrapv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// ConvertTo converts this KubeadmConfig to the Hub version (v1alpha4).
func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*kubeadmbootstrapv1alpha4.KubeadmConfig)
return Convert_v1alpha3_KubeadmConfig_To_v1alpha4_KubeadmConfig(src, dst, nil)

if err := Convert_v1alpha3_KubeadmConfig_To_v1alpha4_KubeadmConfig(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &kubeadmbootstrapv1alpha4.KubeadmConfig{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

if restored.Spec.JoinConfiguration != nil && restored.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors != nil {
if dst.Spec.JoinConfiguration == nil {
dst.Spec.JoinConfiguration = &kubeadmbootstrapv1alpha4.JoinConfiguration{}
}
dst.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors
}

if restored.Spec.InitConfiguration != nil && restored.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors != nil {
if dst.Spec.InitConfiguration == nil {
dst.Spec.InitConfiguration = &kubeadmbootstrapv1alpha4.InitConfiguration{}
}
dst.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors
}

return nil
}

// ConvertFrom converts from the KubeadmConfig Hub version (v1alpha4) to this version.
func (dst *KubeadmConfig) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*kubeadmbootstrapv1alpha4.KubeadmConfig)
return Convert_v1alpha4_KubeadmConfig_To_v1alpha3_KubeadmConfig(src, dst, nil)

if err := Convert_v1alpha4_KubeadmConfig_To_v1alpha3_KubeadmConfig(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this KubeadmConfigList to the Hub version (v1alpha4).
Expand All @@ -50,13 +86,48 @@ func (dst *KubeadmConfigList) ConvertFrom(srcRaw conversion.Hub) error {
// ConvertTo converts this KubeadmConfigTemplate to the Hub version (v1alpha4).
func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*kubeadmbootstrapv1alpha4.KubeadmConfigTemplate)
return Convert_v1alpha3_KubeadmConfigTemplate_To_v1alpha4_KubeadmConfigTemplate(src, dst, nil)

if err := Convert_v1alpha3_KubeadmConfigTemplate_To_v1alpha4_KubeadmConfigTemplate(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &kubeadmbootstrapv1alpha4.KubeadmConfigTemplate{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

if restored.Spec.Template.Spec.JoinConfiguration != nil && restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors != nil {
if dst.Spec.Template.Spec.JoinConfiguration == nil {
dst.Spec.Template.Spec.JoinConfiguration = &kubeadmbootstrapv1alpha4.JoinConfiguration{}
}
dst.Spec.Template.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.Template.Spec.JoinConfiguration.NodeRegistration.IgnorePreflightErrors
}

if restored.Spec.Template.Spec.InitConfiguration != nil && restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors != nil {
if dst.Spec.Template.Spec.InitConfiguration == nil {
dst.Spec.Template.Spec.InitConfiguration = &kubeadmbootstrapv1alpha4.InitConfiguration{}
}
dst.Spec.Template.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors
}

return nil
}

// ConvertFrom converts from the KubeadmConfigTemplate Hub version (v1alpha4) to this version.
func (dst *KubeadmConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*kubeadmbootstrapv1alpha4.KubeadmConfigTemplate)
return Convert_v1alpha4_KubeadmConfigTemplate_To_v1alpha3_KubeadmConfigTemplate(src, dst, nil)

if err := Convert_v1alpha4_KubeadmConfigTemplate_To_v1alpha3_KubeadmConfigTemplate(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this KubeadmConfigTemplateList to the Hub version (v1alpha3).
Expand Down Expand Up @@ -90,3 +161,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)
}
24 changes: 24 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ 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"
kubeadmv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/types/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

Expand All @@ -45,6 +47,18 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
KubeadmConfigStatusFuzzer,
dnsFuzzer,
clusterConfigurationFuzzer,
// This custom functions are needed when ConvertTo/ConvertFrom functions
// uses the json package to unmarshal the bootstrap token string.
//
// The Kubeadm BootstrapTokenString type ships with a custom
// json string representation, in particular it supplies a customized
// UnmarshalJSON function that can return an error if the string
// isn't in the correct form.
//
// This function effectively disables any fuzzing for the token by setting
// the values for ID and Secret to working alphanumeric values.
kubeadmBootstrapTokenStringFuzzerV1beta1,
kubeadmBootstrapTokenStringFuzzerV1Alpha4,
}
}

Expand All @@ -68,3 +82,13 @@ 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 kubeadmBootstrapTokenStringFuzzerV1beta1(in *kubeadmv1beta1.BootstrapTokenString, c fuzz.Continue) {
in.ID = "abcdef"
in.Secret = "abcdef0123456789"
}

func kubeadmBootstrapTokenStringFuzzerV1Alpha4(in *kubeadmbootstrapv1alpha4.BootstrapTokenString, c fuzz.Continue) {
in.ID = "abcdef"
in.Secret = "abcdef0123456789"
}
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
5 changes: 5 additions & 0 deletions bootstrap/kubeadm/api/v1alpha4/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,12 @@ spec:
info. This information will be annotated to the Node API
object, for later re-use
type: string
ignorePreflightErrors:
description: IgnorePreflightErrors provides a slice of pre-flight
errors to be ignored when the current node is registered.
items:
type: string
type: array
kubeletExtraArgs:
additionalProperties:
type: string
Expand Down Expand Up @@ -1747,6 +1753,12 @@ spec:
info. This information will be annotated to the Node API
object, for later re-use
type: string
ignorePreflightErrors:
description: IgnorePreflightErrors provides a slice of pre-flight
errors to be ignored when the current node is registered.
items:
type: string
type: array
kubeletExtraArgs:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,13 @@ spec:
runtime info. This information will be annotated
to the Node API object, for later re-use
type: string
ignorePreflightErrors:
description: IgnorePreflightErrors provides a slice
of pre-flight errors to be ignored when the current
node is registered.
items:
type: string
type: array
kubeletExtraArgs:
additionalProperties:
type: string
Expand Down Expand Up @@ -1786,6 +1793,13 @@ spec:
runtime info. This information will be annotated
to the Node API object, for later re-use
type: string
ignorePreflightErrors:
description: IgnorePreflightErrors provides a slice
of pre-flight errors to be ignored when the current
node is registered.
items:
type: string
type: array
kubeletExtraArgs:
additionalProperties:
type: string
Expand Down
Loading

0 comments on commit 2f96785

Please sign in to comment.