Skip to content

Commit fe8c81a

Browse files
authored
ci,test,hack/tests: add openshift-ci e2e support for subcommands (#1654)
1 parent 222f6cb commit fe8c81a

File tree

9 files changed

+108
-4
lines changed

9 files changed

+108
-4
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ test/unit:
110110

111111
test/subcommand: test/subcommand/test-local test/subcommand/scorecard test/subcommand/alpha-olm
112112

113+
test/subcommand2:
114+
./ci/tests/subcommand.sh
115+
113116
test/subcommand/test-local:
114117
./hack/tests/test-subcommand.sh
115118

116119
test/subcommand/scorecard:
117120
./hack/tests/scorecard-subcommand.sh
118121

122+
test/subcommand/scorecard2:
123+
./ci/tests/scorecard-subcommand.sh
124+
119125
test/subcommand/alpha-olm:
120126
./hack/tests/alpha-olm-subcommands.sh
121127

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM osdk-builder as builder
2+
3+
RUN ci/tests/scorecard-proxy-scaffold.sh
4+
5+
FROM registry.access.redhat.com/ubi7/ubi-minimal:latest
6+
7+
ENV PROXY=/usr/local/bin/scorecard-proxy \
8+
USER_UID=1001 \
9+
USER_NAME=proxy
10+
11+
# install operator binary
12+
COPY --from=builder /scorecard/scorecard-proxy ${PROXY}
13+
14+
COPY --from=builder /scorecard/bin /usr/local/bin
15+
RUN /usr/local/bin/user_setup
16+
17+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
18+
19+
USER ${USER_UID}

ci/tests/scorecard-proxy-scaffold.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
ROOTDIR="$(pwd)"
5+
SCORECARD_DIR="/scorecard"
6+
7+
mkdir -p $SCORECARD_DIR
8+
9+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
10+
go build \
11+
-gcflags "all=-trimpath=${ROOTDIR}" \
12+
-asmflags "all=-trimpath=${ROOTDIR}" \
13+
-o $SCORECARD_DIR/scorecard-proxy \
14+
images/scorecard-proxy/cmd/proxy/main.go
15+
mv images/scorecard-proxy/bin $SCORECARD_DIR/bin

ci/tests/scorecard-subcommand.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
component="scorecard-proxy"
4+
eval IMAGE=$IMAGE_FORMAT
5+
CSV_PATH="deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml"
6+
CONFIG_PATH=".test-osdk-scorecard.yaml"
7+
8+
set -ex
9+
10+
# the test framework directory has all the manifests needed to run the cluster
11+
pushd test/test-framework
12+
commandoutput="$(operator-sdk scorecard \
13+
--cr-manifest deploy/crds/cache_v1alpha1_memcached_cr.yaml \
14+
--cr-manifest deploy/crds/cache_v1alpha1_memcachedrs_cr.yaml \
15+
--init-timeout 60 \
16+
--csv-path "$CSV_PATH" \
17+
--verbose \
18+
--proxy-image "$IMAGE" \
19+
2>&1)"
20+
echo $commandoutput | grep "Total Score: 82%"
21+
22+
# test config file
23+
commandoutput2="$(operator-sdk scorecard \
24+
--proxy-image "$IMAGE" \
25+
--config "$CONFIG_PATH")"
26+
# check basic suite
27+
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 3,[[:space:]]"partialPass": 0,[[:space:]]"fail": 0,[[:space:]]"totalTests": 3,[[:space:]]"totalScorePercent": 100,.*$'
28+
# check olm suite
29+
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 2,[[:space:]]"partialPass": 3,[[:space:]]"fail": 0,[[:space:]]"totalTests": 5,[[:space:]]"totalScorePercent": 74,.*$'
30+
# check custom json result
31+
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 1,[[:space:]]"partialPass": 1,[[:space:]]"fail": 0,[[:space:]]"totalTests": 2,[[:space:]]"totalScorePercent": 71,.*$'
32+
popd

