@@ -275,6 +275,21 @@ func TestPodMutator_Handle(t *testing.T) {
275
275
goodInProcessAnnotatedPod , err := json .Marshal (inProcessPod )
276
276
require .Nil (t , err )
277
277
278
+ missingAnnotationPod := corev1.Pod {
279
+ ObjectMeta : metav1.ObjectMeta {
280
+ Name : "myNotAnnotatedPod" ,
281
+ Namespace : mutatePodNamespace ,
282
+ Annotations : map [string ]string {
283
+ fmt .Sprintf ("%s/%s" , common .OpenFeatureAnnotationPrefix , common .EnabledAnnotation ): "true" ,
284
+ },
285
+ OwnerReferences : []metav1.OwnerReference {{UID : "123" }},
286
+ },
287
+ Spec : corev1.PodSpec {ServiceAccountName : defaultPodServiceAccountName },
288
+ }
289
+
290
+ missingPod , err := json .Marshal (missingAnnotationPod )
291
+ require .Nil (t , err )
292
+
278
293
tests := []struct {
279
294
name string
280
295
mutator * PodMutator
@@ -523,6 +538,47 @@ func TestPodMutator_Handle(t *testing.T) {
523
538
},
524
539
allow : true ,
525
540
},
541
+ {
542
+ name : "ofo enabled but annotation missing" ,
543
+ mutator : & PodMutator {
544
+ Client : NewClient (true ,
545
+ & inProcessPod ,
546
+ & corev1.ServiceAccount {
547
+ ObjectMeta : metav1.ObjectMeta {
548
+ Name : defaultPodServiceAccountName ,
549
+ Namespace : mutatePodNamespace ,
550
+ },
551
+ },
552
+ & rbac.ClusterRoleBinding {
553
+ ObjectMeta : metav1.ObjectMeta {Name : common .ClusterRoleBindingName },
554
+ Subjects : nil ,
555
+ RoleRef : rbac.RoleRef {},
556
+ },
557
+ ),
558
+ decoder : decoder ,
559
+ Log : testr .New (t ),
560
+ },
561
+ req : admission.Request {
562
+ AdmissionRequest : admissionv1.AdmissionRequest {
563
+ UID : "123" ,
564
+ Object : runtime.RawExtension {
565
+ Raw : missingPod ,
566
+ Object : & missingAnnotationPod ,
567
+ },
568
+ },
569
+ },
570
+ setup : func (mockInjector * flagdinjectorfake.MockFlagdContainerInjector ) {
571
+ mockInjector .EXPECT ().
572
+ InjectFlagd (
573
+ gomock .Any (),
574
+ gomock .Any (),
575
+ gomock .Any (),
576
+ gomock .Any (),
577
+ ).Return (nil ).Times (0 )
578
+ },
579
+ wantCode : http .StatusForbidden ,
580
+ allow : false ,
581
+ },
526
582
{
527
583
name : "wrong request" ,
528
584
mutator : & PodMutator {
0 commit comments