github.skymusic.top/operator-framework/operator-sdk@v0.8.2/hack/tests/e2e-ansible-molecule.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  source hack/lib/test_lib.sh
     4  
     5  set -eux
     6  
     7  ROOTDIR="$(pwd)"
     8  GOTMP="$(mktemp -d -p $GOPATH/src)"
     9  trap_add 'rm -rf $GOTMP' EXIT
    10  # Needs to be from source until 2.20 comes out
    11  pip install --user git+https://github.com/ansible/molecule.git
    12  pip install --user docker openshift jmespath
    13  
    14  deploy_prereqs() {
    15      kubectl create -f "$OPERATORDIR/deploy/service_account.yaml"
    16      kubectl create -f "$OPERATORDIR/deploy/role.yaml"
    17      kubectl create -f "$OPERATORDIR/deploy/role_binding.yaml"
    18      kubectl create -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_memcached_crd.yaml"
    19  }
    20  
    21  remove_prereqs() {
    22      kubectl delete --ignore-not-found=true -f "$OPERATORDIR/deploy/service_account.yaml"
    23      kubectl delete --ignore-not-found=true -f "$OPERATORDIR/deploy/role.yaml"
    24      kubectl delete --ignore-not-found=true -f "$OPERATORDIR/deploy/role_binding.yaml"
    25      kubectl delete --ignore-not-found=true -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_memcached_crd.yaml"
    26  }
    27  
    28  pushd "$GOTMP"
    29  operator-sdk new memcached-operator --api-version=ansible.example.com/v1alpha1 --kind=Memcached --type=ansible --generate-playbook
    30  cp "$ROOTDIR/test/ansible-memcached/tasks.yml" memcached-operator/roles/memcached/tasks/main.yml
    31  cp "$ROOTDIR/test/ansible-memcached/defaults.yml" memcached-operator/roles/memcached/defaults/main.yml
    32  cp "$ROOTDIR/test/ansible-memcached/asserts.yml"  memcached-operator/molecule/default/asserts.yml
    33  cp "$ROOTDIR/test/ansible-memcached/molecule.yml"  memcached-operator/molecule/test-local/molecule.yml
    34  cp -a "$ROOTDIR/test/ansible-memcached/memfin" memcached-operator/roles/
    35  cp -a "$ROOTDIR/test/ansible-memcached/secret" memcached-operator/roles/
    36  cat "$ROOTDIR/test/ansible-memcached/watches-finalizer.yaml" >> memcached-operator/watches.yaml
    37  cat "$ROOTDIR/test/ansible-memcached/prepare-test-image.yml" >> memcached-operator/molecule/test-local/prepare.yml
    38  # Append v1 kind to watches to test watching already registered GVK
    39  cat "$ROOTDIR/test/ansible-memcached/watches-v1-kind.yaml" >> memcached-operator/watches.yaml
    40  
    41  
    42  # Test local
    43  pushd memcached-operator
    44  sed -i 's|\(FROM quay.io/operator-framework/ansible-operator\)\(:.*\)\?|\1:dev|g' build/Dockerfile
    45  OPERATORDIR="$(pwd)"
    46  TEST_CLUSTER_PORT=24443 operator-sdk test local --namespace default
    47  
    48  remove_prereqs
    49  
    50  popd
    51  popd
    52  
    53  pushd "${ROOTDIR}/test/ansible-inventory"
    54  
    55  sed -i 's|\(FROM quay.io/operator-framework/ansible-operator\)\(:.*\)\?|\1:dev|g' build/Dockerfile
    56  TEST_CLUSTER_PORT=24443 operator-sdk test local --namespace default
    57  
    58  popd