Skip to content

Commit 0c1aaee

Browse files
authored
feat(cf-common): Add Rollout lib template (#12)
* rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic * rollout lib template for classic
1 parent da581cf commit 0c1aaee

File tree

5 files changed

+120
-7
lines changed

5 files changed

+120
-7
lines changed

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.0.11
5+
version: 0.0.12
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.0.11](https://img.shields.io/badge/Version-0.0.11-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.0.12](https://img.shields.io/badge/Version-0.0.12-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.0.11
21+
version: 0.0.12
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -71,7 +71,7 @@ dependencies:
7171
| controller.revisionHistoryLimit | string | `nil` | Set ReplicaSet revision history limit |
7272
| controller.type | string | `nil` | Define the controller type (`deployment`) |
7373
| extraResources | list | `[]` | Array of extra objects to deploy with the release |
74-
| global | object | `{"env":{},"imagePullSecrets":[],"imageRegistry":""}` | Global parameters |
74+
| global | object | `{"env":{},"imagePullSecrets":[],"imageRegistry":"","rollout":{"analysis":{"successfulRunHistoryLimit":4,"unsuccessfulRunHistoryLimit":2},"canary":{"maxSurge":"25%","maxUnavailable":1,"steps":[{"setWeight":10},{"pause":{"duration":"1h"}},{"setWeight":20},{"pause":{"duration":{}}}]},"strategy":"Canary"}}` | Global parameters |
7575
| global.env | object | `{}` | Global Env vars. NO precedence over `.Values.container.env` |
7676
| global.imagePullSecrets | list | `[]` | Global Docker registry secret names as array |
7777
| global.imageRegistry | string | `""` | Global Docker image registry |

charts/cf-common/templates/controller/_controller.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Usage:
1010
{{- if .Values.controller.enabled -}}
1111
{{- if eq .Values.controller.type "deployment" }}
1212
{{ include "cf-common.controller.deployment" . | nindent 0 }}
13+
{{- else if eq .Values.controller.type "rollout" }}
14+
{{ include "cf-common.controller.rollout" . | nindent 0 }}
1315
{{- else }}
1416
{{ fail (printf "ERROR: %s is invalid controller type!" .Values.controller.type) }}
1517
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Renders rollout template
3+
Usage:
4+
{{ include "cf-common.controller.rollout" . | nindent 0 }}
5+
*/}}
6+
{{- define "cf-common.controller.rollout" -}}
7+
8+
{{- $strategy := default .Values.global.rollout.strategy .Values.controller.rollout.strategy -}}
9+
{{- $fullName:= include "cf-common.names.fullname" . }}
10+
11+
{{- if and (ne $strategy "Canary") (ne $strategy "BlueGreen") -}}
12+
{{- fail (printf "ERROR: %s is invalid Rollout strategy!" $strategy) -}}
13+
{{- end -}}
14+
15+
---
16+
apiVersion: argoproj.io/v1alpha1
17+
kind: Rollout
18+
metadata:
19+
name: {{ include "cf-common.names.fullname" . }}
20+
labels: {{ include "cf-common.labels.standard" . | nindent 4 }}
21+
{{- if .Values.controller.labels }}
22+
{{- include "cf-common.tplrender" (dict "Values" .Values.controller.labels "context" $) | nindent 4 }}
23+
{{- end }}
24+
{{- if .Values.controller.annotations }}
25+
annotations:
26+
{{- include "cf-common.tplrender" (dict "Values" .Values.controller.annotations "context" $) | nindent 4 }}
27+
{{- end }}
28+
spec:
29+
revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit | int | default 5 }}
30+
{{- if (ne .Values.hpa.enabled true) }}
31+
replicas: {{ coalesce .Values.controller.replicas .Values.replicaCount | int | default 1 }}
32+
{{- end }}
33+
selector:
34+
matchLabels: {{ include "cf-common.labels.matchLabels" . | nindent 6 }}
35+
{{- with .Values.controller.rollout }}
36+
analysis: {{ default $.Values.global.rollout.analysis .analysis | toYaml | nindent 4 }}
37+
{{- end }}
38+
strategy:
39+
{{- if eq $strategy "Canary" }}
40+
{{- with .Values.controller.rollout.canary }}
41+
canary:
42+
maxUnavailable: {{ default $.Values.global.rollout.canary.maxUnavailable .maxUnavailable }}
43+
maxSurge: {{ default $.Values.global.rollout.canary.maxSurge .maxSurge }}
44+
stableMetadata: {{ default $.Values.global.rollout.canary.stableMetadata .stableMetadata| toYaml | nindent 8 }}
45+
canaryMetadata: {{ default $.Values.global.rollout.canary.canaryMetadata .canaryMetadata| toYaml | nindent 8 }}
46+
stableService: {{ .stableService | default (printf "%s-stable" ( $fullName )) }}
47+
canaryService: {{ .canaryService | default (printf "%s-canary" ( $fullName )) }}
48+
steps: {{ default $.Values.global.rollout.canary.steps .steps | toYaml | nindent 6 }}
49+
{{- end}}
50+
{{- end }}
51+
template:
52+
metadata:
53+
labels: {{ include "cf-common.labels.matchLabels" . | nindent 8 }}
54+
{{- if .Values.podLabels }}
55+
{{- include "cf-common.tplrender" (dict "Values" .Values.podLabels "context" $) | nindent 8 }}
56+
{{- end }}
57+
{{- if .Values.podAnnotations }}
58+
annotations:
59+
{{- include "cf-common.tplrender" (dict "Values" .Values.podAnnotations "context" $) | nindent 8 }}
60+
{{- end }}
61+
spec: {{- include "cf-common.controller.pod" . | trim | nindent 6 -}}
62+
{{- end -}}

