Skip to content

Commit

Permalink
Use testPods values for test images and container resources (#761)
Browse files Browse the repository at this point in the history
* Use testPods values for test images

* Fix unit tests

* Fix unit tests

* Add unit test

* Add helm docs

* Fix unit tests

* Disable analytics in helm output

* Disable analytics in helm output

* Fix unit tests

---------

Co-authored-by: Yevhen Ivantsov <yivantsov@atlassian.com>
  • Loading branch information
bianchi2 and Yevhen Ivantsov authored Feb 12, 2024
1 parent 1c0bd21 commit f92eea6
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: alpine
image: {{ .Values.testPods.image.statusTestContainer }}
imagePullPolicy: IfNotPresent
env:
- name: STATUS_URL
Expand All @@ -48,6 +48,10 @@ spec:
sleep 10
count=$(( $count + 1 ))
done
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ spec:
EOF
cat output.txt
grep -q "Connection established OK" output.txt
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: debian:stable-slim
image: {{ .Values.testPods.image.permissionsTestContainer }}
imagePullPolicy: IfNotPresent
securityContext:
# We assume that the UID and GID used by the product images are the same, which in practice they are
Expand Down Expand Up @@ -51,6 +51,10 @@ spec:
touch /shared-home/permissions-test
ls -l /shared-home/permissions-test
rm /shared-home/permissions-test
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{ include "bamboo.volumes.sharedHome" . | nindent 4 }}
restartPolicy: Never
Expand Down
1 change: 1 addition & 0 deletions src/main/charts/bamboo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ atlassianAnalyticsAndSupport:
# -- Metadata and pod spec for pods started in Helm tests
#
testPods:
resources: {}
labels: {}
annotations: {}
nodeSelector: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: alpine
image: {{ .Values.testPods.image.statusTestContainer }}
imagePullPolicy: IfNotPresent
env:
- name: STATUS_URL
Expand All @@ -36,6 +36,10 @@ spec:
STATUS=$(curl -s "$STATUS_URL")
echo "Verifying application state is RUNNING or FIRST_RUN: $STATUS"
echo $STATUS | jq -e '.state|test("RUNNING|FIRST_RUN")'
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
EOF
cat output.txt
grep -q "Connection established OK" output.txt
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: debian:stable-slim
image: {{ .Values.testPods.image.permissionsTestContainer }}
imagePullPolicy: IfNotPresent
securityContext:
# We assume that the UID and GID used by the product images are the same, which in practice they are
Expand Down Expand Up @@ -60,6 +60,10 @@ spec:
touch /shared-home/permissions-test
ls -l /shared-home/permissions-test
rm /shared-home/permissions-test
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- if or .Values.volumes.sharedHome.persistentVolumeClaim.create .Values.volumes.sharedHome.customVolume }}
{{ include "bitbucket.volumes.sharedHome" . | nindent 4 }}
Expand Down
1 change: 1 addition & 0 deletions src/main/charts/bitbucket/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ atlassianAnalyticsAndSupport:
# -- Metadata and pod spec for pods started in Helm tests
#
testPods:
resources: {}
labels: {}
annotations: {}
nodeSelector: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: alpine
image: {{ .Values.testPods.image.statusTestContainer }}
env:
- name: STATUS_URL
value: "http://{{ include "common.names.fullname" . }}:{{ .Values.confluence.service.port }}/status"
Expand All @@ -35,6 +35,10 @@ spec:
STATUS=$(curl -s "$STATUS_URL")
echo "Verifying application state is RUNNING or FIRST_RUN: $STATUS"
echo $STATUS | jq -e '.state|test("RUNNING|FIRST_RUN")'
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
EOF
cat output.txt
grep -q "Connection established OK" output.txt
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: debian:stable-slim
image: {{ .Values.testPods.image.permissionsTestContainer }}
imagePullPolicy: IfNotPresent
securityContext:
# We assume that the UID and GID used by the product images are the same, which in practice they are
Expand Down Expand Up @@ -54,6 +54,10 @@ spec:
touch /shared-home/permissions-test
ls -l /shared-home/permissions-test
rm /shared-home/permissions-test
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{ include "confluence.volumes.sharedHome" . | nindent 4 }}
restartPolicy: Never
Expand Down
1 change: 1 addition & 0 deletions src/main/charts/confluence/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ atlassianAnalyticsAndSupport:
# -- Metadata and pod spec for pods started in Helm tests
#
testPods:
resources: {}
labels: {}
annotations: {}
nodeSelector: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: alpine
image: {{ .Values.testPods.image.statusTestContainer }}
env:
- name: STATUS_URL
value: "http://{{ include "common.names.fullname" . }}:{{ .Values.crowd.service.port }}/crowd/status"
Expand All @@ -35,6 +35,10 @@ spec:
STATUS=$(curl -s "$STATUS_URL")
echo "Verifying application state is RUNNING or FIRST_RUN: $STATUS"
echo $STATUS | jq -e '.state|test("RUNNING|FIRST_RUN")'
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: debian:stable-slim
image: {{ .Values.testPods.image.permissionsTestContainer }}
imagePullPolicy: IfNotPresent
securityContext:
# We assume that the UID and GID used by the product images are the same, which in practice they are
Expand Down Expand Up @@ -54,6 +54,10 @@ spec:
touch /shared-home/permissions-test
ls -l /shared-home/permissions-test
rm /shared-home/permissions-test
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{ include "crowd.volumes.sharedHome" . | nindent 4 }}
restartPolicy: Never
Expand Down
1 change: 1 addition & 0 deletions src/main/charts/crowd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ atlassianAnalyticsAndSupport:
# -- Metadata and pod spec for pods started in Helm tests
#
testPods:
resources: {}
labels: {}
annotations: {}
nodeSelector: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
STATUS=$(curl -s "$STATUS_URL")
echo "Verifying application state is RUNNING or FIRST_RUN: $STATUS"
echo $STATUS | jq -e '.state|test("RUNNING|FIRST_RUN")'
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
EOF
cat output.txt
grep -q "Connection established OK" output.txt
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
{{- with .Values.testPods.nodeSelector }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test
image: debian:stable-slim
image: {{ .Values.testPods.image.permissionsTestContainer }}
imagePullPolicy: IfNotPresent
securityContext:
# We assume that the UID and GID used by the product images are the same, which in practice they are
Expand Down Expand Up @@ -54,6 +54,10 @@ spec:
touch /shared-home/permissions-test
ls -l /shared-home/permissions-test
rm /shared-home/permissions-test
{{- with .Values.testPods.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{ include "jira.volumes.sharedHome" . | nindent 4 }}
restartPolicy: Never
Expand Down
1 change: 1 addition & 0 deletions src/main/charts/jira/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ atlassianAnalyticsAndSupport:
# -- Metadata and pod spec for pods started in Helm tests
#
testPods:
resources: {}
labels: {}
annotations: {}
nodeSelector: {}
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/test/TestPodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,42 @@ void test_pods_custom_scheduler_name(Product product) throws Exception {
for (String testPod : testPods) {
final var pod = resources.get(Kind.Pod, Pod.class, product.getHelmReleaseName() + "-" + testPod);
assertEquals("my-scheduler", pod.getSpec().path("schedulerName").asText());
}
}

@ParameterizedTest
@EnumSource(value = Product.class, names = {"bamboo_agent"}, mode = EnumSource.Mode.EXCLUDE)
void test_pods_custom_resources(Product product) throws Exception {
final var resources = helm.captureKubeResourcesFromHelmChart(product, Map.of(
"database.credentials.secretName", "db-secret",
"testPods.resources.requests.cpu", "1",
"testPods.resources.limits.cpu", "2",
"testPods.resources.requests.memory", "2Mi",
"testPods.resources.limits.memory", "3Mi"));
List<String> testPods = List.of("application-status-test", "shared-home-permissions-test", "db-connectivity-test");
if (product.name().equals("crowd")) {
testPods = List.of("application-status-test", "shared-home-permissions-test");
}
for (String testPod : testPods) {
final var pod = resources.get(Kind.Pod, Pod.class, product.getHelmReleaseName() + "-" + testPod);
assertEquals("1", pod.getSpec().path("containers").path(0).path("resources").path("requests").path("cpu").asText());
assertEquals("2", pod.getSpec().path("containers").path(0).path("resources").path("limits").path("cpu").asText());
assertEquals("2Mi", pod.getSpec().path("containers").path(0).path("resources").path("requests").path("memory").asText());
assertEquals("3Mi", pod.getSpec().path("containers").path(0).path("resources").path("limits").path("memory").asText());
}
}

@ParameterizedTest
@EnumSource(value = Product.class, names = {"bamboo_agent"}, mode = EnumSource.Mode.EXCLUDE)
void test_pods_custom_images(Product product) throws Exception {
final var resources = helm.captureKubeResourcesFromHelmChart(product, Map.of(
"testPods.image.statusTestContainer", "centos",
"testPods.image.permissionsTestContainer", "centos"));
List<String> testPods = List.of("application-status-test", "shared-home-permissions-test");
for (String testPod : testPods) {
final var pod = resources.get(Kind.Pod, Pod.class, product.getHelmReleaseName() + "-" + testPod);
assertEquals("centos", pod.getSpec().path("containers").path(0).path("image").asText());
}
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ spec:
template:
metadata:
annotations:
checksum/config-jvm: 42513a28cc58777860ccf2d5c400fbd10c83d85a39e7bc4535e18bb0b6bd39ad
labels:
app.kubernetes.io/name: bamboo-agent
app.kubernetes.io/instance: unittest-bamboo-agent
Expand Down
19 changes: 4 additions & 15 deletions src/test/resources/expected_helm_output/bamboo/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ data:
affinity: {}
atlassianAnalyticsAndSupport:
analytics:
enabled: true
enabled: false
helmValues:
enabled: true
bamboo:
Expand Down Expand Up @@ -267,6 +267,7 @@ data:
statusTestContainer: alpine:latest
labels: {}
nodeSelector: {}
resources: {}
schedulerName: null
tolerations: []
tolerations: []
Expand Down Expand Up @@ -301,19 +302,6 @@ data:
storage: 1Gi
storageClassName: null
subPath: null
analytics.json: |
{
"imageTag": "9.5.1",
"replicas": 1,
"isJmxEnabled": true,
"ingressType": "NONE",
"k8sVersion": "1.28",
"serviceType": "CLUSTER_IP",
"dbType": "UNKNOWN",
"isSharedHomePVCCreated": false,
"isServiceMonitorCreated": false,
"isGrafanaDashboardsCreated": false
}
---
# Source: bamboo/templates/service-jms.yaml
apiVersion: v1
Expand Down Expand Up @@ -405,6 +393,7 @@ spec:
template:
metadata:
annotations:
checksum/config-jvm: d0d822938d8d28725b077e578cd2dda282aee43dab7100c16aed24e2e8b620a6
labels:
app.kubernetes.io/name: bamboo
app.kubernetes.io/instance: unittest-bamboo
Expand Down Expand Up @@ -575,7 +564,7 @@ metadata:
spec:
containers:
- name: test
image: alpine
image: alpine:latest
imagePullPolicy: IfNotPresent
env:
- name: STATUS_URL
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/expected_helm_output/bamboo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ additionalHosts:

monitoring:
exposeJmxMetrics: true

atlassianAnalyticsAndSupport:
analytics:
enabled: false
Loading

0 comments on commit f92eea6

Please sign in to comment.