Skip to content

Commit 0e0f954

Browse files
authored
Add dry run test for multi-doc yaml files (#3230)
* Add dry run test for multi-doc yaml files Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> * f Signed-off-by: Steven Crespo <[email protected]> --------- Signed-off-by: Steven Crespo <[email protected]>
1 parent 49e7cec commit 0e0f954

File tree

11 files changed

+123
-16
lines changed

11 files changed

+123
-16
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{- if .Values.preflight.enabled }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "redis-app.fullname" . }}-preflight
6+
labels:
7+
{{- include "redis-app.labels" . | nindent 4 }}
8+
data:
9+
preflight.yaml: |
10+
apiVersion: troubleshoot.sh/v1beta2
11+
kind: Preflight
12+
metadata:
13+
name: redis-app-preflight
14+
spec:
15+
collectors:
16+
- nodeResources: {}
17+
analyzers:
18+
- nodeResources:
19+
checkName: Node status check
20+
outcomes:
21+
- fail:
22+
when: "nodeCondition(Ready) == False"
23+
message: "Not all nodes are online."
24+
- fail:
25+
when: "nodeCondition(Ready) == Unknown"
26+
message: "Not all nodes are online."
27+
- pass:
28+
message: "All nodes are online."
29+
{{- end }}

e2e/helm-charts/redis-app/values.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Default values for redis-app
22
global:
33
labels: {}
4+
5+
# Preflight checks configuration
6+
preflight:
7+
enabled: false
8+
49
# Server (Redis) configuration
510
server:
611
replicaCount: 1
@@ -29,7 +34,7 @@ client:
2934
repository: redis
3035
pullPolicy: IfNotPresent
3136
tag: "7.2"
32-
intervalSeconds: 30 # Make a request every 30 seconds
37+
intervalSeconds: 30 # Make a request every 30 seconds
3338
resources:
3439
limits:
3540
cpu: 100m
@@ -66,4 +71,4 @@ nodeSelector: {}
6671

6772
tolerations: []
6873

69-
affinity: {}
74+
affinity: {}

tests/dryrun/assets/kotskinds-chart.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ spec:
1818
port: 80
1919
replicaCount: 1
2020
imagePullSecrets:
21-
- name: '{{repl ImagePullSecretName }}'
21+
- name: "{{repl ImagePullSecretName }}"
2222
env:
2323
- name: PRIVATE_CA_CONFIGMAP
24-
value: 'repl{{ PrivateCACert }}'
24+
value: "repl{{ PrivateCACert }}"
2525
- name: SSL_CERT_DIR
2626
value: "/etc/ssl/certs"
2727
client:
@@ -31,14 +31,14 @@ spec:
3131
replicaCount: 1
3232
intervalSeconds: 60
3333
imagePullSecrets:
34-
- name: '{{repl ImagePullSecretName }}'
34+
- name: "{{repl ImagePullSecretName }}"
3535
replicated:
3636
enabled: true
3737
image:
3838
registry: repl{{ HasLocalRegistry | ternary LocalRegistryHost "ec-e2e-proxy.testcluster.net" }}
3939
repository: repl{{ HasLocalRegistry | ternary LocalRegistryNamespace "anonymous/registry.replicated.com/library" }}/replicated-sdk-image
4040
imagePullSecrets:
41-
- name: '{{repl ImagePullSecretName }}'
41+
- name: "{{repl ImagePullSecretName }}"
4242
configItemsConfigMapData:
4343
text_required: repl{{ ConfigOption "text_required" }}
4444

@@ -54,8 +54,25 @@ spec:
5454
volumes:
5555
- name: ca-certs
5656
configMap:
57-
name: 'repl{{ PrivateCACert }}'
57+
name: "repl{{ PrivateCACert }}"
5858

5959
builder:
6060
replicated:
6161
enabled: true
62+
# Do not remove the HelmChart document below. This file is intentionally a multi-document YAML file
63+
# for regression testing of SC-131165 bug fix.
64+
---
65+
apiVersion: kots.io/v1beta2
66+
kind: HelmChart
67+
metadata:
68+
name: redis-app
69+
spec:
70+
chart:
71+
name: redis-app
72+
chartVersion: 0.1.0
73+
namespace: redis-app
74+
values:
75+
preflight:
76+
enabled: true
77+
server:
78+
replicaCount: 1

