Skip to content

Commit

Permalink
Merge pull request k0sproject#3804 from twz123/backport-3796-to-relea…
Browse files Browse the repository at this point in the history
…se-1.26

[Backport release-1.26] Add DefaultStorageExtension() and test
  • Loading branch information
twz123 authored Dec 16, 2023
2 parents c6603b1 + ee6d8d1 commit 8a1458e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/k0s.k0sproject.io/v1beta1/clusterconfig_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions pkg/apis/k0s.k0sproject.io/v1beta1/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
}

0 comments on commit 8a1458e

Please sign in to comment.