Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / common / templates / _strimzikafka.tpl
1 {{/*
2 # Copyright © 2022 Nordix 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   Create a Strimzi KafkaUser.
19   Usage:
20       include "common.kafkauser" .
21
22   Strimzi kafka provides cluster access via its custom resource definition KafkaUser
23   which is deployed using its User Operator component.
24   See more info here - https://github.com/strimzi/strimzi-kafka-operator/blob/main/helm-charts/helm3/strimzi-kafka-operator/crds/044-Crd-kafkauser.yaml
25   This allows fine grained access control per user towards the kafka cluster.
26   See more info here - https://strimzi.io/docs/operators/latest/configuring.html#proc-configuring-kafka-user-str
27
28   The kafka user definition is defined as part of .Values per component.
29   For general use by OOM components, the following list of acl types should suffice:
30        type: group (Used by the client app to be added to a particular kafka consumer group)
31        type: topic (1 or more kafka topics that the client needs to access. Commonly [Read,Write])
32
33   Note: The template will use the following default values.
34
35     spec.authentication.type: scram-sha-512 (dictated by the available broker listeners on the kafka cluster)
36     spec.authorization.type: simple (Only type supported by strimzi at present)
37     spec.authorization.acls.resource.patternType: literal
38
39   Example:
40
41   kafkaUser:
42     acls:
43       - name: sdc (mandatory)
44         suffix: mysuffix (optional. Will be appended (with a hyphen) to the "name" entry. ie "sdc-mysuffix")
45         type: group (mandatory. Type "group" is used by the client as it's kafka consumer group)
46         operations: [Read] (mandatory. List of at least 1)
47       - name: SDC-DISTR
48         type: topic
49         patternType: prefix (optional. In this example, the user will be provided Read and Write access to all topics named "SDC-DISTR*")
50         operations: [Read, Write]
51 */}}
52 {{- define "common.kafkauser" -}}
53 {{- $global := .global }}
54 apiVersion: kafka.strimzi.io/v1beta2
55 kind: KafkaUser
56 metadata:
57   name: {{ include "common.name" . }}-ku
58   labels:
59     strimzi.io/cluster: {{ include "common.release" . }}-strimzi
60 spec:
61   authentication:
62     type: {{ .Values.kafkaUser.authenticationType | default "scram-sha-512" }}
63   authorization:
64     type: {{ .Values.kafkaUser.authorizationType | default "simple" }}
65     acls:
66       {{- range $acl := .Values.kafkaUser.acls }}
67       - resource:
68           type: {{ $acl.type }}
69           patternType: {{ $acl.patternType | default "literal" }}
70           name: {{ ternary (printf "%s-%s" $acl.name $acl.suffix) $acl.name (hasKey $acl "suffix") }}
71         operations:
72         {{- range $operation := $acl.operations }}
73           - {{ . }}
74         {{- end }}
75       {{- end }}
76 {{- end -}}
77
78 {{/*
79   Create a Strimzi KafkaTopic.
80   Usage:
81       include "common.kafkatopic" .
82
83   Strimzi kafka provides kafka topic management via its custom resource definition KafkaTopic
84   which is deployed using its Topic Operator component.
85   See more info here - https://github.com/strimzi/strimzi-kafka-operator/blob/main/helm-charts/helm3/strimzi-kafka-operator/crds/043-Crd-kafkatopic.yaml
86
87   Note: KafkaTopic names should adhere to kubernetes object naming conventions - https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
88         maximum length of 253 characters and consist of lower case alphanumeric characters, -, and .
89
90   Note: The template will use the following default values.
91
92     spec.config.retention.ms: 7200000 (defaults to 2 hrs retention for kafka topic logs)
93     spec.config.segment.bytes: 1073741824 (defaults to 1gb)
94     spec.partitions: 6 (defaults to (2 * (default.replication.factor)) defined by the strimzi broker conf)
95     spec.replicas: 3 (defaults to default.replication.factor defined by the strimzi broker conf. Must be > 0 and <= (num of broker replicas))
96
97   The kafka topic definition is defined as part of .Values per component.
98
99   Example:
100
101   kafkaTopic:
102     - name: my-new-topic (mandatory)
103       retentionMs: 7200000 (optional. Defaults to 2hrs)
104       segmentBytes: 1073741824 (optional. Defaults to 1gb)
105       suffix: my-suffix (optional. Will be appended (with a hyphen) to the "name" value. ie "my-new-topic-my-suffix")
106     - name: my.other.topic
107       suffix: some.other-suffix
108 */}}
109 {{- define "common.kafkatopic" -}}
110 {{- $global := .global }}
111 {{- range $topic := .Values.kafkaTopic }}
112 apiVersion: kafka.strimzi.io/v1beta2
113 kind: KafkaTopic
114 metadata:
115   {{- if (hasKey $topic "strimziTopicName") }}
116   name: {{ ($topic.strimziTopicName) }}-kt
117   {{- else }}
118   name: {{ ($topic.name) | lower }}-kt
119   {{- end }}
120   labels:
121     strimzi.io/cluster: {{ include "common.release" $ }}-strimzi
122 spec:
123   {{- if (hasKey $topic "partitions") }}
124   partitions: {{ $topic.partitions }}
125   {{- end }}
126   {{- if (hasKey $topic "replicas") }}
127   replicas: {{ $topic.replicas }}
128   {{- end }}
129   topicName: {{ ternary (printf "%s-%s" $topic.name $topic.suffix) $topic.name (hasKey $topic "suffix") }}
130   config:
131     retention.ms: {{ $topic.retentionMs | default "7200000" }}
132     segment.bytes: {{ $topic.segmentBytes | default "1073741824"}}
133 ---
134 {{- end }}
135 {{- end -}}