Skip to content

Commit 4065eb1

Browse files
committed
fix TestClusterExtensionInstallReResolvesWhenNewCataloge2e test
1 parent f681af0 commit 4065eb1

File tree

10 files changed

+101
-53
lines changed

10 files changed

+101
-53
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ E2E_REGISTRY_NAMESPACE := operator-controller-e2e
125125

126126
export REG_PKG_NAME := registry-operator
127127
export REGISTRY_ROOT := $(E2E_REGISTRY_NAME).$(E2E_REGISTRY_NAMESPACE).svc:5000
128-
export CATALOG_IMG := $(REGISTRY_ROOT)/test-catalog:e2e
128+
export CATALOG_IMG_TAG := v1
129+
export UPDATED_CATALOG_IMG_TAG := v2
130+
export CATALOG_IMG := $(REGISTRY_ROOT)/test-catalog:$(CATALOG_IMG_TAG)
131+
export UPDATED_CATALOG_IMG := $(REGISTRY_ROOT)/test-catalog:$(UPDATED_CATALOG_IMG_TAG)
129132
.PHONY: test-ext-dev-e2e
130133
test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension create, upgrade and delete tests.
131134
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) $(E2E_REGISTRY_NAMESPACE)
@@ -141,7 +144,8 @@ image-registry: ## Setup in-cluster image registry
141144
./test/tools/image-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME)
142145

143146
build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and push it to the image registry
144-
./test/tools/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(CATALOG_IMG)
147+
./test/tools/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(CATALOG_IMG) $(CATALOG_IMG_TAG)
148+
./test/tools/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(UPDATED_CATALOG_IMG) $(UPDATED_CATALOG_IMG_TAG)
145149

146150
# When running the e2e suite, you can set the ARTIFACT_PATH variable to the absolute path
147151
# of the directory for the operator-controller e2e tests to store the artifacts, which

test/e2e/cluster_extension_install_test.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
9191
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
9292
assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
9393
assert.Contains(ct, cond.Message, "resolved to")
94-
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.2.0.0", Version: "2.0.0"}, clusterExtension.Status.ResolvedBundle)
94+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.1.2.0", Version: "1.2.0"}, clusterExtension.Status.ResolvedBundle)
9595
}, pollDuration, pollInterval)
9696

9797
t.Log("By eventually reporting a successful unpacked")
@@ -133,36 +133,27 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
133133
PackageName: pkgName,
134134
InstallNamespace: "default",
135135
}
136-
137-
t.Log("By deleting the catalog first")
138-
require.NoError(t, c.Delete(context.Background(), extensionCatalog))
139-
require.EventuallyWithT(t, func(ct *assert.CollectT) {
140-
err := c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, &catalogd.ClusterCatalog{})
141-
assert.True(ct, errors.IsNotFound(err))
142-
}, pollDuration, pollInterval)
143-
136+
t.Log("It resolves the specified package with correct bundle path")
144137
t.Log("By creating the ClusterExtension resource")
145138
require.NoError(t, c.Create(context.Background(), clusterExtension))
146139

147-
// TODO: this isn't a good precondition because a missing package results in
148-
// exponential backoff retries. So we can't be sure that the re-reconcile is a result of
149-
// the catalog becoming available because it could also be a retry of the initial failed
150-
// resolution.
151-
t.Log("By failing to find ClusterExtension during resolution")
140+
t.Log("By reporting a successful resolution and bundle path")
152141
require.EventuallyWithT(t, func(ct *assert.CollectT) {
153142
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
143+
assert.Len(ct, clusterExtension.Status.Conditions, len(conditionsets.ConditionTypes))
154144
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
155145
if !assert.NotNil(ct, cond) {
156146
return
157147
}
158-
assert.Equal(ct, metav1.ConditionFalse, cond.Status)
159-
assert.Equal(ct, ocv1alpha1.ReasonResolutionFailed, cond.Reason)
160-
assert.Contains(ct, cond.Message, fmt.Sprintf("no package %q found", pkgName))
148+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
149+
assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
150+
assert.Contains(ct, cond.Message, "resolved to")
151+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.1.2.0", Version: "1.2.0"}, clusterExtension.Status.ResolvedBundle)
161152
}, pollDuration, pollInterval)
162153

