github.com/jmrodri/operator-sdk@v0.5.0/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  # Test cluster
    49  DEST_IMAGE="quay.io/example/memcached-operator:v0.0.2-test"
    50  operator-sdk build --enable-tests "$DEST_IMAGE"
    51  trap_add 'remove_prereqs' EXIT
    52  deploy_prereqs
    53  operator-sdk test cluster --image-pull-policy Never --namespace default --service-account memcached-operator ${DEST_IMAGE}
    54  
    55  remove_prereqs
    56  
    57  popd
    58  popd
    59  
    60  pushd "${ROOTDIR}/test/ansible-inventory"
    61  
    62  sed -i 's|\(FROM quay.io/operator-framework/ansible-operator\)\(:.*\)\?|\1:dev|g' build/Dockerfile
    63  TEST_CLUSTER_PORT=24443 operator-sdk test local --namespace default
    64  
    65  popd