Skip to content

Commit 8c0fa65

Browse files
test fixes
Signed-off-by: James Milligan <[email protected]>
1 parent 630db44 commit 8c0fa65

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

webhooks/pod_webhook.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
126126
}
127127

128128
// Check configuration
129+
ffNames := []string{}
129130
val, ok = pod.GetAnnotations()["openfeature.dev/featureflagconfiguration"]
130-
if !ok {
131-
return admission.Allowed("FeatureFlagConfiguration not found")
131+
if ok {
132+
ffNames = parseList(val)
132133
}
133-
ffNames := parseList(val)
134+
134135
fcNames := []string{}
135136
val, ok = pod.GetAnnotations()["openfeature.dev/flagsourceconfiguration"]
136137
if ok {

webhooks/pod_webhook_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const (
2525
existingPod2ServiceAccountName = "existing-pod-2-service-account"
2626
)
2727

28+
var flagConfig = corev1alpha1.NewFlagSourceConfigurationSpec()
29+
2830
// Sets up environment to simulate an upgrade, with an existing pod already in the cluster
2931
func setupPreviouslyExistingPods() {
3032
ns := &corev1.Namespace{}
@@ -213,17 +215,16 @@ var _ = Describe("pod mutation webhook", func() {
213215
podMutationWebhookCleanup()
214216
})
215217

216-
It("should not create flagd sidecar if openfeature.dev/featureflagconfiguration annotation isn't present", func() {
218+
It("should create flagd sidecar even if openfeature.dev/featureflagconfiguration annotation isn't present", func() {
217219
pod := testPod(defaultPodName, defaultPodServiceAccountName, map[string]string{
218220
"openfeature.dev": "enabled",
219221
})
220-
delete(pod.Annotations, "openfeature.dev/featureflagconfiguration")
221222
err := k8sClient.Create(testCtx, pod)
222223
Expect(err).ShouldNot(HaveOccurred())
223224

224225
pod = getPod(defaultPodName)
225226

226-
Expect(len(pod.Spec.Containers)).To(Equal(1))
227+
Expect(len(pod.Spec.Containers)).To(Equal(2))
227228

228229
podMutationWebhookCleanup()
229230
})
@@ -354,30 +355,30 @@ var _ = Describe("pod mutation webhook", func() {
354355
})
355356

356357
It(`should create flagd sidecar if openfeature.dev/enabled annotation is "true"`, func() {
357-
pod := testPod(map[string]string{
358+
pod := testPod(defaultPodName, defaultPodServiceAccountName, map[string]string{
358359
"openfeature.dev/enabled": "true",
359360
"openfeature.dev/featureflagconfiguration": fmt.Sprintf("%s/%s", mutatePodNamespace, featureFlagConfigurationName),
360361
})
361362
err := k8sClient.Create(testCtx, pod)
362363
Expect(err).ShouldNot(HaveOccurred())
363364

364-
pod = getPod()
365+
pod = getPod(defaultPodName)
365366

366367
Expect(len(pod.Spec.Containers)).To(Equal(2))
367368

368369
podMutationWebhookCleanup()
369370
})
370371

371372
It(`should only write non default flagsourceconfiguration env vars to the flagd container`, func() {
372-
pod := testPod(map[string]string{
373+
pod := testPod(defaultPodName, defaultPodServiceAccountName, map[string]string{
373374
"openfeature.dev": "enabled",
374375
"openfeature.dev/featureflagconfiguration": fmt.Sprintf("%s/%s", mutatePodNamespace, featureFlagConfigurationName),
375376
"openfeature.dev/flagsourceconfiguration": fmt.Sprintf("%s/%s", mutatePodNamespace, flagSourceConfigurationName),
376377
})
377378
err := k8sClient.Create(testCtx, pod)
378379
Expect(err).ShouldNot(HaveOccurred())
379380

380-
pod = getPod()
381+
pod = getPod(defaultPodName)
381382
fmt.Println(pod.Spec.Containers[1])
382383
Expect(pod.Spec.Containers[1].Env).To(Equal([]corev1.EnvVar{
383384
{Name: "FLAGD_METRICS_PORT", Value: "8081"},

0 commit comments

Comments
 (0)