Skip to content

Commit

Permalink
fix: limit webhook patch to Liqo webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiolor committed Jan 22, 2025
1 parent e621593 commit 82f3ca0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/consts/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ const (
// VirtualNodeTolerationKey all Pods that have to be scheduled on virtual nodes must have this toleration
// to Liqo taint.
VirtualNodeTolerationKey = "virtual-node.liqo.io/not-allowed"

// WebHookLabel used to mark the resouces related to the Liqo webhooks.
WebHookLabel = "liqo.io/webhook"

// WebHookLabelValue is the value of the label used to identify Liqo webhooks.
WebHookLabelValue = "true"
)
12 changes: 10 additions & 2 deletions pkg/webhooks/secretcontroller/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -161,9 +162,16 @@ func HandleSecret(ctx context.Context, cl client.Client, secret *corev1.Secret)
}

// patch webhook configurations
whListOptions := client.ListOptions{
LabelSelector: client.MatchingLabelsSelector{
Selector: labels.SelectorFromSet(map[string]string{
consts.WebHookLabel: consts.WebHookLabelValue,
}),
},
}

var mwhcList adminssionregistrationv1.MutatingWebhookConfigurationList
if err := cl.List(ctx, &mwhcList); err != nil {
if err := cl.List(ctx, &mwhcList, &whListOptions); err != nil {
return fmt.Errorf("unable to list MutatingWebhookConfigurations: %w", err)
}

Expand All @@ -180,7 +188,7 @@ func HandleSecret(ctx context.Context, cl client.Client, secret *corev1.Secret)
}

var vwhcList adminssionregistrationv1.ValidatingWebhookConfigurationList
if err := cl.List(ctx, &vwhcList); err != nil {
if err := cl.List(ctx, &vwhcList, &whListOptions); err != nil {
return fmt.Errorf("unable to list ValidatingWebhookConfigurations: %w", err)
}

Expand Down

0 comments on commit 82f3ca0

Please sign in to comment.