charts/cf-common/values.yaml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@ global:
77
# E.g.
88
# imagePullSecrets:
99
# - myRegistrySecret
10-
10+
# Global Rollout parameters
11+
rollout:
12+
analysis:
13+
# Limits the number of successful analysis runs and experiments to be stored in a history
14+
successfulRunHistoryLimit: 4
15+
# Limits the number of unsuccessful analysis runs and experiments to be stored in a history. ( Stages for unsuccessful: "Error", "Failed", "Inconclusive" )
16+
unsuccessfulRunHistoryLimit: 2
17+
# Rollout update strategy - can be Canary or BlueGreen.
18+
strategy: Canary
19+
# Canary update strategy parameters
20+
canary:
21+
# The maximum number of pods that can be unavailable during the update. Value can be an absolute number / percentage
22+
maxUnavailable: 1
23+
# The maximum number of pods that can be scheduled above the original number of pods. Value can be an absolute number / percentage
24+
maxSurge: 25%
25+
# Steps define sequence of steps to take during an update of the canary.
26+
steps:
27+
# Sets the ratio of canary ReplicaSet in percentage.
28+
- setWeight: 10
29+
# Pauses the rollout for configured duration of time. Supported units: s, m, h. when setting `duration: {}` it will pauses indefinitely until manually resumed
30+
- pause:
31+
duration: 1h
32+
- setWeight: 20
33+
- pause:
34+
duration: {}
1135
# -- Global Env vars. NO precedence over `.Values.container.env`
1236
env: {}
1337

@@ -22,6 +46,8 @@ controller:
2246
annotations: {}
2347
# -- Set number of pods
2448
replicas:
49+
# -- Set ReplicaSet revision history limit
50+
revisionHistoryLimit:
2551
# Deployment parameters
2652
deployment:
2753
# -- Set deployment upgrade strategy (`RollingUpdate`/`Recreate`)
@@ -32,8 +58,31 @@ controller:
3258
maxUnavailable:
3359
# -- Set RollingUpdate max surge (absolute number or percentage)
3460
maxSurge:
35-
# -- Set ReplicaSet revision history limit
36-
revisionHistoryLimit:
61+
# Rollout parameters (overrides for global.rollout values)
62+
rollout:
63+
analysis:
64+
# Limits the number of successful analysis runs and experiments to be stored in a history
65+
successfulRunHistoryLimit: 4
66+
# Limits the number of unsuccessful analysis runs and experiments to be stored in a history. ( Stages for unsuccessful: "Error", "Failed", "Inconclusive" )
67+
unsuccessfulRunHistoryLimit: 2
68+
# Rollout update strategy - can be Canary or BlueGreen.
69+
strategy: Canary
70+
# Canary update strategy parameters
71+
canary:
72+
# The maximum number of pods that can be unavailable during the update. Value can be an absolute number / percentage
73+
maxUnavailable: 1
74+
# The maximum number of pods that can be scheduled above the original number of pods. Value can be an absolute number / percentage
75+
maxSurge: 25%
76+
# Steps define sequence of steps to take during an update of the canary.
77+
steps:
78+
# Sets the ratio of canary ReplicaSet in percentage.
79+
- setWeight: 10
80+
# Pauses the rollout for configured duration of time. Supported units: s, m, h. when setting `duration: {}` it will pauses indefinitely until manually resumed
81+
- pause:
82+
duration: 1h
83+
- setWeight: 20
84+
- pause:
85+
duration: {}
3786

3887
# -- Set image pull secrets as array
3988
imagePullSecrets: []

0 commit comments

Comments
 (0)