Skip to content

Commit

Permalink
fix(selector): apply component labels/selectors (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Sep 23, 2024
1 parent aab2ade commit 27de094
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/cryostat/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
```
kubectl -n {{ .Release.Namespace }} wait --for=condition=available --timeout=60s deploy/{{ include "cryostat.fullname" . }}

export POD_NAME=$(kubectl get pods -n {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "cryostat.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
export POD_NAME=$(kubectl get pods -n {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "cryostat.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=cryostat" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod -n {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
kubectl -n {{ .Release.Namespace }} port-forward $POD_NAME "8080:$CONTAINER_PORT"
```
Expand Down
3 changes: 3 additions & 0 deletions charts/cryostat/templates/cryostat_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ metadata:
name: {{ include "cryostat.fullname" . }}
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: cryostat
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
{{- include "cryostat.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: cryostat
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -21,6 +23,7 @@ spec:
{{- end }}
labels:
{{- include "cryostat.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: cryostat
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/templates/cryostat_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ $fullName }}
labels:
{{- include "cryostat.labels" $ | nindent 4 }}
app.kubernetes.io/component: cryostat
{{- if (.Values.authentication.openshift).enabled }}
annotations:
service.alpha.openshift.io/serving-cert-secret-name: {{ .Release.Name }}-proxy-tls
Expand All @@ -25,3 +26,4 @@ spec:
{{- end }}
selector:
{{- include "cryostat.selectorLabels" $ | nindent 4 }}
app.kubernetes.io/component: cryostat
3 changes: 3 additions & 0 deletions charts/cryostat/templates/db_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ metadata:
name: {{ include "cryostat.fullname" . }}-db
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: db
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
{{- include "cryostat.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: db
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -21,6 +23,7 @@ spec:
{{- end }}
labels:
{{- include "cryostat.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: db
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/templates/db_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ metadata:
name: {{ $fullName }}-db
labels:
{{- include "cryostat.labels" $ | nindent 4 }}
app.kubernetes.io/component: db
spec:
type: {{ .Values.db.service.type }}
ports:
- port: {{ .Values.db.service.port }}
selector:
{{- include "cryostat.selectorLabels" $ | nindent 4 }}
app.kubernetes.io/component: db
3 changes: 3 additions & 0 deletions charts/cryostat/templates/reports_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ metadata:
name: {{ include "cryostat.fullname" . }}-reports
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: reports
spec:
replicas: {{ (.Values.reports).replicas }}
strategy:
type: RollingUpdate
selector:
matchLabels:
{{- include "cryostat.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: reports
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -22,6 +24,7 @@ spec:
{{- end }}
labels:
{{- include "cryostat.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: reports
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/templates/reports_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ metadata:
name: {{ $fullName }}-reports
labels:
{{- include "cryostat.labels" $ | nindent 4 }}
app.kubernetes.io/component: reports
spec:
type: {{ .Values.reports.service.type }}
ports:
- port: {{ .Values.reports.service.httpPort }}
selector:
{{- include "cryostat.selectorLabels" $ | nindent 4 }}
app.kubernetes.io/component: reports
{{- end -}}
3 changes: 3 additions & 0 deletions charts/cryostat/templates/storage_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ metadata:
name: {{ include "cryostat.fullname" . }}-storage
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: storage
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
{{- include "cryostat.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: storage
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -21,6 +23,7 @@ spec:
{{- end }}
labels:
{{- include "cryostat.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: storage
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/templates/storage_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ metadata:
name: {{ $fullName }}-storage
labels:
{{- include "cryostat.labels" $ | nindent 4 }}
app.kubernetes.io/component: storage
spec:
type: {{ .Values.storage.service.type }}
ports:
- port: {{ .Values.storage.service.port }}
selector:
{{- include "cryostat.selectorLabels" $ | nindent 4 }}
app.kubernetes.io/component: storage
3 changes: 2 additions & 1 deletion charts/cryostat/templates/tests/test-core-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: "{{ include "cryostat.fullname" . }}-test-core-connection"
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: test-core-connection
annotations:
"helm.sh/hook": test
spec:
Expand All @@ -15,7 +16,7 @@ spec:
- '-exc'
- >
dnf install --disableplugin=subscription-manager -yq jq;
curl -sSf --retry 10 --retry-connrefused -o /tmp/out.json http://{{ include "cryostat.fullname" . }}:{{ .Values.core.service.httpPort }}/health;
curl -sSf --retry 10 --retry-connrefused http://{{ include "cryostat.fullname" . }}:{{ .Values.core.service.httpPort }}/health | tee /tmp/out.json;
cat /tmp/out.json;
{{- if hasSuffix "-dev" .Chart.AppVersion }}
jq -e '{{ printf "(.cryostatVersion | test(\"^v%s-snapshot$\"))" (.Chart.AppVersion | trimSuffix "-dev" | squote) }}' /tmp/out.json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: "{{ include "cryostat.fullname" . }}-test-grafana-connection"
labels:
{{- include "cryostat.labels" . | nindent 4 }}
app.kubernetes.io/component: test-grafana-connection
annotations:
"helm.sh/hook": test
spec:
Expand Down
3 changes: 3 additions & 0 deletions charts/cryostat/tests/cryostat_deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ tests:
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: cryostat
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: cryostat
- equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME-cryostat
Expand All @@ -44,6 +46,7 @@ tests:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "4.0.0-dev"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: cryostat

- it: should validate all container settings including environment variables and security contexts
asserts:
Expand Down
3 changes: 3 additions & 0 deletions charts/cryostat/tests/cryostat_service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: cryostat

- it: should create a Service with the correct settings when OpenShift authentication is enabled
set:
Expand Down Expand Up @@ -85,6 +86,7 @@ tests:
value:
app.kubernetes.io/name: cryostat
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/component: cryostat
- equal:
path: metadata.labels
value:
Expand All @@ -93,6 +95,7 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: cryostat
- equal:
path: metadata.annotations
value:
Expand Down
3 changes: 3 additions & 0 deletions charts/cryostat/tests/db_deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ tests:
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: db
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: db
- equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME-cryostat
Expand All @@ -44,6 +46,7 @@ tests:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "4.0.0-dev"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: db

- it: should validate cryostat-db settings
asserts:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/tests/db_service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: db

- it: should create a Service with the correct settings overrides
set:
Expand Down Expand Up @@ -55,3 +56,4 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: db
2 changes: 1 addition & 1 deletion charts/cryostat/tests/notes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ tests:
```
kubectl -n NAMESPACE wait --for=condition=available --timeout=60s deploy/RELEASE-NAME-cryostat
export POD_NAME=$(kubectl get pods -n NAMESPACE -l "app.kubernetes.io/name=cryostat,app.kubernetes.io/instance=RELEASE-NAME" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
export POD_NAME=$(kubectl get pods -n NAMESPACE -l "app.kubernetes.io/name=cryostat,app.kubernetes.io/instance=RELEASE-NAME,app.kubernetes.io/component=cryostat" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod -n NAMESPACE $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
kubectl -n NAMESPACE port-forward $POD_NAME "8080:$CONTAINER_PORT"
```
Expand Down
5 changes: 4 additions & 1 deletion charts/cryostat/tests/reports_deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ tests:
value: 2
- equal:
path: spec.strategy.type
value: Recreate
value: RollingUpdate
- equal:
path: spec.selector.matchLabels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: reports
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: reports
- equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME-cryostat
Expand All @@ -52,6 +54,7 @@ tests:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "4.0.0-dev"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: reports

- it: should validate all container settings including environment variables and security contexts
set:
Expand Down
3 changes: 3 additions & 0 deletions charts/cryostat/tests/storage_deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ tests:
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: storage
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: cryostat
app.kubernetes.io/component: storage
- equal:
path: spec.template.spec.serviceAccountName
value: RELEASE-NAME-cryostat
Expand All @@ -44,6 +46,7 @@ tests:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "4.0.0-dev"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: storage

- it: should validate cryostat-storage settings
asserts:
Expand Down
2 changes: 2 additions & 0 deletions charts/cryostat/tests/storage_service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: storage

- it: should create a Service with the correct settings overrides
set:
Expand Down Expand Up @@ -56,3 +57,4 @@ tests:
app.kubernetes.io/name: cryostat
app.kubernetes.io/version: "4.0.0-dev"
helm.sh/chart: cryostat-2.0.0-dev
app.kubernetes.io/component: storage

0 comments on commit 27de094

Please sign in to comment.