Skip to content

Commit

Permalink
Merge pull request #4172 from kinvolk/invidian/ignition-support-pr
Browse files Browse the repository at this point in the history
✨ Add support for generating bootstrap data in Ignition format to CABPK
  • Loading branch information
k8s-ci-robot authored Dec 8, 2021
2 parents 3e5a8bf + 87df81f commit f815cef
Show file tree
Hide file tree
Showing 62 changed files with 3,153 additions and 323 deletions.
10 changes: 10 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ aliases:
cluster-api-bootstrap-provider-kubeadm-maintainers:
cluster-api-bootstrap-provider-kubeadm-reviewers:

# -----------------------------------------------------------
# OWNER_ALIASES for bootstrap/kubeadm/internal/ignition
# -----------------------------------------------------------

cluster-api-bootstrap-provider-kubeadm-ignition-maintainers:
cluster-api-bootstrap-provider-kubeadm-ignition-reviewers:
- dongsupark
- invidian
- johananl

# -----------------------------------------------------------
# OWNER_ALIASES for controlplane/kubeadm
# -----------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions bootstrap/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors
}

dst.Spec.Ignition = restored.Spec.Ignition

return nil
}

Expand Down Expand Up @@ -109,6 +111,8 @@ func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors = restored.Spec.Template.Spec.InitConfiguration.NodeRegistration.IgnorePreflightErrors
}

dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition

return nil
}

Expand Down Expand Up @@ -177,3 +181,9 @@ func Convert_v1beta1_JoinConfiguration_To_upstreamv1beta1_JoinConfiguration(in *
// NodeRegistrationOptions.IgnorePreflightErrors does not exist in kubeadm v1beta1 API
return upstreamv1beta1.Convert_v1beta1_JoinConfiguration_To_upstreamv1beta1_JoinConfiguration(in, out, s)
}

// Convert_v1beta1_KubeadmConfigSpec_To_v1alpha3_KubeadmConfigSpec is an autogenerated conversion function.
func Convert_v1beta1_KubeadmConfigSpec_To_v1alpha3_KubeadmConfigSpec(in *v1beta1.KubeadmConfigSpec, out *KubeadmConfigSpec, s apiconversion.Scope) error {
// KubeadmConfigSpec.Ignition does not exist in kubeadm v1alpha3 API.
return autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha3_KubeadmConfigSpec(in, out, s)
}
16 changes: 6 additions & 10 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.

48 changes: 44 additions & 4 deletions bootstrap/kubeadm/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,39 @@ limitations under the License.
package v1alpha4

import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.KubeadmConfig)

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

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

dst.Spec.Ignition = restored.Spec.Ignition

return nil
}

func (dst *KubeadmConfig) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.KubeadmConfig)

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

