Skip to content

Commit 4aa3b18

Browse files
authored
Merge pull request #582 from mhrivnak/ansible-tests
Adds integration tests for ansible operator
2 parents 1579fe2 + 623edd4 commit 4aa3b18

File tree

15 files changed

+284
-25
lines changed

15 files changed

+284
-25
lines changed

.travis.yml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,30 @@ jobs:
1414
env:
1515
- CLUSTER=minikube
1616
- CHANGE_MINIKUBE_NONE_USER=true
17+
script: test/test-go.sh
18+
name: Go on minikube
19+
- before_script: hack/ci/setup-minikube.sh
20+
env:
21+
- CLUSTER=minikube
22+
- CHANGE_MINIKUBE_NONE_USER=true
23+
script: test/test-ansible.sh
24+
name: Ansible on minikube
1725
- before_script: hack/ci/setup-openshift.sh
1826
env: CLUSTER=openshift
27+
script: test/test-go.sh
28+
name: Go on OpenShift
29+
- before_script: hack/ci/setup-openshift.sh
30+
env: CLUSTER=openshift
31+
script: test/test-ansible.sh
32+
name: Ansible on OpenShift
1933

2034
install:
2135
- curl -Lo dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x dep && sudo mv dep /usr/local/bin/
2236
- dep ensure
37+
- make install
2338
# Create example operator directory
2439
- mkdir -p $GOPATH/src/github.com/example-inc
25-
26-
script:
27-
- make install
28-
- go test ./commands/...
29-
- go test ./pkg/...
30-
- go test ./test/e2e/...
31-
- cd test/test-framework
32-
# test framework with defaults
33-
- operator-sdk test local .
34-
# test operator-sdk test flags
35-
- operator-sdk test local . --global-manifest deploy/crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $HOME/.kube/config
36-
# test operator-sdk test local single namespace mode
37-
- kubectl create namespace test-memcached
38-
- operator-sdk test local . --namespace=test-memcached
39-
- kubectl delete namespace test-memcached
40-
# go back to project root
41-
- cd ../..
42-
- go vet ./...
43-
- ./hack/check_license.sh
44-
- ./hack/check_error_case.sh
45-
# Make sure repo is in clean state
46-
- git diff --exit-code
40+
- sudo pip install ansible
4741

4842
after_success:
4943
- echo 'Build succeeded, operator was generated, memcached operator is running on $CLUSTER, and unit/integration tests pass'

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/ci/setup-minikube.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Download kubectl, which is a requirement for using minikube.
2-
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.10.1/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
2+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.11.3/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
33
# Download minikube.
44
# We need to pin to an old version due to minikube requiring systemd starting with v0.26.0 and travis not providing it
55
# - https://github.com/kubernetes/minikube/issues/2704

hack/ci/setup-openshift.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ oc cluster up
1111
# Become cluster admin
1212
oc login -u system:admin
1313

14-
# kubectl is needed for the single namespace local test
15-
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.10.1/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
14+
# kubectl is needed for the single namespace local test and the ansible tests
15+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.11.3/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
size: 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- debug:
2+
msg: "this is a finalizer"

test/ansible-memcached/tasks.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
- name: start memcached
3+
k8s:
4+
definition:
5+
kind: Deployment
6+
apiVersion: apps/v1
7+
metadata:
8+
name: '{{ meta.name }}-memcached'
9+
namespace: '{{ meta.namespace }}'
10+
labels:
11+
app: memcached
12+
spec:
13+
replicas: "{{size}}"
14+
selector:
15+
matchLabels:
16+
app: memcached
17+
template:
18+
metadata:
19+
labels:
20+
app: memcached
21+
spec:
22+
containers:
23+
- name: memcached
24+
command:
25+
- memcached
26+
- -m=64
27+
- -o
28+
- modern
29+
- -v
30+
image: "docker.io/memcached:1.4.36-alpine"
31+
ports:
32+
- containerPort: 11211
33+
readinessProbe:
34+
tcpSocket:
35+
port: 11211
36+
initialDelaySeconds: 3
37+
periodSeconds: 3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
finalizer:
2+
name: finalizer.ansible.example.com
3+
role: /opt/ansible/roles/memfin

test/ansible-operator/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ansible/ansible-runner
2+
3+
RUN pip install --upgrade setuptools
4+
RUN pip install openshift ansible-runner-http
5+
6+
RUN echo "localhost ansible_connection=local" > /etc/ansible/hosts \
7+
&& echo '[defaults]' > /etc/ansible/ansible.cfg \
8+
&& echo 'roles_path = /opt/ansible/roles' >> /etc/ansible/ansible.cfg \
9+
&& echo 'library = /usr/share/ansible/openshift' >> /etc/ansible/ansible.cfg
10+
11+
ENV OPERATOR=/usr/local/bin/ansible-operator \
12+
USER_UID=1001 \
13+
USER_NAME=ansible-operator\
14+
HOME=/opt/ansible
15+
16+
# install operator binary
17+
ADD ansible-operator ${OPERATOR}
18+
19+
COPY bin /usr/local/bin
20+
RUN /usr/local/bin/user_setup
21+
22+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
23+
24+
USER ${USER_UID}

test/ansible-operator/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory temporarily holds the artifacts that are required to build the
2+
ansible operator base image, until they find a more permanent home.

0 commit comments

Comments
 (0)