Skip to content

Commit 8c48030

Browse files
committed
Added experimental GitOps and other changes
1 parent 3840d50 commit 8c48030

File tree

13 files changed

+207
-67
lines changed

13 files changed

+207
-67
lines changed

README.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# OPC-Router 4 Helm Chart
22

3+
## Prequisites
4+
- Kubernetes 1.12+
5+
- Helm 3.1.0
6+
7+
## Installation
8+
To install the chart with the name `my-opcrouter`:
9+
```shell
10+
$ helm install my-opcrouter <Path> --set I_do_accept_the_EULA=true
11+
```
12+
This command will install the opc router with standard settings, as a service with a seperate mongodb container. Accepting the [End User License Agreement](https://www.opc-router.com/terms-of-use-and-eula/) by setting `I_do_accept_the_EULA` to true is required for the OPCRouter to run.
13+
14+
## Uninstalling
15+
The chart with the name `my-opcrouter` can simply be uninstalled by executing:
16+
```shell
17+
$ helm uninstall my-opcrouter
18+
```
19+
However, keep in mind that the persitant volumes of the mongodb container don't get deleted by this. When reinstalling the chart under the same name you will have to use the previous mongodb root password and replica set key or delete the persistant volume beforehand.
20+
321
## Parameters
422

523
### Global parameters
@@ -11,39 +29,42 @@
1129
| `global.storageClass` | Global StorageClass for Persistent Volume(s) | `""` |
1230
| `global.namespaceOverride` | Override the namespace for resource deployed by the chart, but can itself be overridden by the local namespaceOverride | `""` |
1331

14-
1532
### Common parameters
1633

17-
| Name | Description | Value |
18-
| ------------------------ | --------------------------------------------------------------------------------------------------------- | --------------- |
19-
| `nameOverride` | String to partially override opc-router.fullname template (will maintain the release name) | `""` |
20-
| `fullnameOverride` | String to fully override opc-router.fullname template | `""` |
21-
34+
| Name | Description | Value |
35+
| ------------------ | ------------------------------------------------------------------------------------------ | ----- |
36+
| `nameOverride` | String to partially override opc-router.fullname template (will maintain the release name) | `""` |
37+
| `fullnameOverride` | String to fully override opc-router.fullname template | `""` |
2238

2339
### OPCRouter parameters
2440

25-
| Name | Description | Value |
26-
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------- |
27-
| `I_do_accept_the_EULA` | If this is false the opc router container won't be able to run. | `false` |
28-
| `image.repository` | OPC-Router image registry. | `opcrouter/runtime` |
29-
| `image.tag` | OPC-Router image tag (immutable tags are recommended). | `""` |
30-
| `image.pullPolicy` | OPC-Router image pull policy. | `IfNotPresent` |
31-
| `serviceAccount.create` | Specifies whether a service account should be created. | `true` |
32-
| `serviceAccount.annotations` | Annotations to add to the service account. | `{}` |
33-
| `serviceAccount.name` | Name of the service account to use. If not set and create is true, it is generated using the fullname. | `""` |
34-
| `service.type` | Type of the service. Possible values: ClusterIP, NodePort, LoadBalancer. | `ClusterIP` |
35-
| `service.port` | Internal port. The service will be reachable under this port inside the cluster. | `27017` |
36-
| `service.nodePort` | External port. When NodePort, this port will allow external access to the service. | `""` |
37-
| `project.projectRepo` | URL to git repository of a opcrouter4 project. Optional. Empty means no project gets loaded. | `""` |
38-
| `project.projectPath` | Path to the project .rpe file in the repository. Don't begin with '/'. Optional. | `""` |
39-
| `project.configPath` | Path to a projects configuration file. Optional. Empty means no configuration file gets loaded. | `""` |
40-
| `project.auth.ssh_secret` | An existing secret containing the ssh-key under the key 'project-ssh-key'. Optional. | `""` |
41-
| `project.auth.ssh_key` | SSH private key for accessing the git repository. Overridden by ssh_secret, Optional. | `""` |
42-
| `project.auth.safe_key` | If false, the ssh key won't be saved on the cluster and will be deleted from the cluster. | `true` |
43-
| `containerHistoryLimit` | The size of the history of deployments kept for potential rollbacks. | `10` |
44-
| `mongodb.deploy` | If false, the mongodb container wont be deployed. Useful when using integrated db of opcrouter/runtime.| `true` |
45-
| `mongodb.auth.dbRootPassword` | Root password for the mongodb. Will override autogenerated or existing one in secret. | `""` |
46-
| `mongodb.auth.dbReplicaKeySet` | Replica set key for the mongodb. Will override autogenerated or existing one in secret. | `""` |
41+
| Name | Description | Value |
42+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------- |
43+
| `I_do_accept_the_EULA` | If this is false the opc router container won't be able to run. | `false` |
44+
| `image.repository` | OPC-Router image registry. | `opcrouter/service` |
45+
| `image.tag` | OPC-Router image tag (immutable tags are recommended). | `""` |
46+
| `image.pullPolicy` | OPC-Router image pull policy. | `IfNotPresent` |
47+
| `serviceAccount.create` | Specifies whether a service account should be created. | `true` |
48+
| `serviceAccount.annotations` | Annotations to add to the service account. | `{}` |
49+
| `serviceAccount.name` | Name of the service account to use. If not set and create is true, it is generated using the fullname. | `""` |
50+
| `project.projectRepo` | URL to git repository of a opcrouter4 project. Optional. Empty means no project gets loaded. | `""` |
51+
| `project.projectPath` | Path to the project .rpe file in the repository. Don't begin with '/'. Optional. | `""` |
52+
| `project.configPath` | Path to a projects configuration file. Optional. Empty means no configuration file gets loaded. | `""` |
53+
| `project.auth.ssh_secret` | An existing secret containing the ssh-key under the key 'project-ssh-key'. Optional. | `""` |
54+
| `project.auth.ssh_key` | SSH private key for accessing the git repository. Overridden by ssh_secret, Optional. | `""` |
55+
| `project.auth.safe_key` | If false, the ssh key won't be saved on the cluster and will be deleted from the cluster. | `true` |
56+
| `project.persistantVolume.deploy` | If true, deploys a persistant storage volume for the project and runtime db. | `true` |
57+
| `project.persistantVolume.size` | The size of the persistant volume. | `3Gi` |
58+
| `containerHistoryLimit` | The size of the history of deployments kept for potential rollbacks. | `10` |
59+
| `mongodb.deploy` | If false, the mongodb container wont be deployed. Useful when using integrated db of opcrouter/runtime. | `true` |
60+
| `mongodb.replicaCount` | The number of mongodb pods to deploy. Set to two when using a redundency twin. | `1` |
61+
| `mongodb.auth.enabled` | If false, the mongodb won't require any authentification to access. | `true` |
62+
| `mongodb.auth.dbRootPassword` | Root password for the mongodb. Will override autogenerated or existing one in secret. | `""` |
63+
| `mongodb.auth.dbReplicaKeySet` | Replica set key for the mongodb. Will override autogenerated or existing one in secret. | `""` |
64+
| `mongodb.externalAccess.enabled` | If false, the application won't be reachable from outside the cluster. | `true` |
65+
| `mongodb.externalAccess.service.type` | Type of the service. Possible values: ClusterIP, NodePort, LoadBalancer. | `ClusterIP` |
66+
| `mongodb.externalAccess.service.port` | Internal port. The service will be reachable under this port inside the cluster. | `27017` |
67+
| `mongodb.externalAccess.service.nodePorts` | External ports. When NodePort, the ports configured here will allow external access to the service. | ` -` |
4768

4869
### WARNING: MongoDB root password and replica key set
4970

charts/opc-router/templates/NOTES.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
77
{{- end }}
88
{{- end }}
9-
{{- else if contains "NodePort" .Values.service.type }}
10-
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "opc-router.fullname" . }})
9+
{{- else if not .Values.mongodb.externalAccess.enabled }}
10+
External access was disabled, you will not be able to reach the application from the outside.
11+
{{- else if contains "NodePort" .Values.mongodb.externalAccess.service.type }}
12+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ if .Values.mongodb.deploy }}{{ .Release.Name }}-mongodb-0-external{{ else }}{{ include "opc-router.fullname" . }}{{ end }})
1113
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
1214
echo $NODE_IP:$NODE_PORT
13-
{{- else if contains "LoadBalancer" .Values.service.type }}
15+
{{- else if contains "LoadBalancer" .Values.mongodb.externalAccess.service.type }}
1416
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
1517
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "opc-router.fullname" . }}'
16-
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "opc-router.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
17-
echo $SERVICE_IP:{{ .Values.service.port }}
18-
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ if .Values.mongodb.deploy }}{{ .Release.Name }}-mongodb-0-external{{ else }}{{ include "opc-router.fullname" . }}{{ end }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
19+
echo $SERVICE_IP:{{ .Values.mongodb.externalAccess.service.port }}
20+
{{- else if contains "ClusterIP" .Values.mongodb.externalAccess.service.type }}
1921
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "opc-router.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
2022
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
2123
echo "You can now reach the configuration at 127.0.0.1 with port 27020"
2224
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 27020:$CONTAINER_PORT
2325
{{- end }}
2426
{{- else }}
2527
The chart was successfully installed but the opc-router container won't run:
26-
You need to accept to the terms and conditions of the EULA by setting the value I_do_accept_the_EULA to "true".
28+
You need to accept to the terms and conditions of the EULA (https://www.opc-router.com/terms-of-use-and-eula/) by setting the value I_do_accept_the_EULA to "true".
2729
{{ end }}

charts/opc-router/templates/_scripts.tpl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,30 @@ Commands to clone the project repo
2323
mkdir -p /data/project;
2424
git clone {{ .Values.project.projectRepo }} /data/project;
2525
echo Done;
26-
{{- end }}
26+
{{- end }}
27+
28+
{{/*
29+
Commands to continuously update the project and restart the pod on new version
30+
*/}}
31+
{{- define "project.gitops" }}
32+
{{- include "project.ssh" $}}
33+
apk add curl;
34+
cat <<EOF > ~/gitops.sh
35+
cd /data/project;
36+
while [ true ]; do
37+
sleep 60;
38+
{{- if (or $.Values.project.auth.ssh_key $.Values.project.auth.ssh_secret) }}
39+
eval \`ssh-agent\`;
40+
ssh-add ~/.ssh/id;
41+
{{- end }}
42+
git fetch;
43+
if [ \$(git rev-parse HEAD) != \$(git rev-parse @{u}) ]; then
44+
git pull;
45+
curl -XDELETE http://localhost:8001/api/v1/namespaces/{{ .Release.Namespace }}/pods?labelSelector=app.kubernetes.io/name={{ .Chart.Name }};
46+
fi
47+
done
48+
EOF
49+
50+
chmod 777 ~/gitops.sh;
51+
~/gitops.sh;
52+
{{- end }}

charts/opc-router/templates/deletesecret.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.project.projectRepo }}
12
{{- if not .Values.project.auth.safe_key }}
23
{{- with .Values.project.auth.ssh_key }}
34
apiVersion: v1
@@ -11,4 +12,5 @@ type: Opaque
1112
data:
1213
project-ssh-key: {{ . | b64enc }}
1314
{{- end }}
15+
{{- end }}
1416
{{- end }}

charts/opc-router/templates/deployment.yaml

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,30 @@ spec:
3333
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3434
imagePullPolicy: {{ .Values.image.pullPolicy }}
3535
ports:
36+
{{- if eq .Values.image.repository "opcrouter/runtime" }}
37+
{{- if eq .Values.mongodb.deploy false }}
3638
- name: opcrouter
3739
containerPort: 27017
3840
protocol: TCP
41+
{{- end }}
42+
{{- end }}
3943
# Environment variables for the opcrouter container
4044
env:
4145
# Variables for connecting a service to the mongodb if a service is specified
42-
{{- if eq .Values.image.repository "opcrouter/service" }}
43-
- name: OR_DATABASE_USERNAME
44-
value: root
46+
{{- if .Values.mongodb.deploy }}
4547
- name: OR_DATABASE_HOST_ADRESS
4648
value: "{{ .Release.Name }}-mongodb-0.{{ .Release.Name }}-mongodb-headless"
49+
{{- if .Values.mongodb.auth.enabled }}
50+
- name: OR_DATABASE_USERNAME
51+
value: root
4752
# Loading the password for the mongodb from secret
4853
- name: OR_DATABASE_PASSWORD
4954
valueFrom:
5055
secretKeyRef:
5156
name: {{ .Values.mongodb.auth.existingSecret }}
5257
key: mongodb-root-password
5358
{{- end }}
59+
{{- end }}
5460
- name: OR_I_ACCEPT_EULA
5561
value: {{ .Values.I_do_accept_the_EULA | quote }}
5662
# Loading environment variables specified in the values file
@@ -60,9 +66,9 @@ spec:
6066
{{- end }}
6167
resources:
6268
{{- toYaml .Values.resources | nindent 12 }}
63-
# Project repo is specified: Get and load project
64-
{{- if .Values.project.projectRepo }}
65-
# Volume mount for the project and configuration file
69+
{{- if .Values.project.projectRepo }}
70+
# Project repo is specified: Get and load project
71+
# Volume mount for the project and configuration file
6672
volumeMounts:
6773
- mountPath: /data
6874
name: project-volume
@@ -72,15 +78,42 @@ spec:
7278
- "--source"
7379
- "/data/project/{{ .Values.project.projectPath }}"
7480
{{- if eq .Values.image.repository "opcrouter/runtime" }}
81+
{{- if eq .Values.mongodb.deploy false }}
7582
- "--configdb"
7683
- "OPCRouterRuntime"
7784
{{- end }}
85+
{{- end }}
7886
- "--allow-clear-config"
7987
- "--start-service"
8088
{{- if .Values.project.configPath }}
8189
- "--runtime-configuration-filepath"
8290
- "/data/project/{{ .Values.project.configPath }}"
8391
{{- end }}
92+
{{- if .Values.project.autoUpdate }}
93+
- name: kubernetes-proxy
94+
image: bitnami/kubectl:latest
95+
# Script for setting ssh credentials and cloning the repository onto the volume
96+
command: ['sh', '-c', "kubectl proxy;"]
97+
- name: git-ops
98+
image: alpine/git:latest
99+
# Script for setting ssh credentials and cloning the repository onto the volume
100+
command: ["sh", "-c"]
101+
args:
102+
- >-
103+
{{- include "project.gitops" $ | indent 12}}
104+
# Volume mount for the project and configuration file
105+
volumeMounts:
106+
- mountPath: /data
107+
name: project-volume
108+
{{- if (or .Values.project.auth.ssh_key .Values.project.auth.ssh_secret) }}
109+
env:
110+
- name: PROJECT_SSH_KEY
111+
valueFrom:
112+
secretKeyRef:
113+
name: {{ .Values.project.auth.ssh_secret | default (printf "%s-%s" (include "opc-router.fullname" $) "secret" | trunc 63 | trimSuffix "-") }}
114+
key: project-ssh-key
115+
{{- end }}
116+
{{- end }}
84117
# Init container for pulling the project files
85118
initContainers:
86119
- name: pull-project
@@ -105,9 +138,13 @@ spec:
105138
# Volume for the project and configuration file
106139
volumes:
107140
- name: project-volume
141+
{{- if .Values.project.persistantVolume.deploy }}
108142
persistentVolumeClaim:
109143
claimName: {{ include "opc-router.fullname" . }}
110-
{{- end }}
144+
{{- else}}
145+
emptyDir: {}
146+
{{- end }}
147+
{{- end }}
111148
{{- with .Values.nodeSelector }}
112149
nodeSelector:
113150
{{- toYaml . | nindent 8 }}

0 commit comments

Comments
 (0)