From 0058aedcccb64c45cfac1964588c8e58001a24d7 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 16:06:46 -0700 Subject: [PATCH 1/7] chore(notes): simplify post-install steps for ClusterIP service case When installing the chart without further customizations, the user just needs to port-forward the local port to the application pod. Signed-off-by: Thuan Vo --- charts/cryostat/templates/NOTES.txt | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/charts/cryostat/templates/NOTES.txt b/charts/cryostat/templates/NOTES.txt index 3f1eeb77..facd24f2 100644 --- a/charts/cryostat/templates/NOTES.txt +++ b/charts/cryostat/templates/NOTES.txt @@ -1,8 +1,8 @@ {{- $envVars := list }} -{{- $portForwards := list }} +{{- $portForwards := false }} {{- $listNum := 1 }} {{- if not .Values.core.ingress.enabled }} -{{ $listNum }}. Tell Cryostat how to serve external traffic: +{{ $listNum }}. Configure the application to serve external traffic: {{- $listNum = add1 $listNum }} ``` {{- if .Values.core.route.enabled }} @@ -11,6 +11,10 @@ {{- else if .Values.core.ingress.enabled }} {{- /* Do nothing */}} No actions required with this configuration. +{{- else if contains "ClusterIP" .Values.core.service.type }} + {{- /* Do nothing */}} + No actions required with this configuration. +{{- $portForwards = true }} {{- else if contains "NodePort" .Values.core.service.type }} export NODE_IP=$(kubectl get nodes -n {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_PORT=$(kubectl get -n {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "cryostat.fullname" . }}) @@ -20,10 +24,6 @@ You can watch the status by running 'kubectl get -n {{ .Release.Namespace }} -w svc/{{ include "cryostat.fullname" . }}' export SERVICE_IP=$(kubectl get svc -n {{ .Release.Namespace }} {{ include "cryostat.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") {{- $envVars = list "QUARKUS_HTTP_HOST=$SERVICE_IP" }} -{{- else if contains "ClusterIP" .Values.core.service.type }} - 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 CONTAINER_PORT=$(kubectl get pod -n {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") -{{- $portForwards = prepend $portForwards "8080:$CONTAINER_PORT" }} {{- end }} {{- if not (empty $envVars) }} @@ -32,18 +32,19 @@ ``` {{- end }} -{{- if not (empty $portForwards) }} - -{{ $listNum }}. Forward local ports to the application's pod: +{{- if $portForwards }} +{{ $listNum }}. Forward local port to the application's pod: ``` - 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}") kubectl -n {{ .Release.Namespace }} wait --for=condition=available --timeout=60s deploy/{{ include "cryostat.fullname" . }} - kubectl -n {{ .Release.Namespace }} port-forward $POD_NAME {{ join " " $portForwards }} + + 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 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" ``` {{- $listNum = add1 $listNum }} {{- end }} -{{ $listNum }}. {{ "Visit the " }}{{ .Chart.Name | camelcase }}{{ " application at: " }} +{{ $listNum }}. Visit the application at: ``` {{- if .Values.core.route.enabled }} echo {{ ternary "https" "http" .Values.core.route.tls.enabled }}://$(oc get route -n {{ .Release.Namespace }} {{ include "cryostat.fullname" . }} -o jsonpath="{.status.ingress[0].host}") From 738d4d20c0100cab353feafb1666aca7782392c6 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 16:19:57 -0700 Subject: [PATCH 2/7] test: update unittest --- charts/cryostat/tests/notes_test.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index 533a37bf..42c83a33 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -23,7 +23,7 @@ tests: value: | - 1. Visit the Cryostat application at: + 1. Visit the application at: ``` https://example.com/ ``` @@ -36,12 +36,12 @@ tests: - equalRaw: value: | - 1. Tell Cryostat how to serve external traffic: + 1. Configure the application to serve external traffic: ``` No actions required with this configuration. ``` - 2. Visit the Cryostat application at: + 2. Visit the application at: ``` echo http://$(oc get route -n NAMESPACE RELEASE-NAME-cryostat -o jsonpath="{.status.ingress[0].host}") ``` @@ -54,12 +54,12 @@ tests: - equalRaw: value: | - 1. Tell Cryostat how to serve external traffic: + 1. Configure the application to serve external traffic: ``` No actions required with this configuration. ``` - 2. Visit the Cryostat application at: + 2. Visit the application at: ``` echo https://$(oc get route -n NAMESPACE RELEASE-NAME-cryostat -o jsonpath="{.status.ingress[0].host}") ``` @@ -73,14 +73,14 @@ tests: - equalRaw: value: | - 1. Tell Cryostat how to serve external traffic: + 1. Configure the application to serve external traffic: ``` export NODE_IP=$(kubectl get nodes -n NAMESPACE -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_PORT=$(kubectl get -n NAMESPACE -o jsonpath="{.spec.ports[0].nodePort}" services RELEASE-NAME-cryostat) kubectl -n NAMESPACE set env deploy --containers=cryostat RELEASE-NAME-cryostat QUARKUS_HTTP_HOST=$NODE_IP ``` - 2. Visit the Cryostat application at: + 2. Visit the application at: ``` echo http://$NODE_IP:$NODE_PORT ``` @@ -94,7 +94,7 @@ tests: - equalRaw: value: | - 1. Tell Cryostat how to serve external traffic: + 1. Configure the application to serve external traffic: ``` NOTE: It may take a few minutes for the LoadBalancer IP to be available. You can watch the status by running 'kubectl get -n NAMESPACE -w svc/RELEASE-NAME-cryostat' @@ -102,7 +102,7 @@ tests: kubectl -n NAMESPACE set env deploy --containers=cryostat RELEASE-NAME-cryostat QUARKUS_HTTP_HOST=$SERVICE_IP ``` - 2. Visit the Cryostat application at: + 2. Visit the application at: ``` echo http://$SERVICE_IP:8181 ``` From ec4e80fcc7ab3bffdc13b1fc90daa0ed1a9c1b35 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 16:24:33 -0700 Subject: [PATCH 3/7] test: add test for quick installation scenarios --- charts/cryostat/templates/NOTES.txt | 1 + charts/cryostat/tests/notes_test.yaml | 32 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/charts/cryostat/templates/NOTES.txt b/charts/cryostat/templates/NOTES.txt index facd24f2..ac845880 100644 --- a/charts/cryostat/templates/NOTES.txt +++ b/charts/cryostat/templates/NOTES.txt @@ -33,6 +33,7 @@ {{- end }} {{- if $portForwards }} + {{ $listNum }}. Forward local port to the application's pod: ``` kubectl -n {{ .Release.Namespace }} wait --for=condition=available --timeout=60s deploy/{{ include "cryostat.fullname" . }} diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index 42c83a33..24e99cb9 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -28,7 +28,7 @@ tests: https://example.com/ ``` - - it: should render notes for enabled route without TLS + - it: should render correct notes for enabled route without TLS set: core.route.enabled: true core.route.tls.enabled: false @@ -46,7 +46,7 @@ tests: echo http://$(oc get route -n NAMESPACE RELEASE-NAME-cryostat -o jsonpath="{.status.ingress[0].host}") ``` - - it: should render notes for enabled route with TLS + - it: should render correct notes for enabled route with TLS set: core.route.enabled: true core.route.tls.enabled: true @@ -64,7 +64,7 @@ tests: echo https://$(oc get route -n NAMESPACE RELEASE-NAME-cryostat -o jsonpath="{.status.ingress[0].host}") ``` - - it: should render notes for NodePort service without ingress or route + - it: should render correct notes for NodePort service without ingress or route set: core.service.type: "NodePort" core.ingress.enabled: false @@ -85,7 +85,7 @@ tests: echo http://$NODE_IP:$NODE_PORT ``` - - it: should render notes for LoadBalancer service without ingress or route + - it: should render correct notes for LoadBalancer service without ingress or route set: core.service.type: "LoadBalancer" core.ingress.enabled: false @@ -106,3 +106,27 @@ tests: ``` echo http://$SERVICE_IP:8181 ``` + + - it: should render correct notes for ClusterIP service without ingress or route + asserts: + - equalRaw: + value: | + + 1. Configure the application to serve external traffic: + ``` + No actions required with this configuration. + ``` + + 2. Forward local port to the application's pod: + ``` + 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 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" + ``` + + 3. Visit the application at: + ``` + http://localhost:8080 + ``` From 868e2005b972fc541bcc8f73e2d22c1d3f98a22d Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 17:45:02 -0700 Subject: [PATCH 4/7] chore: consistent command with other modes --- charts/cryostat/templates/NOTES.txt | 2 +- charts/cryostat/tests/notes_test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/cryostat/templates/NOTES.txt b/charts/cryostat/templates/NOTES.txt index ac845880..c5a9298a 100644 --- a/charts/cryostat/templates/NOTES.txt +++ b/charts/cryostat/templates/NOTES.txt @@ -60,6 +60,6 @@ {{- else if contains "LoadBalancer" .Values.core.service.type }} echo http://$SERVICE_IP:{{ .Values.core.service.httpPort }} {{- else if contains "ClusterIP" .Values.core.service.type }} - http://localhost:8080 + echo http://localhost:8080 {{- end }} ``` diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index 24e99cb9..4f5389ef 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -128,5 +128,5 @@ tests: 3. Visit the application at: ``` - http://localhost:8080 + echo http://localhost:8080 ``` From 62f85be248013f45fe28fd5212b7221a7a784999 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 17:48:39 -0700 Subject: [PATCH 5/7] fixup: consistent url output as other modes --- charts/cryostat/templates/NOTES.txt | 2 +- charts/cryostat/tests/notes_test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/cryostat/templates/NOTES.txt b/charts/cryostat/templates/NOTES.txt index c5a9298a..7fec00d4 100644 --- a/charts/cryostat/templates/NOTES.txt +++ b/charts/cryostat/templates/NOTES.txt @@ -52,7 +52,7 @@ {{- else if .Values.core.ingress.enabled }} {{- range $host := .Values.core.ingress.hosts -}} {{- range .paths }} - {{ ternary "http" "https" (empty $.Values.core.ingress.tls) }}://{{ $host.host }}{{ .path }} + echo {{ ternary "http" "https" (empty $.Values.core.ingress.tls) }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} {{- else if contains "NodePort" .Values.core.service.type }} diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index 4f5389ef..a05dc48c 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -25,7 +25,7 @@ tests: 1. Visit the application at: ``` - https://example.com/ + echo https://example.com/ ``` - it: should render correct notes for enabled route without TLS From 833dd5d56fa98f814c32796b189d6e4f183536b5 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Wed, 17 Jul 2024 18:14:55 -0700 Subject: [PATCH 6/7] chore: remove empty space --- charts/cryostat/tests/notes_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index a05dc48c..b80ed2a7 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -120,12 +120,12 @@ tests: 2. Forward local port to the application's pod: ``` 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 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" ``` - + 3. Visit the application at: ``` echo http://localhost:8080 From 45fb9cf2669f3c9b1918dcdb19bf904b057c8e71 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Thu, 18 Jul 2024 11:07:50 -0700 Subject: [PATCH 7/7] revert: echo should only used when necessary --- charts/cryostat/templates/NOTES.txt | 4 ++-- charts/cryostat/tests/notes_test.yaml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/cryostat/templates/NOTES.txt b/charts/cryostat/templates/NOTES.txt index 7fec00d4..ac845880 100644 --- a/charts/cryostat/templates/NOTES.txt +++ b/charts/cryostat/templates/NOTES.txt @@ -52,7 +52,7 @@ {{- else if .Values.core.ingress.enabled }} {{- range $host := .Values.core.ingress.hosts -}} {{- range .paths }} - echo {{ ternary "http" "https" (empty $.Values.core.ingress.tls) }}://{{ $host.host }}{{ .path }} + {{ ternary "http" "https" (empty $.Values.core.ingress.tls) }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} {{- else if contains "NodePort" .Values.core.service.type }} @@ -60,6 +60,6 @@ {{- else if contains "LoadBalancer" .Values.core.service.type }} echo http://$SERVICE_IP:{{ .Values.core.service.httpPort }} {{- else if contains "ClusterIP" .Values.core.service.type }} - echo http://localhost:8080 + http://localhost:8080 {{- end }} ``` diff --git a/charts/cryostat/tests/notes_test.yaml b/charts/cryostat/tests/notes_test.yaml index b80ed2a7..f60265dd 100644 --- a/charts/cryostat/tests/notes_test.yaml +++ b/charts/cryostat/tests/notes_test.yaml @@ -25,7 +25,7 @@ tests: 1. Visit the application at: ``` - echo https://example.com/ + https://example.com/ ``` - it: should render correct notes for enabled route without TLS @@ -63,7 +63,7 @@ tests: ``` echo https://$(oc get route -n NAMESPACE RELEASE-NAME-cryostat -o jsonpath="{.status.ingress[0].host}") ``` - + - it: should render correct notes for NodePort service without ingress or route set: core.service.type: "NodePort" @@ -128,5 +128,5 @@ tests: 3. Visit the application at: ``` - echo http://localhost:8080 + http://localhost:8080 ```