diff --git a/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types.go b/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types.go index b35631f8af0a..76d953b8ec6c 100644 --- a/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types.go +++ b/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types.go @@ -240,6 +240,9 @@ func (c *ClusterConfig) UnmarshalJSON(data []byte) error { if jc.Spec.Extensions == nil { jc.Spec.Extensions = DefaultExtensions() } + if jc.Spec.Extensions.Storage == nil { + jc.Spec.Extensions.Storage = DefaultStorageExtension() + } if jc.Spec.Network == nil { jc.Spec.Network = DefaultNetwork() } diff --git a/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types_test.go b/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types_test.go index b748a904c14c..d1f07454e22e 100644 --- a/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types_test.go +++ b/pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types_test.go @@ -195,6 +195,15 @@ spec: telemetry: null konnectivity: null ` + extensionsYamlData := ` +apiVersion: k0s.k0sproject.io/v1beta1 +kind: ClusterConfig +metadata: + name: foobar +spec: + extensions: + storage: null +` c, err := ConfigFromString(yamlData) assert.NoError(t, err) @@ -209,6 +218,10 @@ spec: assert.Equal(t, DefaultInstallSpec(), c.Spec.Install) assert.Equal(t, DefaultClusterTelemetry(), c.Spec.Telemetry) assert.Equal(t, DefaultKonnectivitySpec(), c.Spec.Konnectivity) + + e, err := ConfigFromString(extensionsYamlData) + assert.NoError(t, err) + assert.Equal(t, DefaultExtensions(), e.Spec.Extensions) } func TestWorkerProfileConfig(t *testing.T) { diff --git a/pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go b/pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go index 41e8121e5ec8..52567036a9a0 100644 --- a/pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go +++ b/pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go @@ -151,13 +151,17 @@ func (e *ClusterExtensions) Validate() []error { return errs } +func DefaultStorageExtension() *StorageExtension { + return &StorageExtension{ + Type: ExternalStorage, + CreateDefaultStorageClass: false, + } +} + // DefaultExtensions default values func DefaultExtensions() *ClusterExtensions { return &ClusterExtensions{ - Storage: &StorageExtension{ - Type: ExternalStorage, - CreateDefaultStorageClass: false, - }, - Helm: &HelmExtensions{}, + Storage: DefaultStorageExtension(), + Helm: &HelmExtensions{}, } }