blob: c7d47312792cf5e22050fd274cc7905f23f8a80c [file] [log] [blame]
Woojoong Kim676bbac2021-01-15 12:00:33 -08001{{- /*
2
3# Copyright 2020-present Open Networking Foundation
4#
5# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
6
7*/ -}}
8
9{{/*
10Renders a set of standardised labels.
11*/}}
12{{- define "ros-core.metadata_labels" -}}
13{{- $application := index . 0 -}}
14{{- $context := index . 1 -}}
15release: {{ $context.Release.Name }}
16app: {{ $application }}
17{{- end -}}
18
19{{/*
20Render the given template.
21*/}}
22{{- define "ros-core.template" -}}
23{{- $name := index . 0 -}}
24{{- $context := index . 1 -}}
25{{- $last := base $context.Template.Name }}
26{{- $wtf := $context.Template.Name | replace $last $name -}}
27{{ include $wtf $context }}
28{{- end -}}
Woojoong Kim4f5cf182021-01-31 00:09:54 -080029
30{{/*
31Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint.
32*/}}
33{{- define "ros-core.service_account" -}}
34{{- $context := index . 1 -}}
35{{- $saName := index . 0 -}}
36{{- $saNamespace := $context.Release.Namespace }}
37---
38apiVersion: v1
39kind: ServiceAccount
40metadata:
41 name: {{ $saName }}
42 namespace: {{ $saNamespace }}
43 labels:
44{{ tuple $saName $context | include "ros-core.metadata_labels" | indent 4 }}
45---
46{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
47apiVersion: rbac.authorization.k8s.io/v1
48{{- else }}
49apiVersion: rbac.authorization.k8s.io/v1beta1
50{{- end }}
51kind: RoleBinding
52metadata:
53 name: {{ $saName }}
54 namespace: {{ $saNamespace }}
55 labels:
56{{ tuple $saName $context | include "ros-core.metadata_labels" | indent 4 }}
57roleRef:
58 apiGroup: rbac.authorization.k8s.io
59 kind: Role
60 name: {{ $saName }}
61subjects:
62 - kind: ServiceAccount
63 name: {{ $saName }}
64 namespace: {{ $saNamespace }}
65---
66{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
67apiVersion: rbac.authorization.k8s.io/v1
68{{- else }}
69apiVersion: rbac.authorization.k8s.io/v1beta1
70{{- end }}
71kind: Role
72metadata:
73 name: {{ $saName }}
74 namespace: {{ $saNamespace }}
75 labels:
76{{ tuple $saName $context | include "ros-core.metadata_labels" | indent 4 }}
77rules:
78 - apiGroups:
79 - ""
80 - extensions
81 - batch
82 - apps
83 verbs:
84 - get
85 - list
86 - patch
87 resources:
88 - statefulsets
89 - daemonsets
90 - jobs
91 - pods
92 - services
93 - endpoints
94 - configmaps
95{{- end -}}