Skip to content

Commit

Permalink
chore(stopAll): handle scale specific case for stopping (#539)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 🔃 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.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ 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._
  • Loading branch information
stavros-k committed Oct 28, 2023
1 parent 0ed2bc0 commit 98822c8
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 10 deletions.
84 changes: 84 additions & 0 deletions library/common-test/tests/cnpg/stop_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,87 @@ tests:
path: spec
content:
instances: 0

- it: should set hibernate and 0 instances on ixChartContext - isStopped
set:
operator:
verify:
enabled: false
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
cnpg:
main:
enabled: true
primary: true
user: app
database: app
hibernate: false
instances: 2
asserts:
- documentIndex: &clusterDoc 0
isKind:
of: Cluster
- documentIndex: *clusterDoc
isAPIVersion:
of: postgresql.cnpg.io/v1
- documentIndex: *clusterDoc
isSubset:
path: metadata.annotations
content:
cnpg.io/hibernation: "on"
- documentIndex: &poolerDoc 1
isKind:
of: Pooler
- documentIndex: *poolerDoc
isAPIVersion:
of: postgresql.cnpg.io/v1
- documentIndex: *poolerDoc
isSubset:
path: spec
content:
instances: 0

- it: should not set hibernate and 0 instances on ixChartContext - isStopped
set:
operator:
verify:
enabled: false
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
cnpg:
main:
enabled: true
primary: true
user: app
database: app
hibernate: false
instances: 2
asserts:
- documentIndex: &clusterDoc 0
isKind:
of: Cluster
- documentIndex: *clusterDoc
isAPIVersion:
of: postgresql.cnpg.io/v1
- documentIndex: *clusterDoc
isSubset:
path: metadata.annotations
content:
cnpg.io/hibernation: "off"
- documentIndex: &poolerDoc 1
isKind:
of: Pooler
- documentIndex: *poolerDoc
isAPIVersion:
of: postgresql.cnpg.io/v1
- documentIndex: *poolerDoc
isSubset:
path: spec
content:
instances: 2
48 changes: 48 additions & 0 deletions library/common-test/tests/cronjob/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,51 @@ tests:
schedule: "*/5 * * * *"
timeZone: UTC
suspend: true

- it: should set suspend to true on ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "*/5 * * * *"
suspend: false
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
isSubset:
path: spec
content:
schedule: "*/5 * * * *"
timeZone: UTC
suspend: true

- it: should not set suspend to true on ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "*/5 * * * *"
suspend: false
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
isSubset:
path: spec
content:
schedule: "*/5 * * * *"
timeZone: UTC
suspend: false
42 changes: 42 additions & 0 deletions library/common-test/tests/deployment/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,45 @@ tests:
path: spec
content:
replicas: 0

- it: should set replicas to 0 on ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
workload:
workload-name:
enabled: true
primary: true
type: Deployment
replicas: 2
podSpec: {}
asserts:
- documentIndex: *deploymentDoc
isSubset:
path: spec
content:
replicas: 0

- it: should not set replicas to 0 on ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: Deployment
replicas: 2
podSpec: {}
asserts:
- documentIndex: *deploymentDoc
isSubset:
path: spec
content:
replicas: 2
42 changes: 42 additions & 0 deletions library/common-test/tests/job/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,45 @@ tests:
path: spec
content:
parallelism: 0

- it: should set parallelism to 0 on ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
workload:
workload-name:
enabled: true
primary: true
type: Job
parallelism: 3
podSpec: {}
asserts:
- documentIndex: *jobDoc
isSubset:
path: spec
content:
parallelism: 0

- it: should not set parallelism to 0 on ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: Job
parallelism: 3
podSpec: {}
asserts:
- documentIndex: *jobDoc
isSubset:
path: spec
content:
parallelism: 3
96 changes: 94 additions & 2 deletions library/common-test/tests/pod/node_selector_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tests:
disk: ssd
cpu: intel

- it: should set nodeSelector to non-existing on DaemonSet
- it: should set nodeSelector to non-existing on DaemonSet with stopAll
set:
global:
stopAll: true
Expand All @@ -65,7 +65,53 @@ tests:
value:
non-existing: "true"

- it: should not container non-existing on non-DaemonSet
- it: should set nodeSelector to non-existing on DaemonSet with ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
podOptions:
nodeSelector:
disk: ssd
workload:
workload-name1:
enabled: true
primary: true
type: DaemonSet
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
equal:
path: spec.template.spec.nodeSelector
value:
non-existing: "true"

- it: should not set nodeSelector to non-existing on DaemonSet with ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
podOptions:
nodeSelector:
disk: ssd
workload:
workload-name1:
enabled: true
primary: true
type: DaemonSet
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
notEqual:
path: spec.template.spec.nodeSelector
value:
non-existing: "true"

- it: should not set nodeSelector to non-existent on non-DaemonSet with stopAll
set:
global:
stopAll: true
Expand All @@ -85,6 +131,52 @@ tests:
value:
non-existing: "true"

- it: should not set nodeSelector to non-existent on non-DaemonSet with ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
podOptions:
nodeSelector:
disk: ssd
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
notEqual:
path: spec.template.spec.nodeSelector
value:
non-existing: "true"

- it: should not set nodeSelector to non-existent on non-DaemonSet with ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
podOptions:
nodeSelector:
disk: ssd
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *cronJobDoc
notEqual:
path: spec.template.spec.nodeSelector
value:
non-existing: "true"

- it: should pass with nodeSelector from "pod"
set:
podOptions:
Expand Down
42 changes: 42 additions & 0 deletions library/common-test/tests/statefulset/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,45 @@ tests:
path: spec
content:
replicas: 0

- it: should set replicas to 0 on ixChartContext - isStopped (true)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: true
workload:
workload-name:
enabled: true
primary: true
type: StatefulSet
replicas: 2
podSpec: {}
asserts:
- documentIndex: *statefulSetDoc
isSubset:
path: spec
content:
replicas: 0

- it: should not set replicas to 0 on ixChartContext - isStopped (false)
set:
global:
namespace: ix-something
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: StatefulSet
replicas: 2
podSpec: {}
asserts:
- documentIndex: *statefulSetDoc
isSubset:
path: spec
content:
replicas: 2

0 comments on commit 98822c8

Please sign in to comment.