---
apiVersion: batch/v1
kind: Job
metadata:
  name: sync-check
  namespace: default
  annotations:
    kapp.k14s.io/nonce: ""
    kapp.k14s.io/update-strategy: fallback-on-replace
    kapp.k14s.io/change-rule: "upsert after upserting redis-master"
    kapp.k14s.io/change-rule.1: "upsert after upserting redis-slave"
spec:
  backoffLimit: 0
  activeDeadlineSeconds: 30
  template:
    metadata:
      name: sync-check
      annotations:
        kapp.k14s.io/deploy-logs: ""
    spec:
      containers:
      - name: sync-check
        image: redis
        command:
        - /bin/sh
        - -exc
        - |
          master="-h redis-master -p 6379"
          slave="-h redis-slave -p 6379"

          redis-cli $master ping 2>&1
          redis-cli $slave ping 2>&1
          redis-cli $slave info 2>&1 | grep -A10 Replication

          redis-cli $master set key val 2>&1
          sleep 2
          redis-cli $slave get key 2>&1
          result=$(redis-cli $slave get key 2>&1)

          if [ "x$result" != "xval" ]; then
            echo "Expected slave to be synced to master"
            exit 1
          fi
      restartPolicy: Never
