Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 1 | {{- /* |
Jeremy Ronquillo | ec2d3e4 | 2020-06-05 11:33:39 -0700 | [diff] [blame] | 2 | |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 3 | # Copyright 2018 Intel Corporation |
Jeremy Ronquillo | ec2d3e4 | 2020-06-05 11:33:39 -0700 | [diff] [blame] | 4 | # Copyright 2018-present Open Networking Foundation |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 5 | # |
Jeremy Ronquillo | ec2d3e4 | 2020-06-05 11:33:39 -0700 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 |
Jeremy Ronquillo | 6046ce3 | 2020-06-18 11:06:29 -0700 | [diff] [blame] | 7 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
Jeremy Ronquillo | ec2d3e4 | 2020-06-05 11:33:39 -0700 | [diff] [blame] | 8 | |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 9 | */ -}} |
| 10 | |
| 11 | {{/* |
| 12 | Renders a set of standardised labels |
| 13 | */}} |
| 14 | {{- define "omec-control-plane.metadata_labels" -}} |
| 15 | {{- $application := index . 0 -}} |
| 16 | {{- $context := index . 1 -}} |
| 17 | release: {{ $context.Release.Name }} |
| 18 | app: {{ $application }} |
| 19 | {{- end -}} |
| 20 | |
| 21 | {{/* |
| 22 | Render the given template. |
| 23 | */}} |
| 24 | {{- define "omec-control-plane.template" -}} |
| 25 | {{- $name := index . 0 -}} |
| 26 | {{- $context := index . 1 -}} |
| 27 | {{- $last := base $context.Template.Name }} |
| 28 | {{- $wtf := $context.Template.Name | replace $last $name -}} |
| 29 | {{ include $wtf $context }} |
| 30 | {{- end -}} |
| 31 | |
| 32 | {{/* |
| 33 | Return domain name for Diameter identity, realm, and hostname for a given application. |
| 34 | */}} |
| 35 | {{- define "omec-control-plane.diameter_endpoint" -}} |
| 36 | {{- $service := index . 0 -}} |
| 37 | {{- $type := index . 1 -}} |
| 38 | {{- $context := index . 2 -}} |
| 39 | {{- if eq $type "identity" -}} |
| 40 | {{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}} |
| 41 | {{- else if eq $type "realm" -}} |
| 42 | {{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}} |
| 43 | {{- else if eq $type "host" -}} |
| 44 | {{- printf "%s" $service -}} |
| 45 | {{- end -}} |
| 46 | {{- end -}} |
| 47 | |
| 48 | {{/* |
| 49 | Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint. |
| 50 | */}} |
| 51 | {{- define "omec-control-plane.service_account" -}} |
| 52 | {{- $context := index . 1 -}} |
| 53 | {{- $saName := index . 0 -}} |
| 54 | {{- $saNamespace := $context.Release.Namespace }} |
| 55 | --- |
| 56 | apiVersion: v1 |
| 57 | kind: ServiceAccount |
| 58 | metadata: |
| 59 | name: {{ $saName }} |
| 60 | namespace: {{ $saNamespace }} |
| 61 | labels: |
| 62 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 63 | --- |
Hyunsun Moon | d457d18 | 2020-09-10 15:52:09 -0700 | [diff] [blame] | 64 | {{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }} |
| 65 | apiVersion: rbac.authorization.k8s.io/v1 |
| 66 | {{- else }} |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 67 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
Hyunsun Moon | d457d18 | 2020-09-10 15:52:09 -0700 | [diff] [blame] | 68 | {{- end }} |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 69 | kind: RoleBinding |
| 70 | metadata: |
| 71 | name: {{ $saName }} |
| 72 | namespace: {{ $saNamespace }} |
| 73 | labels: |
| 74 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 75 | roleRef: |
| 76 | apiGroup: rbac.authorization.k8s.io |
| 77 | kind: Role |
| 78 | name: {{ $saName }} |
| 79 | subjects: |
| 80 | - kind: ServiceAccount |
| 81 | name: {{ $saName }} |
| 82 | namespace: {{ $saNamespace }} |
| 83 | --- |
Hyunsun Moon | d457d18 | 2020-09-10 15:52:09 -0700 | [diff] [blame] | 84 | {{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }} |
| 85 | apiVersion: rbac.authorization.k8s.io/v1 |
| 86 | {{- else }} |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 87 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
Hyunsun Moon | d457d18 | 2020-09-10 15:52:09 -0700 | [diff] [blame] | 88 | {{- end }} |
Jeremy Ronquillo | 223db00 | 2020-06-05 10:28:22 -0700 | [diff] [blame] | 89 | kind: Role |
| 90 | metadata: |
| 91 | name: {{ $saName }} |
| 92 | namespace: {{ $saNamespace }} |
| 93 | labels: |
| 94 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 95 | rules: |
| 96 | - apiGroups: |
| 97 | - "" |
| 98 | - extensions |
| 99 | - batch |
| 100 | - apps |
| 101 | verbs: |
| 102 | - get |
| 103 | - list |
| 104 | - patch |
| 105 | resources: |
| 106 | - statefulsets |
| 107 | - daemonsets |
| 108 | - jobs |
| 109 | - pods |
| 110 | - services |
| 111 | - endpoints |
| 112 | - configmaps |
| 113 | {{- end -}} |
| 114 | |
| 115 | {{/* |
| 116 | Render init container for coredump. |
| 117 | */}} |
| 118 | {{- define "omec-control-plane.coredump_init" -}} |
| 119 | {{- $pod := index . 0 -}} |
| 120 | {{- $context := index . 1 -}} |
| 121 | - name: {{ $pod }}-coredump-init |
| 122 | image: {{ $context.Values.images.tags.init | quote }} |
| 123 | imagePullPolicy: {{ $context.Values.images.pullPolicy }} |
| 124 | securityContext: |
| 125 | privileged: true |
| 126 | runAsUser: 0 |
| 127 | command: ["bash", "-xc"] |
| 128 | args: |
| 129 | - echo '/tmp/coredump/core.%h.%e.%t' > /mnt/host-rootfs/proc/sys/kernel/core_pattern |
| 130 | volumeMounts: |
| 131 | - name: host-rootfs |
| 132 | mountPath: /mnt/host-rootfs |
| 133 | {{- end -}} |