Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit 584b425

Browse files
authored
Test upgrade SBO with OLM (#1221)
1 parent 50365e4 commit 584b425

File tree

15 files changed

+426
-63
lines changed

15 files changed

+426
-63
lines changed

.github/workflows/pr-checks-build-images.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ jobs:
4646
export TAG=pr-${PR_NUMBER}-${PR_SHA:0:8}
4747
export OPERATOR_IMAGE_REF=${OPERATOR_REPO_REF}:${TAG}
4848
export OPERATOR_BUNDLE_IMAGE_REF=${OPERATOR_IMAGE_REF}-bundle
49-
export OPERATOR_INDEX_IMAGE_REF=${OPERATOR_IMAGE_REF}-index
49+
export OPERATOR_INDEX_IMAGE_REF=$(make operator-index-image-ref)
50+
export OPERATOR_UPGRADE_INDEX_IMAGE_REF=${OPERATOR_IMAGE_REF}-index
51+
export OPERATOR_BUNDLE_VERSION=$(make operator-version)-${TAG}
5052
5153
which podman
5254
5355
make opm
5456
55-
OPM=.github/actions/setup-podman/opm BUILDAH_FORMAT=docker make SKIP_REGISTRY_LOGIN=true release-operator -o registry-login
57+
podman pull ${OPERATOR_INDEX_IMAGE_REF}
58+
59+
OPM=.github/actions/setup-podman/opm BUILDAH_FORMAT=docker make SKIP_REGISTRY_LOGIN=true push-index-image-upgrade -o registry-login
5660
5761
mkdir -p ${ARTIFACTS}
5862
5963
echo "export OPERATOR_IMAGE_REF=${OPERATOR_IMAGE_REF}" >> ${ARTIFACTS}/operator.refs
6064
echo "export OPERATOR_BUNDLE_IMAGE_REF=${OPERATOR_BUNDLE_IMAGE_REF}" >> ${ARTIFACTS}/operator.refs
61-
echo "export OPERATOR_INDEX_IMAGE_REF=${OPERATOR_INDEX_IMAGE_REF}" >> ${ARTIFACTS}/operator.refs
65+
echo "export OPERATOR_INDEX_IMAGE_REF=${OPERATOR_UPGRADE_INDEX_IMAGE_REF}" >> ${ARTIFACTS}/operator.refs
6266
6367
podman stop reg
6468
tar -czvf ${ARTIFACTS}/registry.tar.gz -C ${GITHUB_WORKSPACE} registry

.github/workflows/pr-checks.yaml

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
MINIKUBE_WANTREPORTERRORPROMPT: false
1414
K8S_VERSION: "1.19.2"
1515
MINIKUBE_VERSION: "1.26.0"
16+
OLM_VERSION: "0.18.1"
1617
TEST_ACCEPTANCE_CLI: "kubectl"
1718
TEST_RESULTS: "out/acceptance-tests"
1819

@@ -69,7 +70,7 @@ jobs:
6970
timeout-minutes: 90
7071

7172
env:
72-
EXTRA_BEHAVE_ARGS: "--tags=~@knative --tags=~@openshift --tags=~@examples --tags=~@supported-operator --tags=~@optional-annotations --tags=~@workload-resource-mapping --tags=~@disable-github-actions"
73+
EXTRA_BEHAVE_ARGS: "--tags=~@knative --tags=~@openshift --tags=~@examples --tags=~@supported-operator --tags=~@optional-annotations --tags=~@workload-resource-mapping --tags=~@upgrade-with-olm --tags=~@disable-github-actions"
7374
TEST_RUN: Acceptance_tests_Kubernetes_with_OLM
7475

7576
steps:
@@ -385,6 +386,95 @@ jobs:
385386
name: workload-resource-mapping
386387
path: ${{ env.TEST_RESULTS }}
387388

389+
acceptance-upgrade-with-olm:
390+
name: Acceptance Tests for upgrading SBO with OLM on Kubernetes
391+
runs-on: ubuntu-20.04
392+
393+
env:
394+
EXTRA_BEHAVE_ARGS: "--tags=@upgrade-with-olm --tags=~@disable-github-actions"
395+
TEST_RUN: Acceptance_tests_Upgrade_with_OLM
396+
397+
steps:
398+
- name: Checkout Git Repository
399+
uses: actions/checkout@v2
400+
401+
- name: Check if acceptance tests can be skipped
402+
id: check-skip-acceptance
403+
uses: ./.github/actions/check-skip-acceptance-tests
404+
405+
- name: Set up Python
406+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
407+
uses: actions/setup-python@v2
408+
with:
409+
python-version: "3.7"
410+
architecture: "x64"
411+
412+
- name: Setup-cli
413+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
414+
uses: ./.github/actions/setup-cli
415+
with:
416+
start-minikube: true
417+
418+
- name: Install OLM
419+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
420+
timeout-minutes: 10
421+
run: |
422+
kubectl get crd clusterserviceversions.operators.coreos.com || curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v${OLM_VERSION}/install.sh | bash -s v${OLM_VERSION}
423+
424+
- name: Wait for push
425+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
426+
uses: lewagon/wait-on-check-action@1b1630e169116b58a4b933d5ad7effc46d3d312d
427+
with:
428+
ref: ${{ github.event.pull_request.head.sha }}
429+
check-name: "Push operator images (PR)"
430+
repo-token: ${{ secrets.GITHUB_TOKEN }}
431+
wait-interval: 60
432+
433+
- name: Extract image references
434+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
435+
uses: marcofaggian/[email protected]
436+
with:
437+
names: operator-refs-${{github.event.pull_request.number}}-${{github.event.pull_request.head.sha}}
438+
439+
- name: Acceptance tests
440+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' }}
441+
timeout-minutes: 60
442+
run: |
443+
source ./operator.refs
444+
export PATH=$PATH:$(pwd)/bin
445+
make opm yq
446+
447+
source ./hack/upgrade-sbo-env.sh
448+
449+
make SKIP_REGISTRY_LOGIN=true -o registry-login test-acceptance
450+
451+
- name: Collect Kube resources
452+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' && always() }}
453+
continue-on-error: true
454+
uses: ./.github/actions/collect-kube-resources
455+
with:
456+
operator-namespace: operators
457+
olm-namespace: olm
458+
test-namespace-file: out/test-namespace
459+
output-path: ${{env.TEST_RESULTS}}
460+
461+
- name: Setup Testspace
462+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' && always() }}
463+
uses: testspace-com/setup-testspace@v1
464+
with:
465+
domain: ${{ github.repository_owner }}
466+
467+
- name: Publish tests results to Testspace
468+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' && always() }}
469+
run: |
470+
testspace [${{ env.TEST_RUN }}]${{ env.TEST_RESULTS }}/TEST*.xml
471+
472+
- uses: actions/upload-artifact@v2
473+
if: ${{ steps.check-skip-acceptance.outputs.can_skip != 'true' && always() }}
474+
with:
475+
name: upgrade-with-olm
476+
path: ${{ env.TEST_RESULTS }}
477+
388478
acceptance_without_olm:
389479
name: Acceptance tests running on Kubernetes without using OLM
390480
runs-on: ubuntu-20.04

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ bundle
112112
bundle.Dockerfile
113113
config/crd/bases/_.yaml
114114
.cache
115+
116+
service-binding-operator-index*

hack/upgrade-sbo-env.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -x
2+
3+
OUTPUT_DIR=${OUTPUT_DIR:-out}
4+
mkdir -p $OUTPUT_DIR
5+
6+
export TEST_ACCEPTANCE_START_SBO=scenarios
7+
export TEST_OPERATOR_INDEX_IMAGE=${OPERATOR_INDEX_IMAGE_REF:-quay.io/redhat-developer/servicebinding-operator:index}
8+
export TEST_OPERATOR_CHANNEL=candidate
9+
operator_index_yaml=$OUTPUT_DIR/operator-index.yaml
10+
11+
opm render ${TEST_OPERATOR_INDEX_IMAGE} -o yaml > $operator_index_yaml
12+
yq_exp='select(.schema=="olm.channel") | select(.name=="'${TEST_OPERATOR_CHANNEL}'").entries[] | select(.replaces == null).name'
13+
export TEST_OPERATOR_CSV=$(yq eval "$yq_exp" "$operator_index_yaml")
14+
yq_exp='select(.schema=="olm.channel") | select(.name=="'${TEST_OPERATOR_CHANNEL}'").package'
15+
export TEST_OPERATOR_PACKAGE=$(yq eval "$yq_exp" "$operator_index_yaml")
16+
17+
env | grep TEST_OPERATOR

make/acceptance.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ifeq ($(TEST_ACCEPTANCE_START_SBO), local)
4444
test-acceptance-setup: stop-local build test-cleanup create-test-namespace deploy-test-3rd-party-crds
4545
$(Q)echo "Starting local SBO instance"
4646
$(eval TEST_ACCEPTANCE_SBO_STARTED := $(shell ZAP_FLAGS="$(ZAP_FLAGS)" OUTPUT="$(TEST_ACCEPTANCE_OUTPUT_DIR)" RUN_IN_BACKGROUND=true ./hack/deploy-sbo-local.sh))
47-
else ifeq ($(TEST_ACCEPTANCE_START_SBO), remote)
47+
else ifeq ($(TEST_ACCEPTANCE_START_SBO), $(filter $(TEST_ACCEPTANCE_START_SBO), remote scenarios))
4848
test-acceptance-setup: test-cleanup create-test-namespace
4949
else ifeq ($(TEST_ACCEPTANCE_START_SBO), operator-hub)
5050
test-acceptance-setup:

make/build.mk

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ manifests: controller-gen
2626
bundle: manifests kustomize yq kubectl-slice operator-sdk push-image
2727
# $(OPERATOR_SDK) generate kustomize manifests -q
2828
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_REPO_REF)@$(OPERATOR_IMAGE_SHA_REF)
29-
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
29+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(OPERATOR_BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS)
3030
$(YQ) e -i '.metadata.annotations.containerImage="$(OPERATOR_REPO_REF)@$(OPERATOR_IMAGE_SHA_REF)"' bundle/manifests/service-binding-operator.clusterserviceversion.yaml
3131
# this is needed because $(OPERATOR_SDK) 1.16 filters out aggregated cluster role and the accompanied binding
3232
$(KUSTOMIZE) build config/manifests | $(YQ) e 'select((.kind == "ClusterRole" and .metadata.name == "service-binding-controller-role") or (.kind == "ClusterRoleBinding" and .metadata.name == "service-binding-controller-rolebinding"))' - | $(KUBECTL_SLICE) -o bundle/manifests -t '{{.metadata.name}}_{{.apiVersion | replace "/" "_"}}_{{.kind | lower}}.yaml'
@@ -67,10 +67,26 @@ index-image: opm push-bundle-image
6767
@echo "package: $(CSV_PACKAGE_NAME)" >> $(OPERATOR_INDEX_YAML)
6868
@echo "name: $(DEFAULT_OPERATOR_CHANNEL)" >> $(OPERATOR_INDEX_YAML)
6969
@echo "entries:" >> $(OPERATOR_INDEX_YAML)
70-
@echo "- name: $(CSV_PACKAGE_NAME).v$(VERSION)" >> $(OPERATOR_INDEX_YAML)
70+
@echo "- name: $(CSV_PACKAGE_NAME).v$(OPERATOR_BUNDLE_VERSION)" >> $(OPERATOR_INDEX_YAML)
7171
$(OPM) validate $(OPERATOR_INDEX_NAME)
7272
$(CONTAINER_RUNTIME) build -f $(OPERATOR_INDEX_NAME).Dockerfile -t $(OPERATOR_INDEX_IMAGE_REF) .
7373

