Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
add reclaim policy
Browse files Browse the repository at this point in the history
  • Loading branch information
surajssd committed Feb 11, 2021
1 parent 8683071 commit f82a7bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/components/rook-ceph/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type component struct {

// StorageClass provides struct to enable it or make it default.
type StorageClass struct {
Enable bool `hcl:"enable,optional"`
Default bool `hcl:"default,optional"`
Enable bool `hcl:"enable,optional"`
Default bool `hcl:"default,optional"`
ReclaimPolicy string `hcl:reclaim_policy,optional`
}

// NewConfig returns new Rook Ceph component configuration with default values set.
Expand All @@ -56,7 +57,7 @@ func NewConfig() *component {
return &component{
Namespace: "rook",
MonitorCount: 1,
StorageClass: &StorageClass{},
StorageClass: &StorageClass{ReclaimPolicy: "Retain"},
}
}

Expand Down
43 changes: 43 additions & 0 deletions pkg/components/rook-ceph/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/hashicorp/hcl/v2"

"github.com/kinvolk/lokomotive/pkg/components/internal/testutil"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

Expand Down Expand Up @@ -82,3 +83,45 @@ component "rook-ceph" {
t.Fatalf("Rendered manifests shouldn't be empty")
}
}

func TestConversion(t *testing.T) {
testCases := []struct {
name string
inputConfig string
expectedManifestName string
expected string
jsonPath string
}{
{
name: "default reclaim policy",
inputConfig: `component "rook-ceph" {}`,
expectedManifestName: "",
jsonPath: "{.reclaimPolicy}",
expected: "Retain",
},
{
name: "over-ridden reclaim policy",
inputConfig: `component "rook-ceph" {
storage_class {
reclaim_policy = "Delete"
}
}`,
expectedManifestName: "",
jsonPath: "{.reclaimPolicy}",
expected: "Delete",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

component := NewConfig()
m := testutil.RenderManifests(t, component, Name, tc.inputConfig)
gotConfig := testutil.ConfigFromMap(t, m, tc.expectedManifestName)

testutil.MatchJSONPathStringValue(t, gotConfig, tc.jsonPath, tc.expected)
})
}
}
2 changes: 1 addition & 1 deletion pkg/components/rook-ceph/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ parameters:
csi.storage.k8s.io/fstype: xfs
# Delete the rbd volume when a PVC is deleted
reclaimPolicy: Delete
reclaimPolicy: {{ .StorageClass.ReclaimPolicy }}
{{- end }}
`,

Expand Down

0 comments on commit f82a7bf

Please sign in to comment.