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

RBAC for pre-install hook #181

Merged
merged 1 commit into from
Sep 9, 2019
Merged
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
2 changes: 1 addition & 1 deletion ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if [ "$TRAVIS_BRANCH" != "master" ] && [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ -
sudo helm dependency update
cd ../../../

with_files=`ls deploy/helm/sumologic/templates/*.yaml | grep -v "setup-job.yaml" | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\\/g'`
with_files=`ls deploy/helm/sumologic/templates/*.yaml | grep -v "setup-*.yaml" | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\\/g'`
eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl --set sumologic.endpoint="bogus" --set sumologic.accessId="bogus" --set sumologic.accessKey="bogus"'

if [[ $(git diff deploy/kubernetes/fluentd-sumologic.yaml.tmpl) ]]; then
Expand Down
19 changes: 19 additions & 0 deletions deploy/helm/sumologic/templates/setup/setup-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.sumologic.setupEnabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ template "sumologic.fullname" . }}-setup
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels:
app: {{ template "sumologic.labels.app" . }}
{{ template "sumologic.labels.common" . }}
rules:
- apiGroups:
- ""
resources:
- secrets
- namespaces
verbs: ["get", "create", "describe"]
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.sumologic.setupEnabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ template "sumologic.fullname" . }}-setup
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels:
app: {{ template "sumologic.labels.app" . }}
{{ template "sumologic.labels.common" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "sumologic.fullname" . }}-setup
subjects:
- kind: ServiceAccount
name: {{ template "sumologic.fullname" . }}-setup
namespace: {{ .Release.Namespace }}

{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "sumologic.fullname" . }}-init
name: {{ template "sumologic.fullname" . }}-setup
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-install
Expand All @@ -14,6 +14,7 @@ spec:
template:
spec:
restartPolicy: OnFailure
serviceAccountName: {{ template "sumologic.fullname" . }}-setup
containers:
- name: setup
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
Expand Down
12 changes: 12 additions & 0 deletions deploy/helm/sumologic/templates/setup/setup-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.sumologic.setupEnabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "sumologic.fullname" . }}-setup
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to name all these new resources with the same name?

Copy link
Contributor Author

@maimaisie maimaisie Sep 9, 2019

Choose a reason for hiding this comment

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

yes, it's a very conventional thing to give resources the same name in helm as long as we don't have two or more resources of the same type with the same name

annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels:
app: {{ template "sumologic.labels.app" . }}
{{ template "sumologic.labels.common" . }}
{{- end }}