Skip to content

Commit 2b24782

Browse files
test(cf-common): add tests for rollouts (#45)
1 parent 317006f commit 2b24782

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+522
-244
lines changed

.github/workflows/lint-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ jobs:
131131
- name: Run unit tests
132132
run: |
133133
echo ${{ matrix.chart }}
134-
helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11
134+
helm plugin install https://github.com/quintush/helm-unittest --version v0.3.1
135135
helm dep update ${{ matrix.chart }}
136-
helm unittest --helm3 --color --debug -f "tests/**/*_test.yaml" ${{ matrix.chart }}
136+
helm unittest --color --debug -f "tests/**/*_test.yaml" ${{ matrix.chart }}
137137
138138
push-charts-dev-cm:
139139
needs:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: rollout error handlers
3+
templates:
4+
- templates/controller.yaml
5+
tests:
6+
- it: Test no steps for Canary rollout
7+
set:
8+
controller:
9+
rollout: null
10+
values:
11+
- values.yaml
12+
asserts:
13+
- failedTemplate:
14+
errorMessage: "controller.rollout.canary.steps is required!"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: rollout metadata
3+
templates:
4+
- templates/rollout.yaml
5+
tests:
6+
- it: Test rollout default metadata
7+
template: templates/controller.yaml
8+
values:
9+
- values.yaml
10+
asserts:
11+
- hasDocuments:
12+
count: 1
13+
- isKind:
14+
of: Rollout
15+
- isNull:
16+
path: metadata.annotations
17+
- equal:
18+
path: metadata.labels
19+
value:
20+
app.kubernetes.io/instance: RELEASE-NAME
21+
app.kubernetes.io/managed-by: Helm
22+
app.kubernetes.io/name: cf-common-test
23+
helm.sh/chart: cf-common-test-0.0.0
24+
- equal:
25+
path: metadata.name
26+
value: RELEASE-NAME-cf-common-test
27+
28+
- it: Test contoller should stay rollout if `.Values.controller.type=rollout` and `.Values.global.controller.type=deployment` are set
29+
template: templates/controller.yaml
30+
values:
31+
- values.yaml
32+
set:
33+
global:
34+
controller:
35+
type: deployment
36+
controller:
37+
type: rollout
38+
asserts:
39+
- hasDocuments:
40+
count: 1
41+
- isKind:
42+
of: Rollout
43+
- isNull:
44+
path: metadata.annotations
45+
- equal:
46+
path: metadata.labels
47+
value:
48+
app.kubernetes.io/instance: RELEASE-NAME
49+
app.kubernetes.io/managed-by: Helm
50+
app.kubernetes.io/name: cf-common-test
51+
helm.sh/chart: cf-common-test-0.0.0
52+
- equal:
53+
path: metadata.name
54+
value: RELEASE-NAME-cf-common-test
55+
56+
- it: Test contoller should stay deployment if `.Values.controller.type=deployment` and `.Values.global.controller.type=rollout` are set
57+
template: templates/controller.yaml
58+
values:
59+
- values.yaml
60+
set:
61+
global:
62+
controller:
63+
type: rollout
64+
controller:
65+
type: deployment
66+
asserts:
67+
- hasDocuments:
68+
count: 1
69+
- isKind:
70+
of: Deployment
71+
- isNull:
72+
path: metadata.annotations
73+
- equal:
74+
path: metadata.labels
75+
value:
76+
app.kubernetes.io/instance: RELEASE-NAME
77+
app.kubernetes.io/managed-by: Helm
78+
app.kubernetes.io/name: cf-common-test
79+
helm.sh/chart: cf-common-test-0.0.0
80+
- equal:
81+
path: metadata.name
82+
value: RELEASE-NAME-cf-common-test
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: rollout strategy
3+
templates:
4+
- templates/rollout.yaml
5+
tests:
6+
- it: Test rollout Canary strategy from default chart values
7+
template: templates/controller.yaml
8+
values:
9+
- values.yaml
10+
asserts:
11+
- equal:
12+
path: spec.strategy.canary
13+
value:
14+
maxUnavailable: 0
15+
maxSurge: 50%
16+
stableMetadata:
17+
labels:
18+
rollout/stage: stable
19+
canaryMetadata:
20+
labels:
21+
rollout/stage: canary
22+
steps:
23+
- setWeight: 20
24+
- pause:
25+
duration: 10s
26+
27+
- it: Test rollout Canary strategy from globals
28+
template: templates/controller.yaml
29+
values:
30+
- values_empty.yaml
31+
set:
32+
global:
33+
controller:
34+
rollout:
35+
canary:
36+
maxUnavailable: 1
37+
maxSurge: 75%
38+
stableMetadata:
39+
labels:
40+
rollout/stage: stable
41+
canaryMetadata:
42+
labels:
43+
rollout/stage: canary
44+
steps:
45+
- setWeight: 20
46+
- pause:
47+
duration: 10s
48+
asserts:
49+
- equal:
50+
path: spec.strategy.canary
51+
value:
52+
maxUnavailable: 1
53+
maxSurge: 75%
54+
stableMetadata:
55+
labels:
56+
rollout/stage: stable
57+
canaryMetadata:
58+
labels:
59+
rollout/stage: canary
60+
steps:
61+
- setWeight: 20
62+
- pause:
63+
duration: 10s
64+
65+
- it: Test rollout Canary strategy values priority (default chart values > globals)
66+
template: templates/controller.yaml
67+
values:
68+
- values.yaml
69+
set:
70+
global:
71+
controller:
72+
rollout:
73+
canary:
74+
maxUnavailable: 1
75+
maxSurge: 75%
76+
stableMetadata:
77+
labels:
78+
rollout/stage: stable
79+
canaryMetadata:
80+
labels:
81+
rollout/stage: canary
82+
steps:
83+
- setWeight: 20
84+
- pause:
85+
duration: 10s
86+
controller:
87+
rollout:
88+
canary:
89+
maxUnavailable: 0
90+
maxSurge: 50%
91+
stableMetadata:
92+
labels:
93+
rollout/stage: stable
94+
canaryMetadata:
95+
labels:
96+
rollout/stage: canary
97+
steps:
98+
- setWeight: 30
99+
- pause:
100+
duration: 20s
101+
asserts:
102+
- equal:
103+
path: spec.strategy.canary
104+
value:
105+
maxUnavailable: 0
106+
maxSurge: 50%
107+
stableMetadata:
108+
labels:
109+
rollout/stage: stable
110+
canaryMetadata:
111+
labels:
112+
rollout/stage: canary
113+
steps:
114+
- setWeight: 30
115+
- pause:
116+
duration: 20s
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# mock values for tests
2+
global: {}
3+
4+
controller:
5+
enabled: true
6+
type: rollout
7+
labels: {}
8+
annotations: {}
9+
rollout:
10+
canary:
11+
maxUnavailable: 0
12+
maxSurge: 50%
13+
stableMetadata:
14+
labels:
15+
rollout/stage: stable
16+
canaryMetadata:
17+
labels:
18+
rollout/stage: canary
19+
steps:
20+
- setWeight: 20
21+
- pause:
22+
duration: 10s
23+
24+
container:
25+
image:
26+
registry: docker.io
27+
repository: nginx
28+
tag: master
29+
pullPolicy: Always
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# mock values for tests
2+
global: {}
3+
4+
controller:
5+
enabled: true
6+
type: rollout
7+
labels: {}
8+
annotations: {}
9+
rollout: {}
10+
11+
container:
12+
image:
13+
registry: docker.io
14+
repository: nginx
15+
tag: master
16+
pullPolicy: Always

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.9.2
5+
version: 0.9.3
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.9.2](https://img.shields.io/badge/Version-0.9.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.9.3](https://img.shields.io/badge/Version-0.9.3-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.9.2
21+
version: 0.9.3
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -96,7 +96,7 @@ dependencies:
9696
| controller.rollout.canary.steps[0] | object | `{"setWeight":null}` | Sets the ratio of canary ReplicaSet in percentage. |
9797
| controller.rollout.canary.steps[1] | object | `{"pause":{"duration":null}}` | Pauses the rollout for configured duration of time. Supported units: s, m, h. when setting `duration: {}` it will pauses indefinitely until manually resumed |
9898
| controller.rollout.strategy | string | `nil` | Rollout update strategy - can be Canary or BlueGreen. |
99-
| controller.strategy | string | `nil` | Set controller upgrade strategy For Deployment: `RollingUpdate`(default) / `Recreate` For StatefulSet: `RollingUpdate`(default) / `OnDelete` |
99+
| controller.strategy | string | `nil` | Set controller upgrade strategy For Deployment: `RollingUpdate`(default) / `Recreate` For StatefulSet: `RollingUpdate`(default) / `OnDelete` For Rollout: `Canary(default) / `BlueGreen` |
100100
| controller.type | string | `""` | Define the controller type (`deployment`/`rollout`/`job`/`cronjob`) |
101101
| extraResources | list | `[]` | Array of extra objects to deploy with the release |
102102
| global | object | `{"controller":{},"env":{},"imagePullSecrets":[],"imageRegistry":""}` | Global parameters |

charts/cf-common/templates/classic/_helpers.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Calculate RabbitMQ URI (for On-Prem)
33
Must me called from chart root context.
44
Usage:
5-
{{ include "cf-common-0.9.2.classic.calculateRabbitMqUri" . }}
5+
{{ include "cf-common-0.9.3.classic.calculateRabbitMqUri" . }}
66
*/}}
77

8-
{{- define "cf-common-0.9.2.classic.calculateRabbitMqUri" }}
8+
{{- define "cf-common-0.9.3.classic.calculateRabbitMqUri" }}
99

1010
{{- $rabbitmqProtocol := .Values.global.rabbitmqProtocol | default "amqp" -}}
1111
{{- $rabbitmqUsername := .Values.global.rabbitmqUsername -}}
@@ -23,9 +23,9 @@ coalesce here for backward compatibility
2323
{{/*
2424
Calculate Mongo Uri (for On-Prem)
2525
Usage:
26-
{{ include "cf.common-0.9.2.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
26+
{{ include "cf.common-0.9.3.classic.calculateMongoUri" (dict "dbName" $.Values.global.pipelineManagerService "mongoURI" $.Values.global.mongoURI) }}
2727
*/}}
28-
{{- define "cf-common-0.9.2.classic.calculateMongoUri" -}}
28+
{{- define "cf-common-0.9.3.classic.calculateMongoUri" -}}
2929
{{- if contains "?" .mongoURI -}}
3030
{{- $mongoURI := (splitList "?" .mongoURI) -}}
3131
{{- printf "%s%s?%s" (first $mongoURI) .dbName (last $mongoURI) }}
@@ -37,7 +37,7 @@ Usage:
3737
{{/*
3838
Calculate Consul host Uri (for On-Prem)
3939
*/}}
40-
{{- define "cf-common-0.9.2.classic.calculateConsulUri" }}
40+
{{- define "cf-common-0.9.3.classic.calculateConsulUri" }}
4141
{{- if .Values.global.consulHost }}
4242
{{- printf "http://%s:%v" .Values.global.consulHost .Values.global.consulHttpPort -}}
4343
{{- else }}

charts/cf-common/templates/common/_annotations.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
Render checksum annotation
33
Must be called from chart root context.
44
Usage:
5-
annotations: {{ include "cf-common-0.9.2.annotations.podAnnotations" . | nindent }}
5+
annotations: {{ include "cf-common-0.9.3.annotations.podAnnotations" . | nindent }}
66
*/}}
7-
{{- define "cf-common-0.9.2.annotations.podAnnotations" -}}
7+
{{- define "cf-common-0.9.3.annotations.podAnnotations" -}}
88

99
{{- if .Values.podAnnotations -}}
10-
{{- include "cf-common-0.9.2.tplrender" (dict "Values" .Values.podAnnotations "context" $) | nindent 0 }}
10+
{{- include "cf-common-0.9.3.tplrender" (dict "Values" .Values.podAnnotations "context" $) | nindent 0 }}
1111
{{- end -}}
1212

1313
{{- $configMapFound := dict -}}
1414
{{- range $configMapIndex, $configMapItem := .Values.configMaps -}}
1515

1616
{{- if $configMapItem.enabled -}}
17-
{{- $_ := set $configMapFound $configMapIndex ( include "cf-common-0.9.2.tplrender" (dict "Values" $configMapItem.data "context" $) | sha256sum) -}}
17+
{{- $_ := set $configMapFound $configMapIndex ( include "cf-common-0.9.3.tplrender" (dict "Values" $configMapItem.data "context" $) | sha256sum) -}}
1818
{{- end -}}
1919

2020
{{- if $configMapFound -}}
@@ -27,7 +27,7 @@ annotations: {{ include "cf-common-0.9.2.annotations.podAnnotations" . | nindent
2727
{{- range $secretIndex, $secretItem := .Values.secrets -}}
2828

2929
{{- if $secretItem.enabled -}}
30-
{{- $_ := set $secretFound $secretIndex ( include "cf-common-0.9.2.tplrender" (dict "Values" $secretItem.stringData "context" $) | sha256sum) -}}
30+
{{- $_ := set $secretFound $secretIndex ( include "cf-common-0.9.3.tplrender" (dict "Values" $secretItem.stringData "context" $) | sha256sum) -}}
3131
{{- end -}}
3232

3333
{{- if $secretFound -}}

0 commit comments

Comments
 (0)