Skip to content

Commit 55c2822

Browse files
authored
updated owner ref on hook (#22)
* updated owner ref on hook * Update manager.yaml This has been moved to /webhooks/certificate.yaml due to a bug in the webhook timeout with cert-manager need a separate call * blocks static pods
1 parent 8d0742b commit 55c2822

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ kind: Kustomization
1313
images:
1414
- name: controller
1515
newName: tibbar/of-operator
16-
newTag: v0.0.2.1
16+
newTag: v0.0.3

config/manager/manager.yaml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,3 @@ spec:
5858
memory: 64Mi
5959
serviceAccountName: controller-manager
6060
terminationGracePeriodSeconds: 10
61-
---
62-
apiVersion: cert-manager.io/v1
63-
kind: Issuer
64-
metadata:
65-
name: open-feature-operator-selfsigned-issuer
66-
namespace: open-feature-operator-system
67-
spec:
68-
selfSigned: {}
69-
---
70-
apiVersion: cert-manager.io/v1
71-
kind: Certificate
72-
metadata:
73-
name: webhook-cert
74-
namespace: open-feature-operator-system
75-
spec:
76-
secretName: sidecar-injector-certs
77-
dnsNames:
78-
- open-feature-operator-webhook-service
79-
- open-feature-operator-webhook-service.open-feature-operator-system.svc
80-
- open-feature-operator-webhook-service.open-feature-operator-system.svc.cluster.local
81-
issuerRef:
82-
name: open-feature-operator-selfsigned-issuer

webhooks/mutating_admission_webhook.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
4242
return admission.Allowed("openfeature is disabled")
4343
}
4444
}
45+
// Check if the pod is static or orphaned
46+
name := pod.Name
47+
if len(pod.GetOwnerReferences()) != 0 {
48+
name = pod.GetOwnerReferences()[0].Name
49+
} else {
50+
return admission.Denied("static or orphaned pods cannot be mutated")
51+
}
52+
4553
var featureFlagCustomResource corev1alpha1.FeatureFlagConfiguration
4654
// Check CustomResource
4755
val, ok = pod.GetAnnotations()["openfeature.dev/featureflagconfiguration"]
@@ -50,17 +58,13 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
5058
} else {
5159
// Current limitation is to use the same namespace, this is easy to fix though
5260
// e.g. namespace/name check
53-
err = m.Client.Get(context.TODO(), client.ObjectKey{Name: val, Namespace: req.Namespace},
61+
err = m.Client.Get(context.TODO(), client.ObjectKey{Name: val,
62+
Namespace: req.Namespace},
5463
&featureFlagCustomResource)
5564
if err != nil {
5665
return admission.Denied("FeatureFlagConfiguration not found")
5766
}
5867
}
59-
name := pod.Name
60-
if len(pod.GetOwnerReferences()) != 0 {
61-
name = pod.GetOwnerReferences()[0].Name
62-
}
63-
6468
// TODO: this should be a short sha to avoid collisions
6569
configName := name
6670
// Create the agent configmap
@@ -70,6 +74,7 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
7074
Namespace: req.Namespace,
7175
},
7276
}) // Delete the configmap if it exists
77+
7378
m.Log.V(1).Info(fmt.Sprintf("Creating configmap %s", configName))
7479
if err := m.Client.Create(ctx, &corev1.ConfigMap{
7580
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)