Skip to content

Commit

Permalink
chore(notes): simplify post-install steps for ClusterIP service case (#…
Browse files Browse the repository at this point in the history
…178)

Signed-off-by: Thuan Vo <thuan.votann@gmail.com>
  • Loading branch information
tthvo authored Jul 18, 2024
1 parent 3e27723 commit 07ebd17
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
24 changes: 13 additions & 11 deletions charts/cryostat/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -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" . }})
Expand All @@ -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) }}
Expand All @@ -32,18 +32,20 @@
```
{{- end }}

{{- if not (empty $portForwards) }}
{{- if $portForwards }}

{{ $listNum }}. Forward local ports to the application's pod:
{{ $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}")
Expand Down
52 changes: 38 additions & 14 deletions charts/cryostat/tests/notes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,48 @@ tests:
value: |
1. Visit the Cryostat application at:
1. Visit the application at:
```
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
asserts:
- 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}")
```
- 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
asserts:
- 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}")
```
- 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
Expand All @@ -73,19 +73,19 @@ 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
```
- 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
Expand All @@ -94,15 +94,39 @@ 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'
export SERVICE_IP=$(kubectl get svc -n NAMESPACE RELEASE-NAME-cryostat --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
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
```
- 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
```

0 comments on commit 07ebd17

Please sign in to comment.