apiVersion: apps/v1
kind: Deployment
metadata:
  name: config-deployer
  labels:
    app: flux
  namespace: bookinfo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flux
  template:
    metadata:
      labels:
        app: flux
    spec:        
      serviceAccountName: bookinfo
      containers:
      - name: hooktainer
        image: 'gcr.io/gke-istio-test-psb/tctl:1.4.0-try'
        imagePullPolicy: Always
        volumeMounts:
        - name: foo
          mountPath: "/etc/foo"
          readOnly: true
        command: ['sh', '-c', '--']
        args:
        - |
            sleep 5
            if [ -z  $(kubectl get svc -n tsb envoy -o jsonpath='{.status.loadBalancer.ingress[0].hostname}') ];then
            MP_ADDRESS=$(kubectl get svc -n tsb envoy -o jsonpath='{.status.loadBalancer.ingress[0].ip}');else
            MP_ADDRESS=$(kubectl get svc -n tsb envoy -o jsonpath='{.status.loadBalancer.ingress[0].hostname}');fi
            echo $MP_ADDRESS
            tctl config clusters set default --bridge-address ${MP_ADDRESS}:8443 --tls-insecure
            TCTL_LOGIN_ORG=tetrate TCTL_LOGIN_TENANT=tetrate TCTL_LOGIN_USERNAME=admin TCTL_LOGIN_PASSWORD=admin tctl login
            tctl apply -f /etc/foo/config.yaml
            sleep infinity
      restartPolicy: Always
      volumes:
      - name: foo
        configMap:
          name: example-configmap-1
