Woojoong Kim | 3f51f0c | 2019-09-06 11:31:13 -0700 | [diff] [blame] | 1 | {{- /* |
| 2 | Copyright 2019-present Open Networking Foundation |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ -}} |
| 16 | |
| 17 | {{/* |
| 18 | Renders a set of standardised labels |
| 19 | */}} |
| 20 | {{- define "cdn-remote.metadata_labels" -}} |
| 21 | {{- $application := index . 0 -}} |
| 22 | {{- $context := index . 1 -}} |
| 23 | release: {{ $context.Release.Name }} |
| 24 | app: {{ $application }} |
| 25 | {{- end -}} |
| 26 | |
| 27 | {{/* |
| 28 | Render the given template. |
| 29 | */}} |
| 30 | {{- define "cdn-remote.template" -}} |
| 31 | {{- $name := index . 0 -}} |
| 32 | {{- $context := index . 1 -}} |
| 33 | {{- $last := base $context.Template.Name }} |
| 34 | {{- $wtf := $context.Template.Name | replace $last $name -}} |
| 35 | {{ include $wtf $context }} |
| 36 | {{- end -}} |
| 37 | |
| 38 | {{/* |
| 39 | Get Domain name |
| 40 | */}} |
| 41 | {{- define "cdn-remote.get_domain" -}} |
| 42 | {{- $service := index . 0 -}} |
| 43 | {{- $context := index . 1 -}} |
| 44 | {{- printf "%s-0.%s.%s.%s" $service $service $context.Release.Namespace "svc.cluster.local" -}} |
| 45 | {{- end -}} |
| 46 | |
| 47 | {{/* |
| 48 | Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint. |
| 49 | */}} |
| 50 | {{- define "cdn-remote.service_account" -}} |
| 51 | {{- $saName := index . 0 -}} |
| 52 | {{- $context := index . 1 -}} |
| 53 | {{- $saNamespace := $context.Release.Namespace }} |
| 54 | --- |
| 55 | apiVersion: v1 |
| 56 | kind: ServiceAccount |
| 57 | metadata: |
| 58 | name: {{ $saName }} |
| 59 | namespace: {{ $saNamespace }} |
| 60 | labels: |
| 61 | {{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }} |
| 62 | --- |
| 63 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 64 | kind: RoleBinding |
| 65 | metadata: |
| 66 | name: {{ $saName }} |
| 67 | namespace: {{ $saNamespace }} |
| 68 | labels: |
| 69 | {{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }} |
| 70 | roleRef: |
| 71 | apiGroup: rbac.authorization.k8s.io |
| 72 | kind: Role |
| 73 | name: {{ $saName }} |
| 74 | subjects: |
| 75 | - kind: ServiceAccount |
| 76 | name: {{ $saName }} |
| 77 | namespace: {{ $saNamespace }} |
| 78 | --- |
| 79 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 80 | kind: Role |
| 81 | metadata: |
| 82 | name: {{ $saName }} |
| 83 | namespace: {{ $saNamespace }} |
| 84 | labels: |
| 85 | {{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }} |
| 86 | rules: |
| 87 | - apiGroups: |
| 88 | - "" |
| 89 | - extensions |
| 90 | - batch |
| 91 | - apps |
| 92 | verbs: |
| 93 | - get |
| 94 | - list |
| 95 | - patch |
| 96 | resources: |
| 97 | - statefulsets |
| 98 | - daemonsets |
| 99 | - jobs |
| 100 | - pods |
| 101 | - services |
| 102 | - endpoints |
| 103 | - configmaps |
| 104 | {{- end -}} |