common: scale down workloads based on middleware provided metadata

This commit is contained in:
Stavros kois
2023-11-01 17:24:20 +02:00
committed by Stavros Kois
parent aa295ecea1
commit f004903659
8 changed files with 185 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ tests:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3
suspend: false
startingDeadlineSeconds:
- documentIndex: *cronJobDoc
isSubset:
@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 -}}

View File

@@ -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 }}

View File

@@ -11,7 +11,14 @@ objectData:
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $strategy := $objectData.strategy | default "Recreate" }}
replicas: {{ $objectData.replicas | default 1 }}
{{- $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 }}

View File

@@ -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: {{ . }}