Skip to content

Commit

Permalink
Add DefaultStorageExtension() and test
Browse files Browse the repository at this point in the history
Signed-off-by: danj-replicated <[email protected]>
(cherry picked from commit e80c996)
(cherry picked from commit 6afa1dd)
(cherry picked from commit 7a56d4b)
  • Loading branch information
danj-replicated authored and twz123 committed Dec 11, 2023
1 parent 72d5541 commit ee6d8d1
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 ee6d8d1

Please sign in to comment.