Skip to content

Commit

Permalink
Merge pull request #49 from jiaqiluo/backport-multiple-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqiluo authored Sep 1, 2021
2 parents 61297a3 + 241c4db commit ac500f4
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 3 deletions.
6 changes: 5 additions & 1 deletion charts/rancher-webhook/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
{{- else -}}
{{- "" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "rancher-webhook.labels" -}}
app: rancher-webhook
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.preDelete.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: rancher-webhook-pre-delete
labels: {{ include "rancher-webhook.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "2"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: rancher-webhook-pre-delete
subjects:
- kind: ServiceAccount
name: rancher-webhook-pre-delete
namespace: {{ .Release.Namespace }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/rancher-webhook/templates/pre-delete-hook-cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if .Values.preDelete.enabled }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rancher-webhook-pre-delete
labels: {{ include "rancher-webhook.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
rules:
- apiGroups: [ "admissionregistration.k8s.io" ]
resources: [ "mutatingwebhookconfigurations" ]
verbs: [ "delete" ]
resourceNames: [ "rancher.cattle.io" ]
- apiGroups: [ "" ]
resources: [ "serviceaccounts" ]
verbs: [ "get" ]
- apiGroups: [ "policy" ]
resources: [ "podsecuritypolicies" ]
verbs: [ "use" ]
resourceNames: [ "rancher-webhook-pre-delete" ]
{{- end }}
26 changes: 26 additions & 0 deletions charts/rancher-webhook/templates/pre-delete-hook-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.preDelete.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: rancher-webhook-pre-delete
namespace: {{ .Release.Namespace }}
labels: {{ include "rancher-webhook.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "3"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
backoffLimit: 3
template:
metadata:
name: rancher-webhook-pre-delete
labels: {{ include "rancher-webhook.labels" . | nindent 8 }}
spec:
serviceAccountName: rancher-webhook-pre-delete
restartPolicy: OnFailure
containers:
- name: rancher-webhook-pre-delete
image: "{{ include "system_default_registry" . }}{{ .Values.preDelete.image.repository }}:{{ .Values.preDelete.image.tag }}"
imagePullPolicy: IfNotPresent
command: [ "kubectl", "delete", "--ignore-not-found=true", "mutatingwebhookconfigurations", "rancher.cattle.io" ]
{{- end }}
33 changes: 33 additions & 0 deletions charts/rancher-webhook/templates/pre-delete-hook-psp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.preDelete.enabled }}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: rancher-webhook-pre-delete
labels: {{ include "rancher-webhook.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
spec:
privileged: false
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'RunAsAny'
seLinux:
rule: 'RunAsAny'
supplementalGroups:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
fsGroup:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
readOnlyRootFilesystem: false
volumes:
- 'secret'
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.preDelete.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: rancher-webhook-pre-delete
namespace: {{ .Release.Namespace }}
labels: {{ include "rancher-webhook.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
{{- end }}
8 changes: 7 additions & 1 deletion charts/rancher-webhook/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ image:

global:
cattle:
systemDefaultRegistry: ""
systemDefaultRegistry: ""

preDelete:
enabled: true
image:
repository: rancher/kubectl
tag: v1.20.2
2 changes: 1 addition & 1 deletion scripts/package-helm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sed -i \
build/charts/rancher-webhook/Chart.yaml

sed -i \
-e 's/tag:.*/tag: '${HELM_TAG}'/' \
-e 's/tag: latest/tag: '${HELM_TAG}'/' \
build/charts/rancher-webhook/values.yaml

helm package -d ./dist/artifacts ./build/charts/rancher-webhook

0 comments on commit ac500f4

Please sign in to comment.