Skip to content

Commit 882d4be

Browse files
Fix integration tests for upgrade flag (#446)
* fix(test): deploment was not installing due to missing selector Signed-off-by: paologallinaharbur <[email protected]> * feat(test): tesi if chart is upgraded and error is triggered Signed-off-by: paologallinaharbur <[email protected]>
1 parent c49112d commit 882d4be

File tree

13 files changed

+178
-1
lines changed

13 files changed

+178
-1
lines changed

pkg/chart/chart_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,15 @@ func TestReadAllChartDirectories(t *testing.T) {
184184
"test_charts/bar",
185185
"test_charts/must-pass-upgrade-install",
186186
"test_charts/mutating-deployment-selector",
187+
"test_charts/simple-deployment",
188+
"test_charts/simple-deployment-different-selector",
187189
"test_charts/mutating-sfs-volumeclaim",
188190
"test_chart_at_root",
189191
}
190192
for _, chart := range actual {
191193
assert.Contains(t, expected, chart)
192194
}
193-
assert.Len(t, actual, 6)
195+
assert.Len(t, actual, 8)
194196
assert.Nil(t, err)
195197
}
196198

pkg/chart/integration_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ func TestUpgradeChart(t *testing.T) {
141141
"test_charts/mutating-sfs-volumeclaim",
142142
processError,
143143
},
144+
{
145+
"change immutable deployment.spec.selector.matchLabels field",
146+
"test_charts/simple-deployment",
147+
"test_charts/simple-deployment-different-selector",
148+
processError,
149+
},
144150
}
145151

146152
for _, tc := range cases {

pkg/chart/test_charts/mutating-deployment-selector/templates/deployment.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ metadata:
1212
revision: {{ .Release.Revision | quote }}
1313
spec:
1414
replicas: {{ .Values.replicaCount }}
15+
selector:
16+
matchLabels:
17+
app.kubernetes.io/name: {{ include "nginx.name" . }}
18+
app.kubernetes.io/instance: {{ .Release.Name }}
19+
revision: {{ .Release.Revision | quote }}
1520
template:
1621
metadata:
1722
labels:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes
4+
name: nginx
5+
version: 0.1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Simple chart with a Deployment having a different selector.
2+
3+
The integration test will install first simple-deployment and then try to upgrade
4+
to simple-deployment-different-selector failing as expected
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "nginx.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "nginx.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "nginx.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "nginx.fullname" . }}
5+
labels:
6+
app.kubernetes.io/name: {{ include "nginx.name" . }}
7+
helm.sh/chart: {{ include "nginx.chart" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
spec:
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
app.kubernetes.io/name: {{ include "nginx.name" . }}
15+
app.kubernetes.io/instance: {{ .Release.Name }}
16+
extra: label
17+
template:
18+
metadata:
19+
labels:
20+
app.kubernetes.io/name: {{ include "nginx.name" . }}
21+
app.kubernetes.io/instance: {{ .Release.Name }}
22+
extra: label
23+
spec:
24+
containers:
25+
- name: {{ .Chart.Name }}
26+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
27+
imagePullPolicy: {{ .Values.image.pullPolicy }}
28+
ports:
29+
- name: http
30+
containerPort: 80
31+
protocol: TCP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Default values for nginx.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
image:
6+
repository: nginx
7+
tag: stable
8+
pullPolicy: IfNotPresent
9+
10+
nameOverride: ""
11+
fullnameOverride: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes
4+
name: nginx
5+
version: 0.1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Simple chart with a Deployment.
2+
3+
The integration test will install first simple-deployment and then try to upgrade
4+
to simple-deployment-different-selector failing as expected
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "nginx.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "nginx.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "nginx.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "nginx.fullname" . }}
5+
labels:
6+
app.kubernetes.io/name: {{ include "nginx.name" . }}
7+
helm.sh/chart: {{ include "nginx.chart" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
spec:
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
app.kubernetes.io/name: {{ include "nginx.name" . }}
15+
app.kubernetes.io/instance: {{ .Release.Name }}
16+
template:
17+
metadata:
18+
labels:
19+
app.kubernetes.io/name: {{ include "nginx.name" . }}
20+
app.kubernetes.io/instance: {{ .Release.Name }}
21+
spec:
22+
containers:
23+
- name: {{ .Chart.Name }}
24+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
25+
imagePullPolicy: {{ .Values.image.pullPolicy }}
26+
ports:
27+
- name: http
28+
containerPort: 80
29+
protocol: TCP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Default values for nginx.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
5+
image:
6+
repository: nginx
7+
tag: stable
8+
pullPolicy: IfNotPresent
9+
10+
nameOverride: ""
11+
fullnameOverride: ""

0 commit comments

Comments
 (0)