Skip to content

Commit 124676a

Browse files
committed
working bash script to add quotas
1 parent 5933244 commit 124676a

File tree

11 files changed

+92
-96
lines changed

11 files changed

+92
-96
lines changed

stable/quotas/confluent/kafka.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

stable/quotas/docker/Dockerfile

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
FROM rockylinux/rockylinux:8.5
2-
3-
ENV container docker
4-
5-
# 1. Adding Confluent repository
6-
RUN rpm --import https://packages.confluent.io/rpm/7.1/archive.key
7-
COPY confluent.repo /etc/yum.repos.d/confluent.repo
8-
RUN yum clean all
9-
10-
# 2. Install Confluent Kafka stack
11-
RUN yum install -y java-1.8.0-openjdk
12-
RUN yum install -y confluent-kafka
13-
14-
# 3. Install JY YAML parser for shell
15-
RUN yum install -y jq
1+
FROM confluentinc/cp-kafka:latest
2+
USER root
3+
RUN yum install -y jq vim vi
164
RUN curl -L -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/`curl -s https://api.github.com/repos/mikefarah/yq/releases/latest | jq .tag_name | sed 's/"//g'`/yq_linux_amd64
17-
RUN chmod 755 /usr/local/bin/yq
5+
RUN chmod +x /usr/local/bin/yq
6+
USER appuser
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
eval $(minikube docker-env)
3-
docker build -t sandbox-kafka-client .
3+
docker build -t quota-manager .

stable/quotas/docker/confluent.repo

Lines changed: 0 additions & 13 deletions
This file was deleted.

stable/quotas/kustomization.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ namespace: sandbox
44
resources:
55
- namespace.yaml
66
- ../../base/cfk-components/confluent-rbac
7-
- client
8-
patchesStrategicMerge:
9-
- confluent/kafka.yaml
7+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
quota_definition="/tmp/quota-definition/quotas.yaml"
4+
5+
for i in $(yq '.platform.quotas | keys' < $quota_definition); do
6+
principal="${i:0}"
7+
if [[ "$principal" != "-" ]]; then
8+
producer_byte_rate=$(yq ".platform.quotas.$principal.producer_byte_rate" < $quota_definition)
9+
consumer_byte_rate=$(yq ".platform.quotas.$principal.consumer_byte_rate" < $quota_definition)
10+
request_percentage=$(yq ".platform.quotas.$principal.request_percentage" < $quota_definition)
11+
config_string=""
12+
if [[ "$producer_byte_rate" != "null" ]]; then
13+
config_string="$config_string producer_byte_rate=$producer_byte_rate,"
14+
fi
15+
if [[ "$consumer_byte_rate" != "null" ]]; then
16+
config_string="$config_string consumer_byte_rate=$consumer_byte_rate,"
17+
fi
18+
if [[ "$request_percentage" != "null" ]]; then
19+
config_string="$config_string request_percentage=$request_percentage,"
20+
fi
21+
# Removes white space and the last trailing comma
22+
config=$(echo $config_string | tr -d " \t\n\r" | rev | cut -c 2- | rev)
23+
set -x
24+
echo $config
25+
26+
kafka-configs \
27+
--bootstrap-server kafka:9071 \
28+
--alter \
29+
--entity-type users \
30+
--entity-name $principal \
31+
--command-config /tmp/config-properties/kafka.properties \
32+
--add-config "$config"
33+
set +x
34+
fi
35+
done
36+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bootstrap.servers=kafka:9071
2+
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username=kafka password=kafka-secret;
3+
sasl.mechanism=PLAIN
4+
security.protocol=SASL_SSL
5+
ssl.truststore.location=/mnt/sslcerts/truststore.jks
6+
ssl.truststore.password=mystorepassword
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
platform:
3+
quotas:
4+
app-0:
5+
producer_byte_rate: 1024
6+
consumer_byte_rate: 1024
7+
request_percentage: 50.0
8+
app-2:
9+
producer_byte_rate: 2048
10+
consumer_byte_rate: 2048
11+
app-3:
12+
request_percentage: 80.0

stable/quotas/quota-manager/demo-topic.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
namespace: sandbox
22
resources:
3-
- demo-topic.yaml
4-
- quota-manager.yaml
3+
- quota-manager.yaml
4+
configMapGenerator:
5+
- name: oso-quota-example
6+
files:
7+
- ./definition/quotas.yaml
8+
- name: config-properties
9+
files:
10+
- ./definition/kafka.properties
11+
- name: apply-quota-script
12+
files:
13+
- ./definition/apply-quotas-script.sh
14+
generatorOptions:
15+
disableNameSuffixHash: true

0 commit comments

Comments
 (0)