Skip to content

Commit b1ec2c0

Browse files
authored
Helm Chart OpenShift Route Handling (#238)
* add route domain setup to values Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * expand template to include route handling Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * update deployment and route for fqdn setting Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * add helper script for openshift install Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * update documentation Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * add functionality for customizable name and path Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> * update readme Signed-off-by: Jordan Dubrick <jdubrick@redhat.com> --------- Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
1 parent 1e05c6f commit b1ec2c0

File tree

7 files changed

+169
-47
lines changed

7 files changed

+169
-47
lines changed

README.md

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,49 +52,7 @@ See the following for more on the component specific build process:
5252
We recommend using the [Devfile Registry Operator](https://github.com/devfile/registry-operator) to install a Devfile Registry on your Kubernetes or OpenShift cluster. Consult [its Readme for more information](https://github.com/devfile/registry-operator#running-the-controller-in-a-cluster).
5353

5454
### Via the Devfile Registry Helm Chart
55-
56-
Alternatively, a Helm chart is also provided if you do not wish to use an operator. To install (with Helm 3) run:
57-
58-
```bash
59-
$ helm install devfile-registry ./deploy/chart/devfile-registry \
60-
--set global.ingress.domain=<ingress-domain> \
61-
--set devfileIndex.image=<index-image> \
62-
--set devfileIndex.tag=<index-image-tag>
63-
```
64-
65-
Where `<ingress-domain>` is the ingress domain for your cluster, `<index-image>` is the devfile index image you want to deploy, and `<index-image-tag>` is the corresponding image tag for the devfile index image.
66-
67-
For example, if you're installing your own custom devfile registry image for dev/test purposes on Minikube, you might run:
68-
69-
```bash
70-
$ helm install devfile-registry ./deploy/chart/devfile-registry \
71-
--set global.ingress.domain="$(minikube ip).nip.io" \
72-
--set devfileIndex.image=quay.io/someuser/devfile-index \
73-
--set devfileIndex.tag=latest
74-
```
75-
76-
You can deploy a devfile registry with a custom registry viewer image (uses `quay.io/devfile/registry-viewer:next` by default) by running the following:
77-
78-
```bash
79-
$ helm install devfile-registry ./deploy/chart/devfile-registry \
80-
--set global.ingress.domain="$(minikube ip).nip.io" \
81-
--set devfileIndex.image=quay.io/someuser/devfile-index \
82-
--set devfileIndex.tag=latest \
83-
--set registryViewer.image=quay.io/someuser/registry-viewer \
84-
--set registryViewer.tag=latest
85-
```
86-
87-
You can deploy a *headless* devfile registry (i.e. without the registry viewer) by specifying `--set global.headless=true` which will look like:
88-
89-
```bash
90-
$ helm install devfile-registry ./deploy/chart/devfile-registry \
91-
--set global.ingress.domain="$(minikube ip).nip.io" \
92-
--set global.headless=true \
93-
--set devfileIndex.image=quay.io/someuser/devfile-index \
94-
--set devfileIndex.tag=latest
95-
```
96-
97-
For more information on the Helm chart, consult [its readme](deploy/chart/devfile-registry/README.md).
55+
Alternatively, a Helm chart is also provided if you do not wish to use an operator. You can find instructions below for installing via Helm to either a Kubernetes or OpenShift environment. You can find detailed instructions [here](deploy/chart/devfile-registry/README.md).
9856

9957
## Contributing
10058

deploy/chart/devfile-registry/README.md

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,95 @@ E.g. if your cluster's ingress domain is 192.168.1.0.nip.io, you would run:
2121
helm install devfile-registry deploy/chart/devfile-registry --set global.ingress.domain=192.168.1.0.nip.io
2222
```
2323

24+
### Kubernetes Installation Examples
25+
```bash
26+
$ helm install devfile-registry ./deploy/chart/devfile-registry \
27+
--set global.ingress.domain=<ingress-domain> \
28+
--set devfileIndex.image=<index-image> \
29+
--set devfileIndex.tag=<index-image-tag>
30+
```
31+
32+
Where `<ingress-domain>` is the ingress domain for your cluster, `<index-image>` is the devfile index image you want to deploy, and `<index-image-tag>` is the corresponding image tag for the devfile index image.
33+
34+
For example, if you're installing your own custom devfile registry image for dev/test purposes on Minikube, you might run:
35+
36+
```bash
37+
$ helm install devfile-registry ./deploy/chart/devfile-registry \
38+
--set global.ingress.domain="$(minikube ip).nip.io" \
39+
--set devfileIndex.image=quay.io/someuser/devfile-index \
40+
--set devfileIndex.tag=latest
41+
```
42+
43+
You can deploy a devfile registry with a custom registry viewer image (uses `quay.io/devfile/registry-viewer:next` by default) by running the following:
44+
45+
```bash
46+
$ helm install devfile-registry ./deploy/chart/devfile-registry \
47+
--set global.ingress.domain="$(minikube ip).nip.io" \
48+
--set devfileIndex.image=quay.io/someuser/devfile-index \
49+
--set devfileIndex.tag=latest \
50+
--set registryViewer.image=quay.io/someuser/registry-viewer \
51+
--set registryViewer.tag=latest
52+
```
53+
54+
You can deploy a *headless* devfile registry (i.e. without the registry viewer) by specifying `--set global.headless=true` which will look like:
55+
56+
```bash
57+
$ helm install devfile-registry ./deploy/chart/devfile-registry \
58+
--set global.ingress.domain="$(minikube ip).nip.io" \
59+
--set global.headless=true \
60+
--set devfileIndex.image=quay.io/someuser/devfile-index \
61+
--set devfileIndex.tag=latest
62+
```
63+
2464
## Installing the Devfile Registry on OpenShift
2565

2666
If you're installing on OpenShift, you need to set `global.isOpenShift` to true, for example:
2767
```
2868
helm install devfile-registry deploy/chart/devfile-registry --set global.isOpenShift=true
2969
```
70+
#### Installation Via Helper Script Environment Variables
71+
By default the name of the install will be `devfile-registry` and the path to the chart will be `/deploy/chart/devfile-registry` as `helm-openshift-install.sh` is located at the root of the repository. If you wish to change these values you need to set the `INSTALL_NAME` and `CHART_PATH` environment variables prior to running the script. Note that `devfile-registry` will be postfixed to any custom name, e.g. `export $INSTALL_NAME=my-install` will result in a Helm install for `my-install-devfile-registry`.
72+
3073

31-
or, if you want to install a specific devfile index image, you can run:
74+
There are 4 ways that you can install the registry on OpenShift:
75+
#### 1: Via Installation Script With OpenShift Generated Route Hostname and Domain
76+
77+
If you wish to take advantage of OpenShift's generated hostname and domain, all you need to run is:
78+
```
79+
$ bash ./helm-openshift-install.sh
3280
```
33-
helm install devfile-registry deploy/chart/devfile-registry --set global.isOpenShift=true --set devfileIndex.image=quay.io/myuser/devfile-index --set devfileIndex.tag=latest
81+
This will install the Devfile Registry to OpenShift for you with the generated route hostname and domain. If you wish to include additional arguments such as changing the image for `devfileIndex`, you can include those alongside the script call:
82+
```
83+
$ bash ./helm-openshift-install.sh \
84+
--set devfileIndex.image=quay.io/someuser/devfile-index \
85+
--set devfileIndex.tag=latest
86+
```
87+
88+
#### 2: Via Installation Script With Custom Hostname
89+
90+
Similar to the above instructions, you can set your own custom domain as part of the arguments to the installation script.
3491
```
92+
$ bash ./helm-openshift-install.sh --set global.route.domain=<domain> <other arguments>
93+
```
94+
95+
#### 3: Via Helm CLI With Custom Hostname
96+
97+
If you do not wish to use a helper script to install to OpenShift, you are able to mimic the Kubernetes installation with one slight change. Instead of `--set global.ingress.domain` you will swap it with `--set global.route.domain` as OpenShift utilizes Routes instead of Ingress.
98+
```bash
99+
$ helm install devfile-registry ./deploy/chart/devfile-registry \
100+
--set global.route.domain=<route-domain> \
101+
--set devfileIndex.image=<index-image> \
102+
--set devfileIndex.tag=<index-image-tag>
103+
```
104+
105+
Installing to OpenShift follows the same process as Kubernetes, you just need to ensure that `--set global.isOpenShift=true` is an argument to the install. Additionally, instead of `--set global.ingress.domain=<domain>` for Kubernetes you will instead include `--set global.route.domain=<domain>` for OpenShift. All other arguments are available to either Kubernetes or OpenShift.
106+
107+
#### 4: Via Helm CLI With OpenShift Generated Route Hostname and Domain
108+
If you wish to manually mimic the `helm-openshift-install.sh` helper script you can follow these steps:
109+
1. Run `helm install <name> <chart path> --set global.isOpenShift=true <more arguments>`
110+
2. Wait for the initial deployment to finish
111+
3. Run `oc get route <name> -o jsonpath='{.spec.host}'` to obtain the generated route
112+
4. Run `helm upgrade <name> <chart path> --reuse-values --set global.route.domain=<route from step 3>`
35113

36114
## Updating the Devfile Registry
37115

@@ -62,8 +140,9 @@ The following fields can be configured in the Helm chart, either via the `values
62140

63141
| Parameter | Description | Default |
64142
| ----------------------- | --------------------------------------------- | ---------------------------------------------------------- |
65-
| `global.ingress.domain` | Ingress domain for the devfile registry | **MUST BE SET BY USER** |
143+
| `global.ingress.domain` | Kubernetes Ingress domain for the devfile registry | **MUST BE SET BY USER** |
66144
| `global.ingress.class` | Ingress class for the devfile registry | `nginx` |
145+
| `global.route.domain` | OpenShift Route domain for the devfile registry | **MUST BE SET BY USER** |
67146
| `global.ingress.secretName` | Name of an existing tls secret if using TLS | ` '' ` |
68147
| `global.isOpenShift ` | Set to true to use OpenShift routes instead of ingress | `false` |
69148
| `global.tlsEnabled` | Set to true to use the devfile registry with TLS | `false` |

deploy/chart/devfile-registry/templates/_template.tpl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
{{- .Values.global.ingress.domain | printf "%s.%s" $hostname -}}
2323
{{- end -}}
2424

25+
{{- define "devfileregistry.routeHostname" -}}
26+
{{- $hostname := .Values.hostnameOverride | default (printf "devfile-registry-%s" .Release.Namespace) -}}
27+
{{- if eq .Values.global.route.domain "" -}} # This allows for Openshift to generate the route name + domain
28+
{{- .Values.global.route.domain -}}
29+
{{- else -}}
30+
{{- .Values.global.route.domain | printf "%s.%s" $hostname -}}
31+
{{- end -}}
32+
{{- end -}}
33+
2534
{{- define "devfileregistry.ingressUrl" -}}
2635
{{- $hostname := .Values.hostnameOverride | default (printf "devfile-registry-%s" .Release.Namespace) -}}
2736
{{- if .Values.global.tlsEnabled -}}
@@ -31,6 +40,23 @@
3140
{{- end -}}
3241
{{- end -}}
3342

43+
{{- define "devfileregistry.routeUrl" -}}
44+
{{- $hostname := .Values.hostnameOverride | default (printf "devfile-registry-%s" .Release.Namespace) -}}
45+
{{- if .Values.global.tlsEnabled -}}
46+
{{- .Values.global.route.domain | printf "https://%s.%s" $hostname -}}
47+
{{- else -}}
48+
{{- .Values.global.route.domain | printf "http://%s.%s" $hostname -}}
49+
{{- end -}}
50+
{{- end -}}
51+
52+
{{- define "devfileregistry.fqdnUrl" -}}
53+
{{- if .Values.global.isOpenShift -}}
54+
{{- template "devfileregistry.routeUrl" . -}}
55+
{{- else -}}
56+
{{- template "devfileregistry.ingressUrl" . -}}
57+
{{- end -}}
58+
{{- end -}}
59+
3460
{{- define "devfileregistry.name" -}}
3561
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
3662
{{- end -}}

deploy/chart/devfile-registry/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ spec:
146146
{
147147
"name": "{{ template "devfileregistry.name" . }}",
148148
"url": "http://localhost:8080",
149-
"fqdn": "{{ template "devfileregistry.ingressUrl" . }}"
149+
"fqdn": "{{ template "devfileregistry.fqdnUrl" . }}"
150150
}
151151
]
152152
securityContext:

deploy/chart/devfile-registry/templates/route.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ metadata:
2121
name: {{ template "devfileregistry.fullname" . }}
2222
namespace: {{ .Release.Namespace }}
2323
spec:
24+
host: {{ template "devfileregistry.routeHostname" . }}
2425
to:
2526
kind: Service
2627
name: {{ template "devfileregistry.fullname" . }}

deploy/chart/devfile-registry/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ global:
1818
class: 'nginx'
1919
domain: 192.168.2.1.nip.io
2020
secretName: ''
21+
route:
22+
domain: ""
2123
isOpenShift: false
2224
tlsEnabled: false
2325
headless: false

helm-openshift-install.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright Red Hat
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
if [ $# -eq 0 ]; then
19+
echo "Usage: $0 <arguments>"
20+
exit 1
21+
fi
22+
23+
name=${INSTALL_NAME:-"devfile-registry"}
24+
path=${CHART_PATH:-"deploy/chart/devfile-registry"}
25+
START_TIME=$(date +%s)
26+
TIMEOUT_SEC=25
27+
SPINUP_SEC=60 # Helm Upgrade can have unexpected results if it is run while the cluster is initially starting
28+
29+
# If user set custom name postfix devfile-registry to it to sync with what was deployed
30+
if [ "$name" != "devfile-registry" ]; then
31+
name="${name}-devfile-registry"
32+
fi
33+
34+
# Run the install without the generated Openshift Route being passed to Registry Viewer fqdn as it does not exist yet
35+
helm install $name $path --set global.isOpenShift=true "$@"
36+
37+
while true; do
38+
ROUTE=$(oc get route $name -o jsonpath='{.spec.host}' 2>/dev/null)
39+
if [ -n "$ROUTE" ]; then
40+
echo Domain found: "$ROUTE"
41+
break
42+
fi
43+
new_time=$(date +%s)
44+
elapsed_time=$((new_time - START_TIME))
45+
if [ $elapsed_time -ge $TIMEOUT_SEC ]; then
46+
echo "TIMEOUT: Domain not found."
47+
exit 1
48+
fi
49+
sleep 1
50+
done
51+
52+
# Allow deployment to start occuring before the upgrade
53+
sleep $SPINUP_SEC
54+
55+
# Run upgrade with the new variable to set fqdn of the Registry Viewer
56+
helm upgrade $name $path --reuse-values --set global.route.domain=$ROUTE

0 commit comments

Comments
 (0)