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

Datadir automatic sync #126

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
96 changes: 96 additions & 0 deletions templates/datadirsync/datadirsync-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{- $webapp := .Values.georchestra.datadirsync -}}
{{- if $webapp.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "georchestra.fullname" . }}-datadirsync
labels:
{{- include "georchestra.labels" . | nindent 4 }}
app.kubernetes.io/component: {{ include "georchestra.fullname" . }}-datadirsync
spec:
replicas: 1
selector:
matchLabels:
app: {{ include "georchestra.fullname" . }}-datadirsync
template:
metadata:
labels:
app: {{ include "georchestra.fullname" . }}-datadirsync
spec:
serviceAccountName: {{ include "georchestra.fullname" . }}-datadirsync-serviceaccount
initContainers:
- name: init-permissions
image: busybox
command:
- sh
- -c
- |
echo "Setting up SSH key..."
if cp /tmp-ssh/id_rsa /tmp/git-rollout-operator/id_rsa; then
echo "SSH key copied successfully"
else
echo "Copy failed"
fi
if chown 1001:1001 /tmp/git-rollout-operator/id_rsa && chmod 600 /tmp/git-rollout-operator/id_rsa; then
echo "SSH key permissions and ownership set successfully"
else
echo "Failed to set permissions or ownership"
fi
volumeMounts:
- name: ssh-key-volume
mountPath: /tmp-ssh
- name: git-rollout-operator-volume
mountPath: /tmp/git-rollout-operator
containers:
- name: operator
image: {{ $webapp.image }}
env:
- name: GIT_REPO_URL
value: "{{ .Values.georchestra.datadir.git.url }}"
- name: GIT_BRANCH
value: "{{ .Values.georchestra.datadir.git.ref }}"
- name: POLL_INTERVAL
value: "{{ $webapp.pollInterval }}"
- name: ROLLOUT_DEPLOYMENTS
value: |
{{ $prefix := include "georchestra.fullname" . -}}
{{ $suffixes := $webapp.deploymentSuffixNameList -}}
{{ $deployments := list -}}
{{- range $suffix := $suffixes }}
{{ $deployments = append $deployments (printf "%s-%s" $prefix $suffix) }}
{{- end -}}
{{- join ", " $deployments }}
- name: ROLLOUT_NAMESPACE
value: "{{ .Release.Namespace }}"
{{- if and .Values.gitCredentials.username .Values.gitCredentials.token }}
- name: GIT_USERNAME
valueFrom:
secretKeyRef:
name: "{{ $webapp.gitCredentials.secretName }}"
key: "{{ $webapp.gitCredentials.usernameKey }}"
- name: GIT_TOKEN
valueFrom:
secretKeyRef:
name: "{{ $webapp.gitCredentials.secretName }}"
key: "{{ $webapp.gitCredentials.tokenKey }}"
{{- end }}
{{- if .Values.gitCredentials.ssh }}
- name: GIT_SSH_COMMAND
value: ssh -i /tmp/git-rollout-operator/id_rsa -o "IdentitiesOnly=yes" -o "StrictHostKeyChecking=no"
volumeMounts:
- name: ssh-key-volume
mountPath: /tmp-ssh/id_rsa
subPath: id_rsa
- name: git-rollout-operator-volume
mountPath: /tmp/git-rollout-operator
{{- end }}
volumes:
- name: ssh-key-volume
secret:
secretName: {{ include "georchestra.fullname" . }}-{{ $webapp.gitCredentials.secretSuffixName }}
items:
- key: {{ $webapp.gitCredentials.sshKey }}
path: id_rsa
- name: git-rollout-operator-volume
emptyDir: {}
{{- end }}
12 changes: 12 additions & 0 deletions templates/datadirsync/datadirsync-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- $webapp := .Values.georchestra.datadirsync -}}
{{- if $webapp.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: {{ .Release.Namespace }}
name: {{ include "georchestra.fullname" . }}-datadirsync-role
rules:
Copy link
Member

@edevosc2c edevosc2c Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to limit the roles to the deployments listed in deploymentSuffixNameList?

According to stackoverflow you can limit the access to certain deployments using resourceNames: https://stackoverflow.com/a/68980720

- apiGroups: ["apps"]
resources: ["pods", "deployments"]
verbs: ["get", "list", "patch", "update"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we limit ourselves to just: verbs: ["get", "patch"]?
https://stackoverflow.com/a/68980720

{{- end }}
15 changes: 15 additions & 0 deletions templates/datadirsync/datadirsync-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- $webapp := .Values.georchestra.datadirsync -}}
{{- if $webapp.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "georchestra.fullname" . }}-datadirsync-rolebinding
subjects:
- kind: ServiceAccount
name: {{ include "georchestra.fullname" . }}-datadirsync-serviceaccount
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
name: {{ include "georchestra.fullname" . }}-datadirsync-role
apiGroup: rbac.authorization.k8s.io
{{- end }}
12 changes: 12 additions & 0 deletions templates/datadirsync/datadirsync-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- $webapp := .Values.georchestra.datadirsync -}}
{{- if $webapp.enabled -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "georchestra.fullname" . }}-datadirsync-credentials
type: Opaque
data:
username: {{ .Values.gitCredentials.username | b64enc }}
token: {{ .Values.gitCredentials.token | b64enc }}
ssh: {{ .Values.gitCredentials.ssh | b64enc }}
{{- end }}
8 changes: 8 additions & 0 deletions templates/datadirsync/datadirsync-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $webapp := .Values.georchestra.datadirsync -}}
{{- if $webapp.enabled -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "georchestra.fullname" . }}-datadirsync-serviceaccount
namespace: {{ .Release.Namespace }}
{{- end }}
18 changes: 18 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ georchestra:
# relay_username: aaaa
# relay_password: aaaa
extra_environment: []
datadirsync:
enabled: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the datadir sync disabled by default.

image: jemacchi/simple-git-rollout-operator:1.3.1 # TODO: image should be in context of c2c dockerhub account (?)
pollInterval: 10
deploymentSuffixNameList:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One component is sufficient for the example. You can just limit to - geoserver

- geoserver
- mapstore
- header
gitCredentials:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what's the diff here with the other gitCredentials section in the YAML?

secretSuffixName: datadirsync-credentials
usernameKey: username
tokenKey: token
sshKey: ssh

fqdn: "georchestra-127-0-1-1.traefik.me"

Expand Down Expand Up @@ -393,6 +406,11 @@ rabbitmq:
# storage_class_name: default
# size: 1Gi

gitCredentials:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

username: "" # To be provided during helm install
token: "" # To be provided during helm install
ssh: "" # To be provided during helm install

# Allow to override /etc/hosts for ALL apps
# https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/
hostAliases: []
Expand Down
Loading