Concurrency-Issue /Event-Loss while deploying multiple CR of same group using Helm Chart
shreegithub opened this issue · 0 comments
Expected behavior (what you expected to happen):
We have usecases to create Kafka topic on AWS MSK on the fly when any application is deployed within Kubernetes Cluster.
We have written one CR/CRD((Api Group "kafka.abc.io")) having the details of topic information. This CR is deployed as part of the application deployment as Helm Chart.
We have written one hook in operator to listen this CR and do appropriate action to create/update topic based on captured Events(Add/Modify).
When Helm chart deploy multiple CR of same Api Group("kafka.abc.io") then shell-operator should capture all the events for the CR added to the cluster.
Actual behavior (what actually happened):
shell-operator is able to capture "Add" Event of only one CR. Other "Add" Events of different CR are being losses because all the CR are added into K8s cluster at same timestamp by Helm Chart
Steps to reproduce:
Apply the below CR using helm chart :
apiVersion: "kafka.abc.io/v1"
kind: topics
metadata:
name: topics-1
namespace: test
spec:
topicName: "kafka-topic1"
sharedTopicDep: false
---
apiVersion: "kafka.abc.io/v1"
kind: topics
metadata:
name: topics-2
namespace: test
spec:
topicName: "kafka-topic2"
sharedTopicDep: false
Environment:
- Shell-operator version: latest
- Kubernetes version: 1.28
- Installation type (kubectl apply, helm chart, etc.): Kubectl apply
Anything else we should know?:
Is there any solution to capture the events which got missed due to concurrency?
Script
#!/usr/bin/env bashif [[ $1 == "--config" ]] ; then
cat <<EOF
{
"configVersion":"v1",
"kubernetes":[{
"apiVersion": "kafka.abc.io/v1",
"kind": "topics",
"executeHookOnEvent":["Added"]
}]
}
EOF
else
type=$(jq -r '.[0].type' ${BINDING_CONTEXT_PATH})if [[ $type == "Event" ]] ; then
echo "${BINDING_CONTEXT_PATH} @@@@@@@@@@@@@@@@@@@@@@@@@@"
name=$(jq -r '.[0].object.metadata.name' ${BINDING_CONTEXT_PATH})
kind=$(jq -r '.[0].object.kind' ${BINDING_CONTEXT_PATH})
echo "${kind}/${name} object is added ###################"
fifi
Logs
{"binding":"kubernetes","event":"kubernetes","hook":"cr-create-call-topic.sh","level":"info","msg":"Execute hook","queue":"main","task":"HookRun","time":"2024-07-23T11:18:25Z"} {"binding":"kubernetes","event":"kubernetes","hook":"cr-create-call-topic.sh","level":"info","msg":"/tmp/shell-operator/hook-cr-create-call-topic-sh-binding-context-7a6cdaad-b1a9-4206-977f-8300fe3d456b.json @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@","output":"stdout","queue":"main","task":"HookRun","time":"2024-07-23T11:18:25Z"} {"binding":"kubernetes","event":"kubernetes","hook":"cr-create-call-topic.sh","level":"info","msg":"topics/topics-1 object is added ###################","output":"stdout","queue":"main","task":"HookRun","time":"2024-07-23T11:18:25Z"}