From ee6d8d18dff85ea8d2a24806dae55b7a42235ce0 Mon Sep 17 00:00:00 2001 From: danj-replicated Date: Mon, 27 Nov 2023 12:53:25 +0000 Subject: [PATCH] Add DefaultStorageExtension() and test Signed-off-by: danj-replicated (cherry picked from commit e80c996d60a814e414e2149458dab536e37983ca) (cherry picked from commit 6afa1dd17035c4d574b73bd4e53149e0f83c8c1a) (cherry picked from commit 7a56d4bcf7df3971f2da63c7dda66394fd53e2b9) --- .../v1beta1/clusterconfig_types.go | 3 +++ .../v1beta1/clusterconfig_types_test.go | 13 +++++++++++++ pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go | 14 +++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) 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{}, } }