Skip to content

Commit

Permalink
feat(test): tesi if chart is upgraded and error is triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
paologallinaharbur committed Jun 13, 2022
1 parent d4e6322 commit 8001304
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@ func TestReadAllChartDirectories(t *testing.T) {
"test_charts/bar",
"test_charts/must-pass-upgrade-install",
"test_charts/mutating-deployment-selector",
"test_charts/simple-deployment",
"test_charts/simple-deployment-different-selector",
"test_charts/mutating-sfs-volumeclaim",
"test_chart_at_root",
}
for _, chart := range actual {
assert.Contains(t, expected, chart)
}
assert.Len(t, actual, 6)
assert.Len(t, actual, 8)
assert.Nil(t, err)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/chart/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func TestUpgradeChart(t *testing.T) {
"test_charts/mutating-sfs-volumeclaim",
processError,
},
{
"change immutable deployment.spec.selector.matchLabels field",
"test_charts/simple-deployment",
"test_charts/simple-deployment-different-selector",
processError,
},
}

for _, tc := range cases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nginx
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Simple chart with a Deployment having a different selector.

The integration test will install first simple-deployment and then try to upgrade
to simple-deployment-different-selector failing as expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "nginx.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nginx.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nginx.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nginx.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
helm.sh/chart: {{ include "nginx.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
extra: label
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
extra: label
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""
5 changes: 5 additions & 0 deletions pkg/chart/test_charts/simple-deployment/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nginx
version: 0.1.0
4 changes: 4 additions & 0 deletions pkg/chart/test_charts/simple-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Simple chart with a Deployment.

The integration test will install first simple-deployment and then try to upgrade
to simple-deployment-different-selector failing as expected
32 changes: 32 additions & 0 deletions pkg/chart/test_charts/simple-deployment/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "nginx.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nginx.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nginx.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
29 changes: 29 additions & 0 deletions pkg/chart/test_charts/simple-deployment/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nginx.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
helm.sh/chart: {{ include "nginx.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "nginx.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
11 changes: 11 additions & 0 deletions pkg/chart/test_charts/simple-deployment/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""

0 comments on commit 8001304

Please sign in to comment.