74+
.PHONY: index-image-upgrade
75+
index-image-upgrade: OPERATOR_BUNDLE_VERSION ?= $(VERSION)-$(GIT_COMMIT_ID)
76+
index-image-upgrade: opm push-bundle-image
77+
mkdir -p $(OPERATOR_INDEX_DIR)
78+
-$(OPM) generate dockerfile $(OPERATOR_INDEX_NAME)
79+
$(OPM) render $(OPERATOR_INDEX_IMAGE_REF) --output=yaml > $(OPERATOR_INDEX_YAML)
80+
$(OPM) render $(OPERATOR_BUNDLE_IMAGE_REF) --output=yaml >> $(OPERATOR_INDEX_YAML)
81+
$(YQ) eval -i '(select(.schema=="olm.channel").entries) += {"name": "$(CSV_PACKAGE_NAME).v$(OPERATOR_BUNDLE_VERSION)", "replaces": "'$$(yq eval 'select(.schema=="olm.channel") | select(.name=="$(DEFAULT_OPERATOR_CHANNEL)").entries[] | select(.replaces == null).name' $(OPERATOR_INDEX_YAML))'"}' $(OPERATOR_INDEX_YAML)
82+
$(OPM) validate $(OPERATOR_INDEX_NAME)
83+
$(CONTAINER_RUNTIME) build -f $(OPERATOR_INDEX_NAME).Dockerfile -t $(OPERATOR_UPGRADE_INDEX_IMAGE_REF) .
84+
85+
.PHONY: push-index-image-upgrade
86+
# push upgrade index image
87+
push-index-image-upgrade: index-image-upgrade registry-login
88+
$(Q)$(CONTAINER_RUNTIME) push $(OPERATOR_UPGRADE_INDEX_IMAGE_REF)
89+
7490
.PHONY: push-index-image
7591
# push index image
7692
push-index-image: index-image registry-login

