Skip to content
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

refactor: remove watches used only by integration tests #891

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions internal/controller/admissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ func (r *AdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPolicyServer),
).
Watches(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPolicyForWebhookConfiguration),
Expand All @@ -108,9 +100,7 @@ func (r *AdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPod(ctx context.Context, object client.Object) []reconcile.Request {
return findPoliciesForPod(ctx, r.Client, object)
}
func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
return findPoliciesForPolicyServer(ctx, r.Client, object, r.DeploymentsNamespace)
}

func (r *AdmissionPolicyReconciler) findAdmissionPolicyForWebhookConfiguration(_ context.Context, webhookConfiguration client.Object) []reconcile.Request {
return findPolicyForWebhookConfiguration(webhookConfiguration, r.Log)
}
12 changes: 0 additions & 12 deletions internal/controller/admissionpolicygroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ func (r *AdmissionPolicyGroupReconciler) SetupWithManager(mgr ctrl.Manager) erro
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPoliciesForPolicyServer),
).
Watches(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
handler.EnqueueRequestsFromMapFunc(r.findAdmissionPolicyForWebhookConfiguration),
Expand All @@ -105,10 +97,6 @@ func (r *AdmissionPolicyGroupReconciler) findAdmissionPoliciesForPod(ctx context
return findPoliciesForPod(ctx, r.Client, object)
}

func (r *AdmissionPolicyGroupReconciler) findAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
return findPoliciesForPolicyServer(ctx, r.Client, object, r.DeploymentsNamespace)
}

func (r *AdmissionPolicyGroupReconciler) findAdmissionPolicyForWebhookConfiguration(_ context.Context, webhookConfiguration client.Object) []reconcile.Request {
return findPolicyForWebhookConfiguration(webhookConfiguration, r.Log)
}
12 changes: 1 addition & 11 deletions internal/controller/clusteradmissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ func (r *ClusterAdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) er
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPolicyServer),
).
Watches(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPolicyForWebhookConfiguration),
Expand All @@ -107,9 +99,7 @@ func (r *ClusterAdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) er
func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPod(ctx context.Context, object client.Object) []reconcile.Request {
return findClusterPoliciesForPod(ctx, r.Client, object)
}
func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
return findClusterPoliciesForPolicyServer(ctx, r.Client, object, r.DeploymentsNamespace)
}

func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPolicyForWebhookConfiguration(_ context.Context, webhookConfiguration client.Object) []reconcile.Request {
return findClusterPolicyForWebhookConfiguration(webhookConfiguration, r.Log)
}
12 changes: 1 addition & 11 deletions internal/controller/clusteradmissionpolicygroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ func (r *ClusterAdmissionPolicyGroupReconciler) SetupWithManager(mgr ctrl.Manage
&corev1.Pod{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPod),
).
// Despite this policy server watch is not strictly necessary, we
// include it for the integration tests, so that we identify
// policy server creations even when the controller-manager is not
// present (so no pods end up being created)
Watches(
&policiesv1.PolicyServer{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPoliciesForPolicyServer),
).
Watches(
&admissionregistrationv1.ValidatingWebhookConfiguration{},
handler.EnqueueRequestsFromMapFunc(r.findClusterAdmissionPolicyForWebhookConfiguration),
Expand All @@ -103,9 +95,7 @@ func (r *ClusterAdmissionPolicyGroupReconciler) SetupWithManager(mgr ctrl.Manage
func (r *ClusterAdmissionPolicyGroupReconciler) findClusterAdmissionPoliciesForPod(ctx context.Context, object client.Object) []reconcile.Request {
return findClusterPoliciesForPod(ctx, r.Client, object)
}
func (r *ClusterAdmissionPolicyGroupReconciler) findClusterAdmissionPoliciesForPolicyServer(ctx context.Context, object client.Object) []reconcile.Request {
return findClusterPoliciesForPolicyServer(ctx, r.Client, object, r.DeploymentsNamespace)
}

func (r *ClusterAdmissionPolicyGroupReconciler) findClusterAdmissionPolicyForWebhookConfiguration(_ context.Context, webhookConfiguration client.Object) []reconcile.Request {
return findClusterPolicyForWebhookConfiguration(webhookConfiguration, r.Log)
}
34 changes: 0 additions & 34 deletions internal/controller/policy_subreconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,23 +349,6 @@ func findClusterPoliciesForPod(ctx context.Context, k8sClient client.Client, obj
return findClusterPoliciesForConfigMap(&configMap)
}

func findClusterPoliciesForPolicyServer(ctx context.Context, k8sClient client.Client, object client.Object, namespace string) []reconcile.Request {
policyServer, ok := object.(*policiesv1.PolicyServer)
if !ok {
return []reconcile.Request{}
}
policyServerDeploymentName := policyServerDeploymentName(policyServer.Name)
configMap := corev1.ConfigMap{}
err := k8sClient.Get(ctx, client.ObjectKey{
Namespace: namespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
if err != nil {
return []reconcile.Request{}
}
return findClusterPoliciesForConfigMap(&configMap)
}

func findClusterPolicyForWebhookConfiguration(webhookConfiguration client.Object, log logr.Logger) []reconcile.Request {
// Pre v1.16.0
_, kubwardenLabelExists := webhookConfiguration.GetLabels()["kubewarden"]
Expand Down Expand Up @@ -403,23 +386,6 @@ func findClusterPolicyForWebhookConfiguration(webhookConfiguration client.Object
}
}

func findPoliciesForPolicyServer(ctx context.Context, k8sClient client.Client, object client.Object, namespace string) []reconcile.Request {
policyServer, ok := object.(*policiesv1.PolicyServer)
if !ok {
return []reconcile.Request{}
}
policyServerDeploymentName := policyServerDeploymentName(policyServer.Name)
configMap := corev1.ConfigMap{}
err := k8sClient.Get(ctx, client.ObjectKey{
Namespace: namespace,
Name: policyServerDeploymentName, // As the deployment name matches the name of the ConfigMap
}, &configMap)
if err != nil {
return []reconcile.Request{}
}
return findPoliciesForConfigMap(&configMap)
}

func findPolicyForWebhookConfiguration(webhookConfiguration client.Object, log logr.Logger) []reconcile.Request {
// Pre v1.16.0
_, kubwardenLabelExists := webhookConfiguration.GetLabels()["kubewarden"]
Expand Down
Loading