# Source: cp-helm-charts/charts/cp-kafka/templates/tests/canary-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "cp-helm-charts-canary"
  annotations:
    "helm.sh/hook": test-success
    "helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
    meta.helm.sh/release-name: 'cp-helm-charts'
  namespace: kafka
  labels:
    gitops.jenkins-x.io/pipeline: 'namespaces'
spec:
  containers:
    - name: cp-helm-charts-canary
      image: "confluentinc/cp-enterprise-kafka:6.0.1"
      imagePullPolicy: "IfNotPresent"
      command:
        - sh
        - -c
        - |
          # Delete the topic if it exists
          kafka-topics --zookeeper cp-helm-charts-cp-zookeeper-headless:2181 --topic cp-helm-charts-cp-kafka-canary-topic --delete --if-exists
          # Create the topic
          kafka-topics --zookeeper cp-helm-charts-cp-zookeeper-headless:2181 --topic cp-helm-charts-cp-kafka-canary-topic --create --partitions 1 --replication-factor 1 --if-not-exists && \
          # Create a message
          MESSAGE="`date -u`" && \
          # Produce a test message to the topic
          echo "$MESSAGE" | kafka-console-producer --broker-list cp-helm-charts-cp-kafka:9092 --topic cp-helm-charts-cp-kafka-canary-topic && \
          # Consume a test message from the topic
          kafka-console-consumer --bootstrap-server cp-helm-charts-cp-kafka-headless:9092 --topic cp-helm-charts-cp-kafka-canary-topic --from-beginning --timeout-ms 2000 | grep "$MESSAGE"
  restartPolicy: Never
