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

feat(agent): add object selector for pod webhook #1018

Merged
merged 1 commit into from
Jan 16, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:4.0.0-dev
createdAt: "2025-01-14T22:32:19Z"
createdAt: "2025-01-16T19:04:11Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down Expand Up @@ -1234,6 +1234,12 @@ spec:
deploymentName: cryostat-operator-controller
failurePolicy: Ignore
generateName: mpod.cryostat.io
objectSelector:
matchExpressions:
- key: cryostat.io/name
operator: Exists
- key: cryostat.io/namespace
operator: Exists
rules:
- apiGroups:
- ""
Expand Down
1 change: 1 addition & 0 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ patchesStrategicMerge:
- image_pull_patch.yaml
- manager_webhook_patch.yaml
- webhookcainjection_patch.yaml
- webhook_object_selector_patch.yaml

# the following config is for teaching kustomize how to do var substitution
apiVersion: kustomize.config.k8s.io/v1beta1
Expand Down
12 changes: 12 additions & 0 deletions config/default/webhook_object_selector_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: mutating-webhook-configuration
webhooks:
- name: mpod.cryostat.io
objectSelector:
matchExpressions:
- key: cryostat.io/name
operator: Exists
- key: cryostat.io/namespace
operator: Exists
5 changes: 3 additions & 2 deletions internal/webhooks/agent/pod_defaulter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ func (r *podMutator) Default(ctx context.Context, obj runtime.Object) error {
return fmt.Errorf("expected a Pod, but received a %T", obj)
}

// TODO do this with objectSelector: https://github.com/kubernetes-sigs/controller-tools/issues/553
// Check for required labels and return early if missing
// Check for required labels and return early if missing.
// This should not happen because such pods are filtered out by Kubernetes server-side due to our object selector.
if !metav1.HasLabel(pod.ObjectMeta, constants.AgentLabelCryostatName) || !metav1.HasLabel(pod.ObjectMeta, constants.AgentLabelCryostatNamespace) {
r.log.Info("pod is missing required labels")
return nil
}

Expand Down
Loading