Skip to content

Commit 8e039f3

Browse files
authored
Add test to verify registry+v1 webhooks limitation (#830)
No bundles with webhooks are currently allowed and we must be clearly indicated in the conditions of `ClusterExtension` Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 7268f2a commit 8e039f3

File tree

6 files changed

+146
-1
lines changed

6 files changed

+146
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ kind-load-test-artifacts: $(KIND) #EXHELP Load the e2e testdata container images
189189
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.1 --name $(KIND_CLUSTER_NAME)
190190
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.2.0 --name $(KIND_CLUSTER_NAME)
191191
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v2.0.0 --name $(KIND_CLUSTER_NAME)
192+
$(CONTAINER_RUNTIME) build testdata/bundles/registry-v1/package-with-webhooks.v1.0.0 -t localhost/testdata/bundles/registry-v1/package-with-webhooks:v1.0.0
193+
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/package-with-webhooks:v1.0.0 --name $(KIND_CLUSTER_NAME)
192194

193195

194196
#SECTION Build
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"os"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
"k8s.io/apimachinery/pkg/api/errors"
11+
apimeta "k8s.io/apimachinery/pkg/api/meta"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
"k8s.io/apimachinery/pkg/types"
14+
15+
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
16+
17+
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
18+
)
19+
20+
func TestClusterExtensionPackagesWithWebhooksAreNotAllowed(t *testing.T) {
21+
ctx := context.Background()
22+
catalog, err := createTestCatalog(ctx, testCatalogName, os.Getenv(testCatalogRefEnvVar))
23+
defer func(cat *catalogd.Catalog) {
24+
require.NoError(t, c.Delete(context.Background(), cat))
25+
require.Eventually(t, func() bool {
26+
err := c.Get(context.Background(), types.NamespacedName{Name: cat.Name}, &catalogd.Catalog{})
27+
return errors.IsNotFound(err)
28+
}, pollDuration, pollInterval)
29+
}(catalog)
30+
require.NoError(t, err)
31+
32+
deleteClusterExtension := func(clusterExtension *ocv1alpha1.ClusterExtension) {
33+
require.NoError(t, c.Delete(ctx, clusterExtension))
34+
require.Eventually(t, func() bool {
35+
err := c.Get(ctx, types.NamespacedName{Name: clusterExtension.Name}, &ocv1alpha1.ClusterExtension{})
36+
return errors.IsNotFound(err)
37+
}, pollDuration, pollInterval)
38+
}
39+
40+
clusterExtension := &ocv1alpha1.ClusterExtension{
41+
ObjectMeta: metav1.ObjectMeta{
42+
GenerateName: "package-with-webhooks-",
43+
},
44+
Spec: ocv1alpha1.ClusterExtensionSpec{
45+
PackageName: "package-with-webhooks",
46+
Version: "1.0.0",
47+
InstallNamespace: "default",
48+
},
49+
}
50+
err = c.Create(ctx, clusterExtension)
51+
defer deleteClusterExtension(clusterExtension)
52+
require.NoError(t, err)
53+
54+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
55+
assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
56+
57+
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeInstalled)
58+
assert.NotNil(ct, cond)
59+
assert.Equal(ct, metav1.ConditionFalse, cond.Status)
60+
assert.Equal(ct, ocv1alpha1.ReasonInstallationFailed, cond.Reason)
61+
assert.Contains(ct, cond.Message, "webhookDefinitions are not supported")
62+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "package-with-webhooks.1.0.0", Version: "1.0.0"}, clusterExtension.Status.ResolvedBundle)
63+
}, pollDuration, pollInterval)
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM scratch
2+
3+
# Core bundle labels.
4+
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
5+
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
6+
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
7+
LABEL operators.operatorframework.io.bundle.package.v1=package-with-webhooks
8+
LABEL operators.operatorframework.io.bundle.channels.v1=beta
9+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.28.0
10+
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
11+
LABEL operators.operatorframework.io.metrics.project_layout=unknown
12+
13+
# Copy files to locations specified by labels.
14+
COPY manifests /manifests/
15+
COPY metadata /metadata/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
name: package-with-webhooks.v1.0.0
5+
namespace: placeholder
6+
spec:
7+
webhookdefinitions:
8+
- admissionReviewVersions:
9+
- v1alpha1
10+
- v1beta1
11+
containerPort: 443
12+
conversionCRDs:
13+
- testcds.package-with-webhooks.io
14+
deploymentName: test-operator-controller-manager
15+
generateName: testcrds
16+
sideEffects: None
17+
targetPort: 9443
18+
type: ConversionWebhook
19+
webhookPath: /convert
20+
description: Test package with webhooks
21+
displayName: Package with webhooks
22+
icon:
23+
- base64data: PHN2ZyB3aWR0aD0iMjQ5MCIgaGVpZ2h0PSIyNTAwIiB2aWV3Qm94PSIwIDAgMjU2IDI1NyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+PHBhdGggZD0iTTEyOC4wMDEuNjY3QzU3LjMxMS42NjcgMCA1Ny45NzEgMCAxMjguNjY0YzAgNzAuNjkgNTcuMzExIDEyNy45OTggMTI4LjAwMSAxMjcuOTk4UzI1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jLjAwMi0uMDAyLTMuOTg3IDE2LjQwMS0xOS4zMTQgMzIuMTk3eiIgZmlsbD0iI0RBNEUzMSIvPjwvc3ZnPg==
24+
mediatype: image/svg+xml
25+
installModes:
26+
- supported: true
27+
type: OwnNamespace
28+
- supported: true
29+
type: SingleNamespace
30+
- supported: false
31+
type: MultiNamespace
32+
- supported: true
33+
type: AllNamespaces
34+
version: 1.0.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
annotations:
2+
# Core bundle annotations.
3+
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
4+
operators.operatorframework.io.bundle.manifests.v1: manifests/
5+
operators.operatorframework.io.bundle.metadata.v1: metadata/
6+
operators.operatorframework.io.bundle.package.v1: package-with-webhooks
7+
operators.operatorframework.io.bundle.channels.v1: beta
8+
operators.operatorframework.io.metrics.builder: operator-sdk-v1.28.0
9+
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
10+
operators.operatorframework.io.metrics.project_layout: unknown

testdata/catalogs/test-catalog/catalog.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,24 @@ properties:
5959
- type: olm.package
6060
value:
6161
packageName: prometheus
62-
version: 2.0.0
62+
version: 2.0.0
63+
---
64+
schema: olm.package
65+
name: package-with-webhooks
66+
defaultChannel: beta
67+
---
68+
schema: olm.channel
69+
name: beta
70+
package: package-with-webhooks
71+
entries:
72+
- name: package-with-webhooks.1.0.0
73+
---
74+
schema: olm.bundle
75+
name: package-with-webhooks.1.0.0
76+
package: package-with-webhooks
77+
image: localhost/testdata/bundles/registry-v1/package-with-webhooks:v1.0.0
78+
properties:
79+
- type: olm.package
80+
value:
81+
packageName: package-with-webhooks
82+
version: 1.0.0

0 commit comments

Comments
 (0)