make/version.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ OPERATOR_REGISTRY ?= quay.io
1010
OPERATOR_REPO_REF ?= $(OPERATOR_REGISTRY)/redhat-developer/servicebinding-operator
1111
OPERATOR_IMAGE_REF ?= $(OPERATOR_REPO_REF):$(GIT_COMMIT_ID)
1212
OPERATOR_IMAGE_SHA_REF ?= $(shell $(CONTAINER_RUNTIME) inspect --format='{{index .RepoDigests 0}}' $(OPERATOR_IMAGE_REF) | cut -f 2 -d '@')
13+
OPERATOR_BUNDLE_VERSION ?= $(VERSION)
1314
OPERATOR_BUNDLE_IMAGE_REF ?= $(OPERATOR_REPO_REF):bundle-$(VERSION)-$(GIT_COMMIT_ID)
1415
OPERATOR_INDEX_IMAGE_REF ?= $(OPERATOR_REPO_REF):index
16+
OPERATOR_UPGRADE_INDEX_IMAGE_REF ?= $(OPERATOR_REPO_REF):upgrade-index
17+
18+
.PHONY: operator-version
19+
# Prints operator version
20+
operator-version:
21+
@echo $(VERSION)
1522

1623
.PHONY: operator-repo-ref
1724
# Prints operator repo ref
@@ -32,3 +39,8 @@ operator-bundle-image-ref:
3239
# Prints operator index image ref
3340
operator-index-image-ref:
3441
@echo $(OPERATOR_INDEX_IMAGE_REF)
42+
43+
.PHONY: operator-upgrade-index-image-ref
44+
# Prints operator upgrade index image ref
45+
operator-upgrade-index-image-ref:
46+
@echo $(OPERATOR_UPGRADE_INDEX_IMAGE_REF)