func (src *KubeadmConfigList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -49,13 +67,29 @@ func (dst *KubeadmConfigList) ConvertFrom(srcRaw conversion.Hub) error {
func (src *KubeadmConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.KubeadmConfigTemplate)

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

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

dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition

return nil
}

func (dst *KubeadmConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.KubeadmConfigTemplate)

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

func (src *KubeadmConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
Expand All @@ -69,3 +103,9 @@ func (dst *KubeadmConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {

return Convert_v1beta1_KubeadmConfigTemplateList_To_v1alpha4_KubeadmConfigTemplateList(src, dst, nil)
}

// Convert_v1beta1_KubeadmConfigSpec_To_v1alpha4_KubeadmConfigSpec is an autogenerated conversion function.
func Convert_v1beta1_KubeadmConfigSpec_To_v1alpha4_KubeadmConfigSpec(in *v1beta1.KubeadmConfigSpec, out *KubeadmConfigSpec, s apiconversion.Scope) error {
// KubeadmConfigSpec.Ignition does not exist in kubeadm v1alpha4 API.
return autoConvert_v1beta1_KubeadmConfigSpec_To_v1alpha4_KubeadmConfigSpec(in, out, s)
}
19 changes: 15 additions & 4 deletions bootstrap/kubeadm/api/v1alpha4/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

const (
fakeID = "abcdef"
fakeSecret = "abcdef0123456789"
)

func TestFuzzyConversion(t *testing.T) {
t.Run("for KubeadmConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &v1beta1.KubeadmConfig{},
Expand Down Expand Up @@ -57,6 +62,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
// the values for ID and Secret to working alphanumeric values.
kubeadmBootstrapTokenStringFuzzerV1UpstreamBeta1,
kubeadmBootstrapTokenStringFuzzerV1Beta1,
kubeadmBootstrapTokenStringFuzzerV1Alpha4,
}
}

Expand All @@ -75,11 +81,16 @@ func clusterConfigurationFuzzer(obj *upstreamv1beta1.ClusterConfiguration, c fuz
}

func kubeadmBootstrapTokenStringFuzzerV1UpstreamBeta1(in *upstreamv1beta1.BootstrapTokenString, c fuzz.Continue) {
in.ID = "abcdef"
in.Secret = "abcdef0123456789"
in.ID = fakeID
in.Secret = fakeSecret
}

func kubeadmBootstrapTokenStringFuzzerV1Beta1(in *v1beta1.BootstrapTokenString, c fuzz.Continue) {
in.ID = "abcdef"
in.Secret = "abcdef0123456789"
in.ID = fakeID
in.Secret = fakeSecret
}

func kubeadmBootstrapTokenStringFuzzerV1Alpha4(in *BootstrapTokenString, c fuzz.Continue) {
in.ID = fakeID
in.Secret = fakeSecret
}
40 changes: 28 additions & 12 deletions bootstrap/kubeadm/api/v1alpha4/zz_generated.conversion.go

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

32 changes: 31 additions & 1 deletion bootstrap/kubeadm/api/v1beta1/kubeadmconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
)

// Format specifies the output format of the bootstrap data
// +kubebuilder:validation:Enum=cloud-config
// +kubebuilder:validation:Enum=cloud-config;ignition
type Format string

const (
// CloudConfig make the bootstrap data to be of cloud-config format.
CloudConfig Format = "cloud-config"

// Ignition make the bootstrap data to be of Ignition format.
Ignition Format = "ignition"
)

// KubeadmConfigSpec defines the desired state of KubeadmConfig.
Expand Down Expand Up @@ -95,6 +98,33 @@ type KubeadmConfigSpec struct {
// For more information, refer to https://github.com/kubernetes-sigs/cluster-api/pull/2763#discussion_r397306055.
// +optional
UseExperimentalRetryJoin bool `json:"useExperimentalRetryJoin,omitempty"`

// Ignition contains Ignition specific configuration.
// +optional
Ignition *IgnitionSpec `json:"ignition,omitempty"`
}

// IgnitionSpec contains Ignition specific configuration.
type IgnitionSpec struct {
// ContainerLinuxConfig contains CLC specific configuration.
// +optional
ContainerLinuxConfig *ContainerLinuxConfig `json:"containerLinuxConfig,omitempty"`
}

// ContainerLinuxConfig contains CLC-specific configuration.
//
// We use a structured type here to allow adding additional fields, for example 'version'.
type ContainerLinuxConfig struct {
// AdditionalConfig contains additional configuration to be merged with the Ignition
// configuration generated by the bootstrapper controller. More info: https://coreos.github.io/ignition/operator-notes/#config-merging
//
// The data format is documented here: https://kinvolk.io/docs/flatcar-container-linux/latest/provisioning/cl-config/
// +optional
AdditionalConfig string `json:"additionalConfig,omitempty"`

// Strict controls if AdditionalConfig should be strictly parsed. If so, warnings are treated as errors.
// +optional
Strict bool `json:"strict,omitempty"`
}

// KubeadmConfigStatus defines the observed state of KubeadmConfig.
Expand Down
Loading

0 comments on commit f815cef

Please sign in to comment.