Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: scale down workloads based on middleware provided metadata #1693

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions library/common-test/tests/cronjob/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tests:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3
suspend: false
startingDeadlineSeconds:
- documentIndex: *cronJobDoc
isSubset:
Expand Down Expand Up @@ -83,3 +84,71 @@ tests:
parallelism: 5
ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100

- it: should set suspend to true
set:
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "*/5 * * * *"
suspend: true
podSpec:
restartPolicy: Never
asserts:
- documentIndex: *cronJobDoc
isSubset:
path: spec
content:
schedule: "*/5 * * * *"
timeZone: UTC
suspend: true

- it: should set suspend to true on ixChartContext - isStopped (true)
set:
global:
ixChartContext:
storageClassName: some-storage-class
isStopped: true
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "*/5 * * * *"
suspend: false
podSpec:
restartPolicy: Never
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:
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: CronJob
schedule: "*/5 * * * *"
suspend: false
podSpec:
restartPolicy: Never
asserts:
- documentIndex: *cronJobDoc
isSubset:
path: spec
content:
schedule: "*/5 * * * *"
timeZone: UTC
suspend: false
40 changes: 40 additions & 0 deletions library/common-test/tests/deployment/spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,43 @@ tests:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0

- it: should set replicas to 0 on ixChartContext - isStopped (true)
set:
global:
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:
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 @@ -54,3 +54,45 @@ tests:
parallelism: 5
ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100

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

- it: should not set parallelism to 0 on ixChartContext - isStopped (false)
set:
global:
ixChartContext:
storageClassName: some-storage-class
isStopped: false
workload:
workload-name:
enabled: true
primary: true
type: Job
parallelism: 3
podSpec:
restartPolicy: Never
asserts:
- documentIndex: *jobDoc
isSubset:
path: spec
content:
parallelism: 3
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: common
description: A library chart for iX Official Catalog
type: library
version: 1.2.0
version: 1.2.1
appVersion: v1
annotations:
title: Common Library Chart
Expand Down
12 changes: 12 additions & 0 deletions library/common/templates/helpers/_isStopped.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- define "ix.v1.common.helper.isStopped" -}}
{{- $rootCtx := . -}}

{{- $stop := "" -}}
{{- with $rootCtx.Values.global.ixChartContext -}}
{{- if .isStopped -}}
{{- $stop = true -}}
{{- end -}}
{{- end -}}

{{- $stop -}}
{{- end -}}
5 changes: 5 additions & 0 deletions library/common/templates/lib/workload/_cronjobSpec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ objectData:
{{- define "ix.v1.common.lib.workload.cronjobSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $suspend := $objectData.suspend | default false -}}
{{- if (include "ix.v1.common.helper.isStopped" $rootCtx) -}}
{{- $suspend = true -}}
{{- end }}
timeZone: {{ (tpl ($objectData.timezone | default $rootCtx.Values.TZ) $rootCtx) | quote }}
schedule: {{ (tpl $objectData.schedule $rootCtx) | quote }}
concurrencyPolicy: {{ $objectData.concurrencyPolicy | default "Forbid" }}
failedJobsHistoryLimit: {{ $objectData.failedJobsHistoryLimit | default 1 }}
successfulJobsHistoryLimit: {{ $objectData.successfulJobsHistoryLimit | default 3 }}
startingDeadlineSeconds: {{ $objectData.startingDeadlineSeconds | default nil }}
suspend: {{ $suspend }}
jobTemplate:
spec:
{{- include "ix.v1.common.lib.workload.jobSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) | nindent 4 }}
Expand Down
11 changes: 9 additions & 2 deletions library/common/templates/lib/workload/_deployementSpec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ objectData:
{{- define "ix.v1.common.lib.workload.deploymentSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $strategy := $objectData.strategy | default "Recreate" }}
replicas: {{ $objectData.replicas | default 1 }}
{{- $strategy := $objectData.strategy | default "Recreate" -}}
{{- $replicas := 1 -}}
{{- if hasKey $objectData "replicas" -}}
{{- $replicas = $objectData.replicas -}}
{{- end -}}
{{- if (include "ix.v1.common.helper.isStopped" $rootCtx) -}}
{{- $replicas = 0 -}}
{{- end }}
replicas: {{ $replicas }}
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
strategy:
type: {{ $strategy }}
Expand Down
9 changes: 8 additions & 1 deletion library/common/templates/lib/workload/_jobSpec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ objectData:
{{- define "ix.v1.common.lib.workload.jobSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $parallelism := 1 -}}
{{- if hasKey $objectData "parallelism" -}}
{{- $parallelism = $objectData.parallelism -}}
{{- end -}}
{{- if (include "ix.v1.common.helper.isStopped" $rootCtx) -}}
{{- $parallelism = 0 -}}
{{- end }}
backoffLimit: {{ $objectData.backoffLimit | default 5 }}
completionMode: {{ $objectData.completionMode | default "NonIndexed" }}
completions: {{ $objectData.completions | default nil }}
parallelism: {{ $objectData.parallelism | default 1 }}
parallelism: {{ $parallelism }}
ttlSecondsAfterFinished: {{ $objectData.ttlSecondsAfterFinished | default 120 }}
{{- with $objectData.activeDeadlineSeconds }}
activeDeadlineSeconds: {{ . }}
Expand Down
Loading