ci/tests/subcommand.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
source hack/lib/test_lib.sh
3+
4+
set -eux
5+
6+
ROOTDIR="$(pwd)"
7+
mkdir -p $ROOTDIR/bin
8+
export PATH=$ROOTDIR/bin:$PATH
9+
10+
if ! [ -x "$(command -v kubectl)" ]; then
11+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.14.2/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl bin/
12+
fi
13+
14+
if ! [ -x "$(command -v oc)" ]; then
15+
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
16+
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
17+
fi
18+
19+
oc version
20+
21+
make install
22+
23+
./hack/tests/test-subcommand.sh
24+
./ci/tests/scorecard-subcommand.sh
25+
# This can't run in openshift-ci because the test cluster already has OLM installed.
26+
#./hack/tests/alpha-olm-subcommands.sh

hack/tests/scorecard-subcommand.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ echo $commandoutput | grep "Total Score: 82%"
2525
# test config file
2626
commandoutput2="$(operator-sdk scorecard \
2727
--proxy-image "$DEST_IMAGE" \
28+
--proxy-pull-policy "Never" \
2829
--config "$CONFIG_PATH")"
2930
# check basic suite
3031
echo $commandoutput2 | grep '^.*"error": 0,[[:space:]]"pass": 3,[[:space:]]"partialPass": 0,[[:space:]]"fail": 0,[[:space:]]"totalTests": 3,[[:space:]]"totalScorePercent": 100,.*$'

hack/tests/test-subcommand.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ source hack/lib/test_lib.sh
33

44
set -ex
55

6+
if [ -z "$KUBECONFIG" ]; then
7+
KUBECONFIG=$HOME/.kube/config
8+
fi
9+
610
pushd test/test-framework
711
# test framework with defaults
812
operator-sdk test local ./test/e2e
913

1014
# test operator-sdk test flags
11-
operator-sdk test local ./test/e2e --global-manifest deploy/crds/cache_v1alpha1_memcached_crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $HOME/.kube/config --image=quay.io/coreos/operator-sdk-dev:test-framework-operator-runtime
15+
operator-sdk test local ./test/e2e --global-manifest deploy/crds/cache_v1alpha1_memcached_crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $KUBECONFIG --image=quay.io/coreos/operator-sdk-dev:test-framework-operator-runtime
1216

1317
# we use the test-memcached namespace for all future tests, so we only need to set this trap once
1418
kubectl create namespace test-memcached
@@ -23,7 +27,7 @@ kubectl delete namespace test-memcached
2327

2428
# test operator in up local mode with kubeconfig
2529
kubectl create namespace test-memcached
26-
operator-sdk test local ./test/e2e --up-local --namespace=test-memcached --kubeconfig $HOME/.kube/config
30+
operator-sdk test local ./test/e2e --up-local --namespace=test-memcached --kubeconfig $KUBECONFIG
2731
kubectl delete namespace test-memcached
2832

2933
# test operator in no-setup mode

test/test-framework/.test-osdk-scorecard.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ cr-manifest:
33
- "deploy/crds/cache_v1alpha1_memcachedrs_cr.yaml"
44
init-timeout: 60
55
csv-path: "deploy/olm-catalog/memcached-operator/0.0.3/memcached-operator.v0.0.3.clusterserviceversion.yaml"
6-
proxy-image: "scorecard-proxy"
7-
proxy-pull-policy: "Never"
86
verbose: true
97
output: json
8+
proxy-image: "scorecard-proxy"

test/test-framework/deploy/namespace-init.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ roleRef:
6565
apiVersion: apps/v1
6666
kind: Deployment
6767
metadata:
68+
creationTimestamp: null
6869
name: memcached-operator
6970
spec:
7071
replicas: 1
@@ -74,6 +75,7 @@ spec:
7475
strategy: {}
7576
template:
7677
metadata:
78+
creationTimestamp: null
7779
labels:
7880
name: memcached-operator
7981
spec:

0 commit comments

Comments
 (0)