apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-kafka-connect
  namespace: kafka-connect
  labels:
    app: kafka-connect
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-connect
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: kafka-connect
    spec:
      initContainers:
        - name: app-wait-kakfa
          image: busybox
          command:
            - /bin/sh
            - -c
            - 'until [ "1" = "$(echo dump | nc -v app-zookeeper.zookeeper.svc.cluster.local 32181 | grep brokers | wc -l)" ] ; do echo waiting for zookeeper ; sleep 1 ; done'
          env:
            - name: SERVICE_TYPE
              value: "init"
      containers:
        - image: davidescus/kafka-connector-source-mysql
          name: kafka-connect-app
          env:
            - name: CONNECT_BOOTSTRAP_SERVERS
              value: "app-kafka.kafka.svc.cluster.local:29092"
            - name: CONNECT_REST_PORT
              value: "28083"
            - name: CONNECT_GROUP_ID
              value: "quickstart-avro"
            - name: CONNECT_CONFIG_STORAGE_TOPIC
              value: "quickstart-avro-config"
            - name: CONNECT_OFFSET_STORAGE_TOPIC
              value: "quickstart-avro-offsets"
            - name: CONNECT_STATUS_STORAGE_TOPIC
              value: "quickstart-avro-status"
            - name: CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR
              value: "1"
            - name: CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR
              value: "1"
            - name: CONNECT_STATUS_STORAGE_REPLICATION_FACTOR
              value: "1"
            - name: CONNECT_KEY_CONVERTER
              value: "io.confluent.connect.avro.AvroConverter"
            - name: CONNECT_VALUE_CONVERTER
              value: "io.confluent.connect.avro.AvroConverter"
            - name: CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL
              value: "http://localhost:8081"
            - name: CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL
              value: "http://localhost:8081"
            - name: CONNECT_INTERNAL_KEY_CONVERTER
              value: "org.apache.kafka.connect.json.JsonConverter"
            - name: CONNECT_INTERNAL_VALUE_CONVERTER
              value: "org.apache.kafka.connect.json.JsonConverter"
            - name: CONNECT_REST_ADVERTISED_HOST_NAME
              value: "localhost"
            - name: CONNECT_LOG4J_ROOT_LOGLEVEL
              value: "INFO"
            - name: CONNECT_PLUGIN_PATH
              value: /usr/share/java,/etc/kafka-connect/jars
          ports:
            - containerPort: 28083
              name: kafka-connect
        - image: confluentinc/cp-schema-registry:5.0.0
          name: schema-registry-app
          env:
            - name: SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL
              value: "app-zookeeper.zookeeper.svc.cluster.local:32181"
            - name: SCHEMA_REGISTRY_HOST_NAME
              value: "localhost"
            - name: SCHEMA_REGISTRY_LISTENERS
              value: "http://localhost:8081"
          ports:
            - containerPort: 8081
              name: schema-registry
