Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix webhook
  • Loading branch information
sklarsa committed Aug 6, 2023
commit 15474ddb3ae817d9e3b712a57fdc8a1da1b173b6
12 changes: 7 additions & 5 deletions api/v1beta1/questdb_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ var _ webhook.Defaulter = &QuestDB{}
func (r *QuestDB) Default() {
questdblog.Info("default", "name", r.Name)

// TODO(user): fill in your defaulting logic.
if r.Spec.ImagePullPolicy == v1.PullPolicy("") {
r.Spec.ImagePullPolicy = v1.PullIfNotPresent
}
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
Expand Down Expand Up @@ -108,10 +110,6 @@ func (r *QuestDB) ValidateCreate() error {
return err
}

if r.Spec.ImagePullPolicy == v1.PullPolicy("") {
r.Spec.ImagePullPolicy = v1.PullIfNotPresent
}

return nil
}

Expand Down Expand Up @@ -157,6 +155,10 @@ func (r *QuestDB) ValidateUpdate(old runtime.Object) error {
return errors.New("cannot change storage class name")
}

if r.Spec.ImagePullPolicy == "" {
return errors.New("image pull policy cannot be empty")
}

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions api/v1beta1/questdb_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -73,6 +74,12 @@ var _ = Describe("QuestDB Webhook", func() {
}
Expect(k8sClient.Create(ctx, q)).ToNot(Succeed())
})

It("should handle an empty image pull policy", func() {
q.Spec.ImagePullPolicy = ""
Expect(k8sClient.Create(ctx, q)).To(Succeed())
Expect(q.Spec.ImagePullPolicy).To(Equal(v1.PullIfNotPresent))
})
})

Context("When validating QuestDB Updates", func() {
Expand Down Expand Up @@ -136,6 +143,7 @@ var _ = Describe("QuestDB Webhook", func() {
q.Spec.Volume.SnapshotName = "foo"
Expect(k8sClient.Update(ctx, q)).ToNot(Succeed())
})

})

})
4 changes: 2 additions & 2 deletions internal/controller/questdb_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ var _ = Describe("QuestDB Controller", func() {
By("Changing the image pull policy")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(q), q)).To(Succeed())
q.Spec.ImagePullPolicy = "Always"
q.Spec.ImagePullPolicy = v1.PullAlways
g.Expect(k8sClient.Update(ctx, q)).To(Succeed())
}, timeout, interval).Should(Succeed())

By("Verifying the statefulset has been updated")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: q.Name, Namespace: q.Namespace}, sts)).To(Succeed())
g.Expect(sts.Spec.Template.Spec.Containers[0].ImagePullPolicy).To(Equal("Always"))
g.Expect(sts.Spec.Template.Spec.Containers[0].ImagePullPolicy).To(Equal(v1.PullAlways))
}, timeout, interval).Should(Succeed())
})
})
Expand Down