Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(notes): simplify post-install steps for ClusterIP service case #178

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 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,32 +32,34 @@
```
{{- 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}")
{{- 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 }}
tthvo marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.core.service.type }}
echo http://$NODE_IP:$NODE_PORT
{{- 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 }}
```
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/
echo 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:
```
echo http://localhost:8080
```