163-
t.Log("By creating an ClusterExtension catalog with the desired package")
154+
t.Log("By creating an ClusterExtension catalog with the updated ClusterCatalog")
164155
var err error
165-
extensionCatalog, err = createTestCatalog(context.Background(), testCatalogName, os.Getenv(testCatalogRefEnvVar))
156+
extensionCatalog, err = patchTestCatalog(context.Background(), testCatalogName, os.Getenv(testUpdatedCatalogRefEnvVar))
166157
require.NoError(t, err)
167158
require.EventuallyWithT(t, func(ct *assert.CollectT) {
168159
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog))
@@ -174,15 +165,18 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
174165
assert.Equal(ct, catalogd.ReasonUnpackSuccessful, cond.Reason)
175166
}, pollDuration, pollInterval)
176167

177-
t.Log("By eventually resolving the package successfully")
168+
t.Log("By eventually reporting a successful resolution and bundle path")
178169
require.EventuallyWithT(t, func(ct *assert.CollectT) {
179170
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
171+
assert.Len(ct, clusterExtension.Status.Conditions, len(conditionsets.ConditionTypes))
180172
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
181173
if !assert.NotNil(ct, cond) {
182174
return
183175
}
184176
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
185177
assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
178+
assert.Contains(ct, cond.Message, "resolved to")
179+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.2.0.0", Version: "2.0.0"}, clusterExtension.Status.ResolvedBundle)
186180
}, pollDuration, pollInterval)
187181
}
188182

test/e2e/e2e_suite_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ var (
2222
)
2323

2424
const (
25-
testCatalogRefEnvVar = "CATALOG_IMG"
26-
testCatalogName = "test-catalog"
25+
testCatalogRefEnvVar = "CATALOG_IMG"
26+
testUpdatedCatalogRefEnvVar = "UPDATED_CATALOG_IMG"
27+
testCatalogName = "test-catalog"
2728
)
2829

