-
Notifications
You must be signed in to change notification settings - Fork 67
✨ Promote Webhook FeatureGates to GA (OPRUN-4098) #2267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 3 commits into
operator-framework:main
from
camilamacedo86:promote-webhook-ga
Oct 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/utils/ptr" | ||
|
||
ocv1 "github.com/operator-framework/operator-controller/api/v1" | ||
utils "github.com/operator-framework/operator-controller/internal/shared/util/testutils" | ||
) | ||
|
||
var dynamicClient dynamic.Interface | ||
|
||
func TestNoop(t *testing.T) { | ||
t.Log("Running experimental-e2e tests") | ||
defer utils.CollectTestArtifacts(t, artifactName, c, cfg) | ||
} | ||
|
||
func TestWebhookSupport(t *testing.T) { | ||
t.Log("Test support for bundles with webhooks") | ||
defer utils.CollectTestArtifacts(t, artifactName, c, cfg) | ||
|
||
if dynamicClient == nil { | ||
var err error | ||
dynamicClient, err = dynamic.NewForConfig(cfg) | ||
require.NoError(t, err) | ||
} | ||
|
||
t.Log("By creating install namespace, and necessary rbac resources") | ||
namespace := corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "webhook-operator", | ||
}, | ||
} | ||
require.NoError(t, c.Create(t.Context(), &namespace)) | ||
t.Cleanup(func() { | ||
require.NoError(t, c.Delete(context.Background(), &namespace)) | ||
}) | ||
|
||
serviceAccount := corev1.ServiceAccount{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "webhook-operator-installer", | ||
Namespace: namespace.GetName(), | ||
}, | ||
} | ||
require.NoError(t, c.Create(t.Context(), &serviceAccount)) | ||
t.Cleanup(func() { | ||
require.NoError(t, c.Delete(context.Background(), &serviceAccount)) | ||
}) | ||
|
||
clusterRoleBinding := &rbacv1.ClusterRoleBinding{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "webhook-operator-installer", | ||
}, | ||
Subjects: []rbacv1.Subject{ | ||
{ | ||
Kind: "ServiceAccount", | ||
APIGroup: corev1.GroupName, | ||
Name: serviceAccount.GetName(), | ||
Namespace: serviceAccount.GetNamespace(), | ||
}, | ||
}, | ||
RoleRef: rbacv1.RoleRef{ | ||
APIGroup: rbacv1.GroupName, | ||
Kind: "ClusterRole", | ||
Name: "cluster-admin", | ||
}, | ||
} | ||
require.NoError(t, c.Create(t.Context(), clusterRoleBinding)) | ||
t.Cleanup(func() { | ||
require.NoError(t, c.Delete(context.Background(), clusterRoleBinding)) | ||
}) | ||
|
||
t.Log("By creating the webhook-operator ClusterCatalog") | ||
extensionCatalog := &ocv1.ClusterCatalog{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "webhook-operator-catalog", | ||
}, | ||
Spec: ocv1.ClusterCatalogSpec{ | ||
Source: ocv1.CatalogSource{ | ||
Type: ocv1.SourceTypeImage, | ||
Image: &ocv1.ImageSource{ | ||
Ref: fmt.Sprintf("%s/e2e/test-catalog:v1", os.Getenv("CLUSTER_REGISTRY_HOST")), | ||
PollIntervalMinutes: ptr.To(1), | ||
}, | ||
}, | ||
}, | ||
} | ||
require.NoError(t, c.Create(t.Context(), extensionCatalog)) | ||
t.Cleanup(func() { | ||
require.NoError(t, c.Delete(context.Background(), extensionCatalog)) | ||
}) | ||
|
||
t.Log("By waiting for the catalog to serve its metadata") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
require.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.GetName()}, extensionCatalog)) | ||
cond := apimeta.FindStatusCondition(extensionCatalog.Status.Conditions, ocv1.TypeServing) | ||
require.NotNil(ct, cond) | ||
require.Equal(ct, metav1.ConditionTrue, cond.Status) | ||
require.Equal(ct, ocv1.ReasonAvailable, cond.Reason) | ||
}, pollDuration, pollInterval) | ||
|
||
t.Log("By installing the webhook-operator ClusterExtension") | ||
clusterExtension := &ocv1.ClusterExtension{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "webhook-operator-extension", | ||
}, | ||
Spec: ocv1.ClusterExtensionSpec{ | ||
Source: ocv1.SourceConfig{ | ||
SourceType: "Catalog", | ||
Catalog: &ocv1.CatalogFilter{ | ||
PackageName: "webhook-operator", | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{"olm.operatorframework.io/metadata.name": extensionCatalog.Name}, | ||
}, | ||
}, | ||
}, | ||
Namespace: namespace.GetName(), | ||
ServiceAccount: ocv1.ServiceAccountReference{ | ||
Name: serviceAccount.GetName(), | ||
}, | ||
}, | ||
} | ||
require.NoError(t, c.Create(t.Context(), clusterExtension)) | ||
t.Cleanup(func() { | ||
require.NoError(t, c.Delete(context.Background(), clusterExtension)) | ||
}) | ||
|
||
t.Log("By waiting for webhook-operator extension to be installed successfully") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
require.NoError(ct, c.Get(t.Context(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension)) | ||
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeInstalled) | ||
require.NotNil(ct, cond) | ||
require.Equal(ct, metav1.ConditionTrue, cond.Status) | ||
require.Equal(ct, ocv1.ReasonSucceeded, cond.Reason) | ||
require.Contains(ct, cond.Message, "Installed bundle") | ||
require.NotNil(ct, clusterExtension.Status.Install) | ||
require.NotEmpty(ct, clusterExtension.Status.Install.Bundle) | ||
}, pollDuration, pollInterval) | ||
|
||
t.Log("By waiting for webhook-operator deployment to be available") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
deployment := &appsv1.Deployment{} | ||
require.NoError(ct, c.Get(t.Context(), types.NamespacedName{Namespace: namespace.GetName(), Name: "webhook-operator-controller-manager"}, deployment)) | ||
available := false | ||
for _, cond := range deployment.Status.Conditions { | ||
if cond.Type == appsv1.DeploymentAvailable { | ||
available = cond.Status == corev1.ConditionTrue | ||
} | ||
} | ||
require.True(ct, available) | ||
}, pollDuration, pollInterval) | ||
|
||
v1Gvr := schema.GroupVersionResource{ | ||
Group: "webhook.operators.coreos.io", | ||
Version: "v1", | ||
Resource: "webhooktests", | ||
} | ||
v1Client := dynamicClient.Resource(v1Gvr).Namespace(namespace.GetName()) | ||
|
||
t.Log("By eventually seeing that invalid CR creation is rejected by the validating webhook") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
obj := getWebhookOperatorResource("invalid-test-cr", namespace.GetName(), false) | ||
_, err := v1Client.Create(t.Context(), obj, metav1.CreateOptions{}) | ||
require.Error(ct, err) | ||
require.Contains(ct, err.Error(), "Invalid value: false: Spec.Valid must be true") | ||
}, pollDuration, pollInterval) | ||
|
||
var ( | ||
res *unstructured.Unstructured | ||
err error | ||
obj = getWebhookOperatorResource("valid-test-cr", namespace.GetName(), true) | ||
) | ||
|
||
t.Log("By eventually creating a valid CR") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
res, err = v1Client.Create(t.Context(), obj, metav1.CreateOptions{}) | ||
require.NoError(ct, err) | ||
}, pollDuration, pollInterval) | ||
t.Cleanup(func() { | ||
require.NoError(t, v1Client.Delete(context.Background(), obj.GetName(), metav1.DeleteOptions{})) | ||
}) | ||
|
||
require.Equal(t, map[string]interface{}{ | ||
"valid": true, | ||
"mutate": true, | ||
}, res.Object["spec"]) | ||
|
||
t.Log("By checking a valid CR is converted to v2 by the conversion webhook") | ||
v2Gvr := schema.GroupVersionResource{ | ||
Group: "webhook.operators.coreos.io", | ||
Version: "v2", | ||
Resource: "webhooktests", | ||
} | ||
v2Client := dynamicClient.Resource(v2Gvr).Namespace(namespace.GetName()) | ||
|
||
t.Log("By eventually getting the valid CR with a v2 client") | ||
require.EventuallyWithT(t, func(ct *assert.CollectT) { | ||
res, err = v2Client.Get(t.Context(), obj.GetName(), metav1.GetOptions{}) | ||
require.NoError(ct, err) | ||
}, pollDuration, pollInterval) | ||
|
||
t.Log("and verifying that the CR is correctly converted") | ||
require.Equal(t, map[string]interface{}{ | ||
"conversion": map[string]interface{}{ | ||
"valid": true, | ||
"mutate": true, | ||
}, | ||
}, res.Object["spec"]) | ||
} | ||
|
||
func getWebhookOperatorResource(name string, namespace string, valid bool) *unstructured.Unstructured { | ||
return &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": "webhook.operators.coreos.io/v1", | ||
"kind": "webhooktests", | ||
"metadata": map[string]interface{}{ | ||
"name": name, | ||
"namespace": namespace, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"valid": valid, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have more than one kind of webhook that is supported.
certManager is used only for the admission webhook
So, I think it would not be very accurate.
The other suggestion was accepted :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, isn't that what I wrote?
"By default, OLM v1 uses the community Cert Manager package for admission webhook validation."
(I'm totally fine if you don't take the suggestion, but I thought we are both saying the same thing?)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have "OLMv1 supports the installation of bundles containing webhooks by default."
(because we support more than admission webhooks)
Then, below, we explain that for the specific case, admission, certmanager is used.
So, I updated it with a mix of your suggestions.