tests/dryrun/assets/kotskinds-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Do not remove the leading "---" separator below. It is intentional and required for
2+
# regression testing of SC-131165 bug fix.
3+
---
14
apiVersion: kots.io/v1beta1
25
kind: Config
36
spec:
File renamed without changes.
2.9 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: redis-app-preflight
6+
labels:
7+
helm.sh/chart: redis-app-0.1.0
8+
app.kubernetes.io/name: redis-app
9+
app.kubernetes.io/instance: redis-app
10+
app.kubernetes.io/version: "1.0.0"
11+
app.kubernetes.io/managed-by: Helm
12+
data:
13+
preflight.yaml: |
14+
apiVersion: troubleshoot.sh/v1beta2
15+
kind: Preflight
16+
metadata:
17+
name: redis-app-preflight
18+
spec:
19+
collectors:
20+
- nodeResources: {}
21+
analyzers:
22+
- nodeResources:
23+
checkName: Node status check
24+
outcomes:
25+
- fail:
26+
when: "nodeCondition(Ready) == False"
27+
message: "Not all nodes are online."
28+
- fail:
29+
when: "nodeCondition(Ready) == Unknown"
30+
message: "Not all nodes are online."
31+
- pass:
32+
message: "All nodes are online."

tests/dryrun/util.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ var (
6363
//go:embed assets/kotskinds-chart.yaml
6464
helmChartData string
6565

66-
//go:embed assets/chart.tgz
67-
helmChartArchiveData string
66+
//go:embed assets/nginx-app-0.1.0.tgz
67+
nginxChartArchiveData string
68+
69+
//go:embed assets/redis-app-0.1.0.tgz
70+
redisChartArchiveData string
6871

6972
//go:embed assets/install-license.yaml
7073
licenseData string
@@ -156,7 +159,8 @@ func embedReleaseData(clusterConfig string) error {
156159
"application.yaml": []byte(applicationData),
157160
"config.yaml": []byte(configData),
158161
"chart.yaml": []byte(helmChartData),
159-
"nginx-app-0.1.0.tgz": []byte(helmChartArchiveData),
162+
"nginx-app-0.1.0.tgz": []byte(nginxChartArchiveData),
163+
"redis-app-0.1.0.tgz": []byte(redisChartArchiveData),
160164
}); err != nil {
161165
return fmt.Errorf("set release data: %v", err)
162166
}

tests/dryrun/v3_install_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,8 +1810,11 @@ func validateVeleroPlugin(t *testing.T, hcli *helm.MockClient) {
18101810
}
18111811

18121812
var (
1813-
//go:embed assets/rendered-chart-preflight.yaml
1814-
renderedChartPreflightData string
1813+
//go:embed assets/rendered-nginx-chart-preflight.yaml
1814+
renderedNginxChartPreflightData string
1815+
1816+
//go:embed assets/rendered-redis-chart-preflight.yaml
1817+
renderedRedisChartPreflightData string
18151818

18161819
//go:embed assets/kotskinds-config-values.yaml
18171820
configValuesData string
@@ -1847,7 +1850,8 @@ func setupV3Test(t *testing.T, opts setupV3TestOpts) (string, string) {
18471850
"application.yaml": []byte(applicationData),
18481851
"config.yaml": []byte(configData),
18491852
"chart.yaml": []byte(helmChartData),
1850-
"nginx-app-0.1.0.tgz": []byte(helmChartArchiveData),
1853+
"nginx-app-0.1.0.tgz": []byte(nginxChartArchiveData),
1854+
"redis-app-0.1.0.tgz": []byte(redisChartArchiveData),
18511855
}); err != nil {
18521856
t.Fatalf("fail to set release data: %v", err)
18531857
}
@@ -1893,7 +1897,13 @@ func setupV3TestHelmClient() *helm.MockClient {
18931897
On("Render", mock.Anything, mock.MatchedBy(func(opts helm.InstallOptions) bool {
18941898
return opts.ReleaseName == "nginx-app"
18951899
})).
1896-
Return([][]byte{[]byte(renderedChartPreflightData)}, nil).
1900+
Return([][]byte{[]byte(renderedNginxChartPreflightData)}, nil).
1901+
Maybe()
1902+
hcli.
1903+
On("Render", mock.Anything, mock.MatchedBy(func(opts helm.InstallOptions) bool {
1904+
return opts.ReleaseName == "redis-app"
1905+
})).
1906+
Return([][]byte{[]byte(renderedRedisChartPreflightData)}, nil).
18971907
Maybe()
18981908
hcli.On("Close").Return(nil).Maybe()
18991909

0 commit comments

Comments
 (0)