Fixup the permissions script and make it more efficient (#355)

* Fixup the permissions script and make it more efficient

* update common and common-test versions
This commit is contained in:
Kjeld Schouten-Lebbing
2021-04-15 14:28:28 +02:00
committed by GitHub
parent f9f44af8ba
commit 6abf2fae1a
5 changed files with 77 additions and 81 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
apiVersion: v2 apiVersion: v2
kubeVersion: ">=1.16.0-0" kubeVersion: ">=1.16.0-0"
name: common-test name: common-test
version: 2.1.1 version: 2.1.2
# upstream_version: # upstream_version:
appVersion: none appVersion: none
description: Helper chart to test different use cases of the common library description: Helper chart to test different use cases of the common library
+64 -36
View File
@@ -20,47 +20,75 @@ env: {}
# PUID: 1001 # PUID: 1001
# PGID: 1001 # PGID: 1001
services:
main:
enabled: true
port:
port: 9117
additionalServices:
- name: test3
enabled: true
type: ClusterIP
port:
port: 8083
name: extra-tcp-test
protocol: TCP
targetPort: 8083
- name: test4
enabled: true
type: ClusterIP
port:
port: 8084
name: extra-udp-test
protocol: UDP
targetPort: 8084
ingress:
test1:
enabled: true
test2:
enabled: true
additionalIngress:
- name: "test3"
enabled: true
- name: "test4"
enabled: true
persistence: persistence:
config: config:
enabled: false
emptyDir: false
torrentblackhole:
enabled: false
emptyDir: false
mountPath: /downloads
## Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
# storageClass: "-"
# accessMode: ReadWriteOnce
# size: 1Gi
## Do not delete the pvc upon helm uninstall
# skipuninstall: false
# existingClaim: ""
## TrueCharts Values
ingress:
main:
enabled: true enabled: true
# Used when including ingress using {{ include "common.ingress" . }} mountPath: "/config"
type: "HTTP" emptyDir: true
entrypoint: "websecure" accessMode: ReadWriteOnce
certType: "" size: 1Gi
annotations: {} storageClass: ""
hosts:
- host: chart-example.local
path: /
appVolumeMounts: # these values and names are set specifically with the unittests in mind.
config: fixMountPermissions: false
deviceMounts:
test1:
enabled: true enabled: true
emptyDir: true emptyDir: true
mountPath: "/test1"
hostPath: "/tmp"
test2:
enabled: true
emptyDir: false
mountPath: "/test2"
hostPath: "/tmp"
# these values and names are set specifically with the unittests in mind.
customStorage:
- name: "test3"
enabled: true
emptyDir: true
mountPath: "/test3"
hostPath: ""
- name: "test4"
enabled: true
emptyDir: false
setPermissions: true setPermissions: true
mountPath: "/config" mountPath: "/test4"
hostPath: "/tmp"
+1
View File
@@ -78,5 +78,6 @@ customStorage:
- name: "test4" - name: "test4"
enabled: true enabled: true
emptyDir: false emptyDir: false
setPermissions: true
mountPath: "/test4" mountPath: "/test4"
hostPath: "/tmp" hostPath: "/tmp"
+1 -1
View File
@@ -1,7 +1,7 @@
apiVersion: v2 apiVersion: v2
kubeVersion: ">=1.16.0-0" kubeVersion: ">=1.16.0-0"
name: common name: common
version: 3.0.2 version: 3.0.3
# upstream_version: # upstream_version:
appVersion: none appVersion: none
description: Function library for TrueCharts description: Function library for TrueCharts
@@ -5,55 +5,26 @@ before chart installation.
{{- define "common.storage.permissions" -}} {{- define "common.storage.permissions" -}}
{{- if .Values.fixMountPermissions }} {{- if .Values.fixMountPermissions }}
{{- range $index, $avm := .Values.customStorage -}}
{{- if and $avm.enabled $avm.setPermissions}} {{- $jobName := include "common.names.fullname" . -}}
{{- $values := .Values -}}
{{- print "---" | nindent 0 -}} {{- print "---" | nindent 0 -}}
{{- $AVMValues := $avm -}}
{{- if not $AVMValues.nameSuffix -}}
{{- $_ := set $AVMValues "nameSuffix" $index -}}
{{ end -}}
{{- $_ := set $ "ObjectValues" (dict "appVolumeMounts" $AVMValues) -}}
{{ include "common.storage.permissions.job" $ | nindent 0 }}
{{- $values := .Values.appVolumeMounts -}}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.appVolumeMounts -}}
{{- $values = . -}}
{{- end -}}
{{ end -}}
{{- $JobName := include "common.names.fullname" . -}}
{{- if hasKey $values "nameSuffix" -}}
{{- $JobName = printf "%v-%v" $JobName $values.nameSuffix -}}
{{ end -}}
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ $JobName }} name: {{ $jobName }}-autopermissions
labels: labels:
{{- include "common.labels" . | nindent 4 }} {{- include "common.labels" . | nindent 4 }}
{{- with .Values.controllerLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations: annotations:
"helm.sh/hook": pre-install,pre-upgrade "helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-10" "helm.sh/hook-weight": "-10"
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed,before-hook-creation "helm.sh/hook-delete-policy": hook-succeeded,hook-failed,before-hook-creation
{{- with .Values.controllerAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec: spec:
template: template:
metadata: metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "common.labels.selectorLabels" . | nindent 8 }}
spec: spec:
restartPolicy: Never restartPolicy: Never
containers: containers:
@@ -62,8 +33,8 @@ spec:
command: command:
- /bin/sh - /bin/sh
- -c - -c
- | - | {{ range $index, $cs := .Values.customStorage}}{{ if and $cs.enabled $cs.setPermissions}}
chown -R{{ if eq .podSecurityContext.runAsNonRoot false }}{{ print .Values.PUID }}{{ else }}{{ print .podSecurityContext.runAsUser }}{{ end }}:{{ print .podSecurityContext.fsGroup }} {{ print $values.mountPath }} chown -R {{ if eq $values.podSecurityContext.runAsNonRoot false }}{{ print $values.PUID }}{{ else }}{{ print $values.podSecurityContext.runAsUser }}{{ end }}:{{ print $values.podSecurityContext.fsGroup }} {{ print $cs.mountPath }}{{ end }}{{ end }}
#args: #args:
# #
#securityContext: #securityContext:
@@ -78,7 +49,3 @@ spec:
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }}
{{- end }}