test/acceptance/features/environment.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929

3030
def before_all(_context):
3131
if ctx.cli == "oc":
32-
output, code = cmd.run("oc version --client | grep Client")
33-
assert code == 0, f"Checking oc version failed: {output}"
34-
35-
oc_ver = output.split()[2]
32+
oc_ver = ctx.cli_version
3633
assert semver.compare(oc_ver, "4.5.0") > 0, f"oc version is required 4.5+, but is {oc_ver}."
3734

3835
namespace = os.getenv("TEST_NAMESPACE")
@@ -41,7 +38,7 @@ def before_all(_context):
4138

4239
start_sbo = os.getenv("TEST_ACCEPTANCE_START_SBO")
4340
assert start_sbo is not None, "TEST_ACCEPTANCE_START_SBO is not set. It should be one of local, remote or operator-hub"
44-
assert start_sbo in {"local", "remote", "operator-hub"}, "TEST_ACCEPTANCE_START_SBO should be one of local, remote or operator-hub"
41+
assert start_sbo in {"local", "remote", "operator-hub", "scenarios"}, "TEST_ACCEPTANCE_START_SBO should be one of local, remote or operator-hub"
4542

4643
if start_sbo == "local":
4744
assert not str(os.getenv("TEST_ACCEPTANCE_SBO_STARTED")).startswith("FAILED"), "TEST_ACCEPTANCE_SBO_STARTED shoud not be FAILED."
@@ -53,6 +50,8 @@ def before_all(_context):
5350
output = str(output).strip()
5451
assert output != "", "Unable to find SBO's deployment in any namespace."
5552
_context.sbo_namespace = output
53+
elif start_sbo == "scenarios":
54+
print("INFO: The scenarios are responsible for installing and running SBO...")
5655
else:
5756
assert False, f"TEST_ACCEPTANCE_START_SBO={start_sbo} is currently unsupported."
5857
ctx.no_scenarios_failed = True
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import os
2+
from steps.command import Command
23

