Skip to content

Commit

Permalink
feat(common): add storageClass class/spawner (#578)
Browse files Browse the repository at this point in the history
**Description**

Adds support for creating storageClasses on demand through common.
Allows us for easy inclusion of more dynamic pvc provisioners on SCALE
and other platforms

⚒️ Fixes  #559 

**⚙️ Type of change**

- [x] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning

**➕ App addition**

If this PR is an app addition please make sure you have done the
following.

- [x] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [x] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._

---------

Co-authored-by: Stavros Kois <[email protected]>
Co-authored-by: Stavros kois <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2023
1 parent a0df81b commit 6d88c6d
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/common-test/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appVersion: ""
dependencies:
- name: common
repository: file://../common
version: ~14.3.0
version: ~14.4.0
deprecated: false
description: Helper chart to test different use cases of the common library
home: https://github.com/truecharts/apps/tree/master/charts/library/common-test
Expand Down
65 changes: 65 additions & 0 deletions library/common-test/ci/storageclass-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
service:
main:
enabled: true
primary: true
ports:
main:
enabled: true
primary: true
protocol: http
port: 8080

workload:
main:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
main:
enabled: true
primary: true
args:
- --port
- "8080"
probes:
liveness:
enabled: true
type: http
port: "{{ .Values.service.main.ports.main.port }}"
readiness:
enabled: true
type: http
port: "{{ .Values.service.main.ports.main.port }}"
startup:
enabled: true
type: http
port: "{{ .Values.service.main.ports.main.port }}"

# -- create storageClasses on demand
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
example2:
enabled: true
provisioner: some.provisioner.io
reclaimPolicy: retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
example3:
enabled: true
provisioner: some.provisioner.io
parameters: {}
mountOptions: []
example4:
enabled: true
provisioner: some.provisioner.io
parameters: {}
reclaimPolicy: retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
mountOptions: []

manifestManager:
enabled: false
60 changes: 60 additions & 0 deletions library/common-test/tests/storageClass/metadata_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
suite: storageClass metadata test
templates:
- common.yaml
chart:
appVersion: &appVer v9.9.9
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should pass with storageClass created with labels and annotations
set:
label1: label1
label2: global_label2
annotation1: annotation1
annotation2: global_annotation2
global:
labels:
g_label1: global_label1
g_label2: "{{ .Values.label2 }}"
annotations:
g_annotation1: global_annotation1
g_annotation2: "{{ .Values.annotation2 }}"
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
labels:
label1: "{{ .Values.label1 }}"
label2: label2
annotations:
annotation1: "{{ .Values.annotation1 }}"
annotation2: annotation2
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: metadata.annotations
value:
annotation1: annotation1
annotation2: annotation2
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *storageClassDoc
equal:
path: metadata.labels
value:
app: common-test-1.0.0
release: test-release-name
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/name: common-test
app.kubernetes.io/instance: test-release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
label2: label2
37 changes: 37 additions & 0 deletions library/common-test/tests/storageClass/names_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
suite: storageClass name test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should generate correct name
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
example2:
enabled: true
provisioner: some.provisioner.io
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
isAPIVersion:
of: storage.k8s.io/v1
- documentIndex: *storageClassDoc
equal:
path: metadata.name
value: test-release-name-common-test-example1
- documentIndex: &otherStorageClassDoc 1
isKind:
of: StorageClass
- documentIndex: *otherStorageClassDoc
isAPIVersion:
of: storage.k8s.io/v1
- documentIndex: *otherStorageClassDoc
equal:
path: metadata.name
value: test-release-name-common-test-example2
187 changes: 187 additions & 0 deletions library/common-test/tests/storageClass/spec_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
suite: storageClass name test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should generate correct spec with provisioner provided
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
isAPIVersion:
of: storage.k8s.io/v1
- documentIndex: *storageClassDoc
equal:
path: provisioner
value: some.provisioner.io
- documentIndex: *storageClassDoc
equal:
path: reclaimPolicy
value: Retain
- documentIndex: *storageClassDoc
equal:
path: allowVolumeExpansion
value: true
- documentIndex: *storageClassDoc
equal:
path: volumeBindingMode
value: Immediate

- it: should generate correct spec with non-default reclaim policy
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
reclaimPolicy: Delete
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: reclaimPolicy
value: Delete

- it: should generate correct spec with non-default allowVolumeExpansion
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
allowVolumeExpansion: false
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: allowVolumeExpansion
value: false

- it: should generate correct spec with parameters provided from tpl
set:
test:
key1: value1
key2: value2
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
parameters:
param1: "{{ .Values.test.key1 }}"
param2: "{{ .Values.test.key2 }}"
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: parameters
value:
param1: value1
param2: value2

- it: should generate correct spec with parameters provided
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
parameters:
param1: value1
param2: value2
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: parameters
value:
param1: value1
param2: value2

- it: should generate correct spec with mountOptions provided
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
mountOptions:
- option1
- option2=value2
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: mountOptions
value:
- option1
- option2=value2

- it: should generate correct spec with mountOptions provided from tpl
set:
test:
key1: option1
key2: value2
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
mountOptions:
- "{{ .Values.test.key1 }}"
- option2={{ .Values.test.key2 }}
asserts:
- documentIndex: &storageClassDoc 0
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: mountOptions
value:
- option1
- option2=value2

# Failures
- it: should fail without provisioner
set:
storageClass:
example1:
enabled: true
provisioner: ""
asserts:
- failedTemplate:
errorMessage: Storage Class - Expected non-empty [provisioner]

- it: should fail with invalid reclaimPolicy
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
reclaimPolicy: invalid
asserts:
- failedTemplate:
errorMessage: Storage Class - Expected [reclaimPolicy] to be one of [Retain, Delete], but got [invalid]

- it: should fail with invalid volumeBindingMode
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
volumeBindingMode: invalid
asserts:
- failedTemplate:
errorMessage: Storage Class - Expected [volumeBindingMode] to be one of [WaitForFirstConsumer, Immediate], but got [invalid]
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 14.3.5
version: 14.4.0
Loading

0 comments on commit 6d88c6d

Please sign in to comment.