Skip to content

Commit 1a548c0

Browse files
committed
Merge branch 'master' into go-e2e-refactor
2 parents 794cb2d + b11d50e commit 1a548c0

36 files changed

+1263
-501
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ images/scorecard-proxy/scorecard-proxy
105105

106106
# Test artifacts
107107
pkg/ansible/runner/testdata/valid.yaml
108+
bin/*

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
- Remove TypeMeta declaration from the implementation of the objects [#1462](https://github.com/operator-framework/operator-sdk/pull/1462/)
1818
- Relaxed API version format check when parsing `pkg/apis` in code generators. API dir structures can now be of the format `pkg/apis/<group>/<anything>`, where `<anything>` was previously required to be in the Kubernetes version format, ex. `v1alpha1`. ([#1525](https://github.com/operator-framework/operator-sdk/pull/1525))
1919
- The SDK and operator projects will work outside of `$GOPATH/src` when using [Go modules](https://github.com/golang/go/wiki/Modules). ([#1475](https://github.com/operator-framework/operator-sdk/pull/1475))
20+
- `CreateMetricsService()` function from the metrics package accepts an array of ServicePort objects ([]v1.ServicePort) as input to create Service metrics. `CRPortName` constant is added to describe the string of custom resource port name. ([#1560](https://github.com/operator-framework/operator-sdk/pull/1560))
2021

2122
### Deprecated
2223

2324
### Removed
2425

2526
- The SDK no longer depends on a `vendor/` directory to manage dependencies *only if* using [Go modules](https://github.com/golang/go/wiki/Modules). The SDK and operator projects will only use vendoring if using `dep`, or modules and a `vendor/` dir is present. ([#1519](https://github.com/operator-framework/operator-sdk/pull/1519))
27+
- **Breaking change:** `ExposeMetricsPort` is removed and replaced with `CreateMetricsService()` function. `PrometheusPortName` constant is replaced with `OperatorPortName`. ([#1560](https://github.com/operator-framework/operator-sdk/pull/1560))
2628

2729
### Bug Fixes
2830

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ install:
5252
" \
5353
$(BUILD_PATH)
5454

55+
ci-build: build/operator-sdk-$(VERSION)-x86_64-linux-gnu ci-install
56+
57+
ci-install:
58+
mv build/operator-sdk-$(VERSION)-x86_64-linux-gnu build/operator-sdk
59+
5560
release_x86_64 := \
5661
build/operator-sdk-$(VERSION)-x86_64-linux-gnu \
5762
build/operator-sdk-$(VERSION)-x86_64-apple-darwin
@@ -120,6 +125,9 @@ test/e2e/go:
120125
test/e2e/ansible: image/build/ansible
121126
./hack/tests/e2e-ansible.sh
122127

128+
test/e2e/ansible2:
129+
./ci/tests/e2e-ansible.sh
130+
123131
test/e2e/ansible-molecule:
124132
./hack/tests/e2e-ansible-molecule.sh
125133

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The following workflow is for a new **Helm** operator:
5353

5454
Follow the steps in the [installation guide][install_guide] to learn how to install the Operator SDK CLI tool.
5555

56+
**Note:** If you are using a release version of the SDK, make sure to follow the documentation for that version. e.g.: For version 0.8.1, see docs in https://github.com/operator-framework/operator-sdk/tree/v0.8.1.
57+
5658
### Create and deploy an app-operator
5759

5860
```sh
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM osdk-builder as builder
2+
3+
RUN go run hack/image/ansible/scaffold-ansible-image.go
4+
RUN ci/tests/e2e-ansible-scaffold-hybrid.sh
5+
6+
FROM ansible/ansible-runner:1.2
7+
8+
RUN yum remove -y ansible python-idna
9+
RUN yum install -y inotify-tools && yum clean all
10+
RUN pip uninstall ansible-runner -y
11+
12+
RUN pip install --upgrade setuptools==41.0.1
13+
RUN pip install "urllib3>=1.23,<1.25"
14+
RUN pip install ansible==2.7.10 \
15+
ansible-runner==1.2 \
16+
ansible-runner-http==1.0.0 \
17+
idna==2.7 \
18+
"kubernetes>=8.0.0,<9.0.0" \
19+
openshift==0.8.8
20+
21+
RUN mkdir -p /etc/ansible \
22+
&& echo "localhost ansible_connection=local" > /etc/ansible/hosts \
23+
&& echo '[defaults]' > /etc/ansible/ansible.cfg \
24+
&& echo 'roles_path = /opt/ansible/roles' >> /etc/ansible/ansible.cfg \
25+
&& echo 'library = /usr/share/ansible/openshift' >> /etc/ansible/ansible.cfg
26+
27+
ENV OPERATOR=/usr/local/bin/ansible-operator \
28+
USER_UID=1001 \
29+
USER_NAME=ansible-operator\
30+
HOME=/opt/ansible
31+
32+
COPY --from=builder /ansible/memcached-operator/watches.yaml ${HOME}/watches.yaml
33+
34+
COPY --from=builder /ansible/memcached-operator/roles/ ${HOME}/roles/
35+
36+
# install operator binary
37+
COPY --from=builder /memcached-operator ${OPERATOR}
38+
39+
# install k8s_status Ansible Module
40+
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/library/k8s_status.py /usr/share/ansible/openshift/
41+
42+
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/bin /usr/local/bin
43+
RUN /usr/local/bin/user_setup
44+
45+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
46+
47+
USER ${USER_UID}

ci/dockerfiles/ansible-e2e.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM osdk-builder as builder
2+
3+
RUN ci/tests/e2e-ansible-scaffold.sh
4+
5+
FROM osdk-ansible
6+
7+
COPY --from=builder /ansible/memcached-operator/watches.yaml ${HOME}/watches.yaml
8+
9+
COPY --from=builder /ansible/memcached-operator/roles/ ${HOME}/roles/

ci/dockerfiles/ansible.Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM osdk-builder as builder
2+
3+
RUN go run hack/image/ansible/scaffold-ansible-image.go
4+
5+
FROM ansible/ansible-runner:1.2
6+
7+
RUN yum remove -y ansible python-idna
8+
RUN yum install -y inotify-tools && yum clean all
9+
RUN pip uninstall ansible-runner -y
10+
11+
RUN pip install --upgrade setuptools==41.0.1
12+
RUN pip install "urllib3>=1.23,<1.25"
13+
RUN pip install ansible==2.7.10 \
14+
ansible-runner==1.2 \
15+
ansible-runner-http==1.0.0 \
16+
idna==2.7 \
17+
"kubernetes>=8.0.0,<9.0.0" \
18+
openshift==0.8.8
19+
20+
RUN mkdir -p /etc/ansible \
21+
&& echo "localhost ansible_connection=local" > /etc/ansible/hosts \
22+
&& echo '[defaults]' > /etc/ansible/ansible.cfg \
23+
&& echo 'roles_path = /opt/ansible/roles' >> /etc/ansible/ansible.cfg \
24+
&& echo 'library = /usr/share/ansible/openshift' >> /etc/ansible/ansible.cfg
25+
26+
ENV OPERATOR=/usr/local/bin/ansible-operator \
27+
USER_UID=1001 \
28+
USER_NAME=ansible-operator\
29+
HOME=/opt/ansible
30+
31+
# install operator binary
32+
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/build/operator-sdk ${OPERATOR}
33+
# install k8s_status Ansible Module
34+
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/library/k8s_status.py /usr/share/ansible/openshift/
35+
36+
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/bin /usr/local/bin
37+
RUN /usr/local/bin/user_setup
38+
39+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
40+
41+
USER ${USER_UID}

ci/dockerfiles/builder.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM openshift/origin-release:golang-1.12
2+
3+
WORKDIR /go/src/github.com/operator-framework/operator-sdk
4+
# Set gopath before build and include build destination in PATH
5+
ENV GOPATH=/go PATH=/go/src/github.com/operator-framework/operator-sdk/build:$PATH
6+
7+
COPY . .
8+
9+
RUN make ci-build
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
source hack/lib/test_lib.sh
4+
5+
set -eux
6+
7+
ROOTDIR="$(pwd)"
8+
ANSIBLEDIR="/go/src/github.com/ansible-op"
9+
10+
mkdir -p $ANSIBLEDIR
11+
cd $ANSIBLEDIR
12+
13+
# create and build the operator
14+
operator-sdk new memcached-operator --api-version=ansible.example.com/v1alpha1 --kind=Memcached --type=ansible
15+
cp "$ROOTDIR/test/ansible-memcached/tasks.yml" memcached-operator/roles/memcached/tasks/main.yml
16+
cp "$ROOTDIR/test/ansible-memcached/defaults.yml" memcached-operator/roles/memcached/defaults/main.yml
17+
cp -a "$ROOTDIR/test/ansible-memcached/memfin" memcached-operator/roles/
18+
cat "$ROOTDIR/test/ansible-memcached/watches-finalizer.yaml" >> memcached-operator/watches.yaml
19+
# Append Foo kind to watches to test watching multiple Kinds
20+
cat "$ROOTDIR/test/ansible-memcached/watches-foo-kind.yaml" >> memcached-operator/watches.yaml
21+
22+
pushd memcached-operator
23+
# Add a second Kind to test watching multiple GVKs
24+
operator-sdk add crd --kind=Foo --api-version=ansible.example.com/v1alpha1
25+
26+
export GO111MODULE=on
27+
operator-sdk migrate
28+
29+
if [[ ! -e build/Dockerfile.sdkold ]];
30+
then
31+
echo FAIL the old Dockerfile should have been renamed to Dockerfile.sdkold
32+
exit 1
33+
fi
34+
35+
# Run `go build ./...` to pull down the deps specified by the scaffolded
36+
# `go.mod` file and verify dependencies build correctly.
37+
go build ./...
38+
39+
# TODO: remove go.mod file generation after PR 1566 gets merged
40+
# Use the local operator-sdk directory as the repo. To make the go toolchain
41+
# happy, the directory needs a `go.mod` file that specifies the module name,
42+
# so we need this temporary hack until we update the SDK repo itself to use
43+
# go modules.
44+
echo "module github.com/operator-framework/operator-sdk" > $ROOTDIR/go.mod
45+
go mod edit -replace=github.com/operator-framework/operator-sdk=$ROOTDIR
46+
go build ./...
47+
48+
WD="$(dirname "$(pwd)")"
49+
go build -gcflags "all=-trimpath=${WD}" -asmflags "all=-trimpath=${WD}" -o /memcached-operator github.com/ansible-op/memcached-operator/cmd/manager
50+
popd
51+
mv $ANSIBLEDIR /ansible

ci/tests/e2e-ansible-scaffold.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
source hack/lib/test_lib.sh
4+
5+
set -eux
6+
7+
ROOTDIR="$(pwd)"
8+
9+
mkdir -p /ansible
10+
cd /ansible
11+
12+
# create and build the operator
13+
operator-sdk new memcached-operator --api-version=ansible.example.com/v1alpha1 --kind=Memcached --type=ansible
14+
cp "$ROOTDIR/test/ansible-memcached/tasks.yml" memcached-operator/roles/memcached/tasks/main.yml
15+
cp "$ROOTDIR/test/ansible-memcached/defaults.yml" memcached-operator/roles/memcached/defaults/main.yml
16+
cp -a "$ROOTDIR/test/ansible-memcached/memfin" memcached-operator/roles/
17+
cat "$ROOTDIR/test/ansible-memcached/watches-finalizer.yaml" >> memcached-operator/watches.yaml
18+
# Append Foo kind to watches to test watching multiple Kinds
19+
cat "$ROOTDIR/test/ansible-memcached/watches-foo-kind.yaml" >> memcached-operator/watches.yaml

ci/tests/e2e-ansible.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env bash
2+
3+
source hack/lib/test_lib.sh
4+
5+
set -eux
6+
7+
component="osdk-ansible-e2e"
8+
eval IMAGE=$IMAGE_FORMAT
9+
component="osdk-ansible-e2e-hybrid"
10+
eval IMAGE2=$IMAGE_FORMAT
11+
ROOTDIR="$(pwd)"
12+
GOTMP="$(mktemp -d -p $GOPATH/src)"
13+
trap_add 'rm -rf $GOTMP' EXIT
14+
15+
mkdir -p $ROOTDIR/bin
16+
export PATH=$ROOTDIR/bin:$PATH
17+
18+
if ! [ -x "$(command -v kubectl)" ]; then
19+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.14.2/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl bin/
20+
fi
21+
22+
if ! [ -x "$(command -v oc)" ]; then
23+
curl -Lo oc.tar.gz https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
24+
tar xvzOf oc.tar.gz openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc > oc && chmod +x oc && mv oc bin/ && rm oc.tar.gz
25+
fi
26+
27+
oc version
28+
29+
make install
30+
31+
deploy_operator() {
32+
kubectl create -f "$OPERATORDIR/deploy/service_account.yaml"
33+
if oc api-versions | grep openshift; then
34+
oc adm policy add-cluster-role-to-user cluster-admin -z memcached-operator || :
35+
fi
36+
kubectl create -f "$OPERATORDIR/deploy/role.yaml"
37+
kubectl create -f "$OPERATORDIR/deploy/role_binding.yaml"
38+
kubectl create -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_memcached_crd.yaml"
39+
kubectl create -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_foo_crd.yaml"
40+
kubectl create -f "$OPERATORDIR/deploy/operator.yaml"
41+
}
42+
43+
remove_operator() {
44+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/service_account.yaml"
45+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/role.yaml"
46+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/role_binding.yaml"
47+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_memcached_crd.yaml"
48+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/crds/ansible_v1alpha1_foo_crd.yaml"
49+
kubectl delete --wait=true --ignore-not-found=true -f "$OPERATORDIR/deploy/operator.yaml"
50+
}
51+
52+
test_operator() {
53+
# wait for operator pod to run
54+
if ! timeout 1m kubectl rollout status deployment/memcached-operator;
55+
then
56+
echo FAIL: operator failed to run
57+
kubectl logs deployment/memcached-operator -c operator
58+
kubectl logs deployment/memcached-operator -c ansible
59+
exit 1
60+
fi
61+
62+
# create CR
63+
kubectl create -f deploy/crds/ansible_v1alpha1_memcached_cr.yaml
64+
if ! timeout 20s bash -c -- 'until kubectl get deployment -l app=memcached | grep memcached; do sleep 1; done';
65+
then
66+
echo FAIL: operator failed to create memcached Deployment
67+
kubectl logs deployment/memcached-operator -c operator
68+
kubectl logs deployment/memcached-operator -c ansible
69+
exit 1
70+
fi
71+
memcached_deployment=$(kubectl get deployment -l app=memcached -o jsonpath="{..metadata.name}")
72+
if ! timeout 1m kubectl rollout status deployment/${memcached_deployment};
73+
then
74+
echo FAIL: memcached Deployment failed rollout
75+
kubectl logs deployment/${memcached_deployment}
76+
exit 1
77+
fi
78+
79+
80+
# make a configmap that the finalizer should remove
81+
kubectl create configmap deleteme
82+
trap_add 'kubectl delete --ignore-not-found configmap deleteme' EXIT
83+
84+
kubectl delete -f ${OPERATORDIR}/deploy/crds/ansible_v1alpha1_memcached_cr.yaml --wait=true
85+
# if the finalizer did not delete the configmap...
86+
if kubectl get configmap deleteme 2> /dev/null;
87+
then
88+
echo FAIL: the finalizer did not delete the configmap
89+
kubectl logs deployment/memcached-operator -c operator
90+
kubectl logs deployment/memcached-operator -c ansible
91+
exit 1
92+
fi
93+
94+
# The deployment should get garbage collected, so we expect to fail getting the deployment.
95+
if ! timeout 20s bash -c -- "while kubectl get deployment ${memcached_deployment} 2> /dev/null; do sleep 1; done";
96+
then
97+
echo FAIL: memcached Deployment did not get garbage collected
98+
kubectl logs deployment/memcached-operator -c operator
99+
kubectl logs deployment/memcached-operator -c ansible
100+
exit 1
101+
fi
102+
103+
# Ensure that no errors appear in the log
104+
if kubectl logs deployment/memcached-operator -c operator | grep -i error;
105+
then
106+
echo FAIL: the operator log includes errors
107+
kubectl logs deployment/memcached-operator -c operator
108+
kubectl logs deployment/memcached-operator -c ansible
109+
exit 1
110+
fi
111+
}
112+
113+
# switch to the "default" namespace
114+
oc project default
115+
116+
# create and build the operator
117+
pushd "$GOTMP"
118+
operator-sdk new memcached-operator --api-version=ansible.example.com/v1alpha1 --kind=Memcached --type=ansible
119+
120+
pushd memcached-operator
121+
# Add a second Kind to test watching multiple GVKs
122+
operator-sdk add crd --kind=Foo --api-version=ansible.example.com/v1alpha1
123+
sed -i 's|{{ pull_policy.default..Always.. }}|Always|g' deploy/operator.yaml
124+
cp deploy/operator.yaml deploy/operator-copy.yaml
125+
sed -i "s|{{ REPLACE_IMAGE }}|$IMAGE|g" deploy/operator.yaml
126+
127+
OPERATORDIR="$(pwd)"
128+
129+
deploy_operator
130+
trap_add 'remove_operator' EXIT
131+
test_operator
132+
remove_operator
133+
134+
# the memcached-operator pods remain after the deployment is gone; wait until the pods are removed
135+
if ! timeout 60s bash -c -- "until kubectl get pods -l name=memcached-operator |& grep \"No resources found\"; do sleep 2; done";
136+
then
137+
echo FAIL: memcached-operator Deployment did not get garbage collected
138+
kubectl logs deployment/memcached-operator -c operator
139+
kubectl logs deployment/memcached-operator -c ansible
140+
exit 1
141+
fi
142+
143+
cp deploy/operator-copy.yaml deploy/operator.yaml
144+
sed -i "s|{{ REPLACE_IMAGE }}|$IMAGE2|g" deploy/operator.yaml
145+
deploy_operator
146+
test_operator
147+
remove_operator
148+
149+
popd

0 commit comments

Comments
 (0)