2930
func TestMain(m *testing.M) {
@@ -58,3 +59,23 @@ func createTestCatalog(ctx context.Context, name string, imageRef string) (*cata
5859
err := c.Create(ctx, catalog)
5960
return catalog, err
6061
}
62+
63+
func patchTestCatalog(ctx context.Context, name string, newImageRef string) (*catalogd.ClusterCatalog, error) {
64+
// Fetch the existing ClusterCatalog
65+
catalog := &catalogd.ClusterCatalog{}
66+
err := c.Get(ctx, client.ObjectKey{Name: name}, catalog)
67+
if err != nil {
68+
return nil, err
69+
}
70+
71+
// Update the ImageRef
72+
catalog.Spec.Source.Image.Ref = newImageRef
73+
74+
// Patch the ClusterCatalog
75+
err = c.Update(ctx, catalog)
76+
if err != nil {
77+
return nil, err
78+
}
79+
80+
return catalog, err
81+
}

test/tools/build-push-e2e-catalog.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,61 @@ set -o pipefail
77
help="
88
build-push-e2e-catalog.sh is a script to build and push the e2e catalog image using kaniko.
99
Usage:
10-
build-push-e2e-catalog.sh [NAMESPACE] [TAG]
10+
build-push-e2e-catalog.sh [NAMESPACE] [IMAGE] [TAG]
1111
1212
Argument Descriptions:
1313
- NAMESPACE is the namespace the kaniko Job should be created in
14+
- IMAGE is the full image name to build and push the catalog image
1415
- TAG is the full tag used to build and push the catalog image
1516
"
1617

17-
if [[ "$#" -ne 2 ]]; then
18+
if [[ "$#" -ne 3 ]]; then
1819
echo "Illegal number of arguments passed"
1920
echo "${help}"
2021
exit 1
2122
fi
2223

2324
namespace=$1
24-
tag=$2
25+
image=$2
26+
tag=$3
2527

26-
echo "${namespace}" "${tag}"
28+
echo "${namespace}" "${image}" "${tag}"
2729

28-
kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog.Dockerfile operator-controller-e2e.dockerfile
29-
kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog operator-controller-e2e.build-contents
30+
kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog-${tag}.Dockerfile operator-controller-e2e-${tag}.dockerfile
31+
kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog-${tag} operator-controller-e2e-${tag}.build-contents
3032

3133
kubectl apply -f - << EOF
3234
apiVersion: batch/v1
3335
kind: Job
3436
metadata:
35-
name: kaniko
37+
name: "kaniko-${tag}"
3638
namespace: "${namespace}"
3739
spec:
3840
template:
3941
spec:
4042
containers:
41-
- name: kaniko
43+
- name: kaniko-${tag}
4244
image: gcr.io/kaniko-project/executor:latest
43-
args: ["--dockerfile=/workspace/test-catalog.Dockerfile",
45+
args: ["--dockerfile=/workspace/test-catalog-${tag}.Dockerfile",
4446
"--context=/workspace/",
45-
"--destination=${tag}",
47+
"--destination=${image}",
4648
"--skip-tls-verify"]
4749
volumeMounts:
4850
- name: dockerfile
4951
mountPath: /workspace/
5052
- name: build-contents
51-
mountPath: /workspace/test-catalog/
53+
mountPath: /workspace/test-catalog-${tag}/
5254
restartPolicy: Never
5355
volumes:
5456
- name: dockerfile
5557
configMap:
56-
name: operator-controller-e2e.dockerfile
58+
name: operator-controller-e2e-${tag}.dockerfile
5759
items:
58-
- key: test-catalog.Dockerfile
59-
path: test-catalog.Dockerfile
60+
- key: test-catalog-${tag}.Dockerfile
61+
path: test-catalog-${tag}.Dockerfile
6062
- name: build-contents
6163
configMap:
62-
name: operator-controller-e2e.build-contents
64+
name: operator-controller-e2e-${tag}.build-contents
6365
EOF
6466

65-
kubectl wait --for=condition=Complete -n "${namespace}" jobs/kaniko --timeout=60s
67+
kubectl wait --for=condition=Complete -n "${namespace}" jobs/kaniko-${tag} --timeout=60s

testdata/catalogs/test-catalog.Dockerfile renamed to testdata/catalogs/test-catalog-v1.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM scratch
2-
ADD test-catalog /configs
2+
ADD test-catalog-v1 /configs
33

44
# Set DC-specific label for the location of the DC root directory
55
# in the image

testdata/catalogs/test-catalog/catalog.yaml renamed to testdata/catalogs/test-catalog-v1/catalog.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ entries:
1818
replaces: prometheus-operator.1.0.0
1919
- name: prometheus-operator.1.2.0
2020
replaces: prometheus-operator.1.0.1
21-
- name: prometheus-operator.2.0.0
22-
replaces: prometheus-operator.1.2.0
2321
---
2422
schema: olm.bundle
2523
name: prometheus-operator.1.0.0
@@ -50,13 +48,3 @@ properties:
5048
value:
5149
packageName: prometheus
5250
version: 1.2.0
53-
---
54-
schema: olm.bundle
55-
name: prometheus-operator.2.0.0
56-
package: prometheus
57-
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v2.0.0
58-
properties:
59-
- type: olm.package
60-
value:
61-
packageName: prometheus
62-
version: 2.0.0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM scratch
2+
ADD test-catalog-v2 /configs
3+
4+
# Set DC-specific label for the location of the DC root directory
5+
# in the image
6+
LABEL operators.operatorframework.io.index.configs.v1=/configs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/expected_all.json
2+
..*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
schema: olm.package
3+
name: prometheus
4+
defaultChannel: beta
5+
---
6+
schema: olm.channel
7+
name: beta
8+
package: prometheus
9+
entries:
10+
- name: prometheus-operator.2.0.0
11+
replaces: prometheus-operator.1.2.0
12+
---
13+
schema: olm.bundle
14+
name: prometheus-operator.1.2.0
15+
package: prometheus
16+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.2.0
17+
properties:
18+
- type: olm.package
19+
value:
20+
packageName: prometheus
21+
version: 1.2.0
22+
---
23+
schema: olm.bundle
24+
name: prometheus-operator.2.0.0
25+
package: prometheus
26+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v2.0.0
27+
properties:
28+
- type: olm.package
29+
value:
30+
packageName: prometheus
31+
version: 2.0.0

0 commit comments

Comments
 (0)