34

45
class Environment(object):
56
cli = "oc"
7+
cli_version = None
68

7-
def __init__(self, cli):
9+
def __init__(self, cli, cli_version=None):
810
self.cli = cli
11+
self.cli_version = cli_version
912

1013

1114
# This is a global context (complementing behave's context)
1215
# to be accesible from any place, even where behave's context is not available.
1316
global ctx
14-
ctx = Environment(os.getenv("TEST_ACCEPTANCE_CLI", "oc"))
17+
cmd = Command()
18+
cli = os.getenv("TEST_ACCEPTANCE_CLI", "oc")
19+
cli_version = None
20+
if cli == "oc":
21+
output, code = cmd.run("oc version --client | grep Client")
22+
assert code == 0, f"Checking {cli} version failed: {output}"
23+
cli_version = output.split()[2]
24+
elif cli == "kubectl":
25+
output, code = cmd.run("kubectl version -o json | jq -rc '.clientVersion.gitVersion'")
26+
assert code == 0, f"Checking {cli} version failed: {output}"
27+
cli_version = output.split(sep="v")[1]
28+
29+
ctx = Environment(cli, cli_version)

test/acceptance/features/steps/olm.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,22 @@ def install_catalog_source(self):
5151
return False
5252
return self.openshift.wait_for_package_manifest(self.package_name, self.operator_catalog_source_name, self.operator_catalog_channel)
5353

54+
def csv_version_resolved(self, csv_version=None):
55+
if csv_version is None:
56+
if self.operator_subscription_csv_version is None:
57+
return self.openshift.get_current_csv(self.package_name, self.operator_catalog_source_name, self.operator_catalog_channel)
58+
else:
59+
return self.operator_subscription_csv_version
60+
else:
61+
return csv_version
62+
5463
def install_operator_subscription(self, csv_version=None, install_mode=InstallMode.Automatic):
55-
csv_version_resolved = self.operator_subscription_csv_version if csv_version is None else csv_version
64+
csv_version_resolved = self.csv_version_resolved(csv_version)
5665
install_sub_output = self.openshift.create_operator_subscription(
5766
self.package_name, self.operator_catalog_source_name, self.operator_catalog_channel, self.operator_catalog_namespace,
5867
csv_version_resolved, install_mode)
5968
if re.search(r'.*subscription.operators.coreos.com/%s\s(unchanged|created)' % self.package_name, install_sub_output) is None:
6069
print("Failed to create {} operator subscription".format(self.package_name))
6170
return False
62-
self.openshift.approve_operator_subscription(self.package_name, csv_version_resolved)
71+
self.openshift.approve_operator_subscription(self.package_name)
6372
return True

0 commit comments

Comments
 (0)