-
Notifications
You must be signed in to change notification settings - Fork 106
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
Only create per-object webhooks for configured types #285
Changes from all commits
a90901f
9f5553a
ecb0517
e07e0fd
637630d
f04e447
07a8a95
a42edac
db236ea
ebe7df4
bcfffac
6e89f15
3cdf2a7
17d0f3e
36139e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,21 @@ import ( | |
|
||
. "github.com/onsi/ginkgo/v2" //lint:ignore ST1001 Ignoring this for now | ||
. "github.com/onsi/gomega" //lint:ignore ST1001 Ignoring this for now | ||
apiadmissionregistrationv1 "k8s.io/api/admissionregistration/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/utils/pointer" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
"sigs.k8s.io/hierarchical-namespaces/internal/objects" | ||
"sigs.k8s.io/hierarchical-namespaces/internal/webhooks" | ||
|
||
// +kubebuilder:scaffold:imports | ||
|
||
|
@@ -69,8 +76,28 @@ func HNCBeforeSuite() { | |
SetDefaultEventuallyTimeout(time.Second * 4) | ||
|
||
By("configuring test environment") | ||
sideEffectClassNone := apiadmissionregistrationv1.SideEffectClassNone | ||
testEnv = &envtest.Environment{ | ||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, | ||
WebhookInstallOptions: envtest.WebhookInstallOptions{ | ||
ValidatingWebhooks: []*apiadmissionregistrationv1.ValidatingWebhookConfiguration{{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit that this should match what's in the config |
||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: webhooks.ValidatingWebhookConfigurationName, | ||
}, | ||
Webhooks: []apiadmissionregistrationv1.ValidatingWebhook{{ | ||
Name: webhooks.ObjectsWebhookName, | ||
AdmissionReviewVersions: []string{"v1"}, | ||
SideEffects: &sideEffectClassNone, | ||
ClientConfig: apiadmissionregistrationv1.WebhookClientConfig{ | ||
Service: &apiadmissionregistrationv1.ServiceReference{ | ||
Namespace: "system", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike in the config, where you can just say |
||
Name: "webhook-service", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto, should be |
||
Path: pointer.String(objects.ServingPath), | ||
}, | ||
}, | ||
}}, | ||
}}, | ||
}, | ||
} | ||
|
||
By("starting test environment") | ||
|
@@ -94,13 +121,20 @@ func HNCBeforeSuite() { | |
// CF: https://github.com/microsoft/azure-databricks-operator/blob/0f722a710fea06b86ecdccd9455336ca712bf775/controllers/suite_test.go | ||
|
||
By("creating manager") | ||
webhookInstallOptions := &testEnv.WebhookInstallOptions | ||
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{ | ||
NewClient: config.NewClient(false), | ||
MetricsBindAddress: "0", // disable metrics serving since 'go test' runs multiple suites in parallel processes | ||
Scheme: scheme.Scheme, | ||
Host: webhookInstallOptions.LocalServingHost, | ||
Port: webhookInstallOptions.LocalServingPort, | ||
CertDir: webhookInstallOptions.LocalServingCertDir, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// Register a dummy webhook since the test control plane is to test reconcilers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above, if we're allowing everything, why not just not have it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer as above. I think the tests are failing without it. But worth a try. |
||
k8sManager.GetWebhookServer().Register(objects.ServingPath, &webhook.Admission{Handler: &allowAllHandler{}}) | ||
|
||
By("creating reconcilers") | ||
opts := setup.Options{ | ||
MaxReconciles: 100, | ||
|
@@ -125,6 +159,12 @@ func HNCBeforeSuite() { | |
}() | ||
} | ||
|
||
type allowAllHandler struct{} | ||
|
||
func (a allowAllHandler) Handle(_ context.Context, _ admission.Request) admission.Response { | ||
return webhooks.Allow("All requests are allowed by allowAllHandler") | ||
} | ||
|
||
func HNCAfterSuite() { | ||
if k8sManagerCancelFn != nil { | ||
k8sManagerCancelFn() | ||
|
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.
Why do we have any of this? The integ tests never registered webhooks before, I'm not sure why that's changed now?
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 don't remember, but there was probably a reason. I suggest attempting to remove it and see if the tests passes.