Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Display Go version
run: go version
- name: Check that all autogenerated files are up to date
run: make manifests generate && git diff --quiet HEAD --
run: make manifests generate && git diff HEAD --
- name: Check that all docs are up to date
run: make docs && git diff --quiet HEAD --
run: make docs && git diff HEAD --
- name: Unit Test
run: make test
1 change: 1 addition & 0 deletions api/v1beta1/questdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type QuestDBSpec struct {
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
PodSecurityContext v1.PodSecurityContext `json:"podSecurityContext,omitempty"`
Resources v1.ResourceRequirements `json:"resources,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
StatefulSetAnnotations map[string]string `json:"statefulSetAnnotations,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
}
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/crd.questdb.io_questdbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,10 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
serviceAnnotations:
additionalProperties:
type: string
type: object
statefulSetAnnotations:
additionalProperties:
type: string
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: questdb/questdb-operator
newTag: v0.0.0
newTag: v0.5.1
1 change: 1 addition & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ _Appears in:_
| `podAnnotations` _object (keys:string, values:string)_ | |
| `podSecurityContext` _[PodSecurityContext](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#podsecuritycontext-v1-core)_ | |
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#resourcerequirements-v1-core)_ | |
| `serviceAnnotations` _object (keys:string, values:string)_ | |
| `statefulSetAnnotations` _object (keys:string, values:string)_ | |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#toleration-v1-core) array_ | |

Expand Down
24 changes: 20 additions & 4 deletions internal/controller/questdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ func (r *QuestDBReconciler) reconcileStatefulSet(ctx context.Context, q *crdv1be
func (r *QuestDBReconciler) buildService(q *crdv1beta1.QuestDB) v1.Service {
svc := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: q.Name,
Namespace: q.Namespace,
Labels: q.Labels,
Name: q.Name,
Namespace: q.Namespace,
Labels: q.Labels,
Annotations: q.Spec.ServiceAnnotations,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand Down Expand Up @@ -391,7 +392,8 @@ func (r *QuestDBReconciler) buildService(q *crdv1beta1.QuestDB) v1.Service {

func (r *QuestDBReconciler) reconcileService(ctx context.Context, q *crdv1beta1.QuestDB) error {
var (
err error
err error
needsUpdate bool

actual = &v1.Service{}
desired = r.buildService(q)
Expand All @@ -410,7 +412,21 @@ func (r *QuestDBReconciler) reconcileService(ctx context.Context, q *crdv1beta1.
*actual = desired
}

if !reflect.DeepEqual(actual.Annotations, desired.Annotations) {
actual.Annotations = desired.Annotations
needsUpdate = true
}

if needsUpdate {
if err = r.Update(ctx, actual); err != nil {
r.Recorder.Event(q, v1.EventTypeWarning, "ServiceUpdateFailed", err.Error())
return err
}
r.Recorder.Event(q, v1.EventTypeNormal, "ServiceUpdated", "Service updated")
}

return nil

}

func (r *QuestDBReconciler) buildPvc(q *crdv1beta1.QuestDB) v1.PersistentVolumeClaim {
Expand Down
30 changes: 27 additions & 3 deletions internal/controller/questdb_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ var _ = Describe("QuestDB Controller", func() {

})

Context("port allocation", func() {
Context("service updates", func() {
var (
q *crdv1beta1.QuestDB
q *crdv1beta1.QuestDB
svc = &v1.Service{}
)
BeforeEach(func() {
By("Creating a new QuestDB")
Expand All @@ -100,7 +101,6 @@ var _ = Describe("QuestDB Controller", func() {
}, timeout, interval).Should(Succeed())

By("Check the service port values")
svc := &v1.Service{}
Eventually(func() error {
return k8sClient.Get(ctx, client.ObjectKey{Name: q.Name, Namespace: q.Namespace}, svc)
}, timeout, interval).Should(Succeed())
Expand All @@ -127,6 +127,30 @@ var _ = Describe("QuestDB Controller", func() {
))
})

It("should update the service annotations if they change", func() {
By("Getting the service and ensuring that there are no annotations")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: q.Name, Namespace: q.Namespace}, svc)).Should(Succeed())
g.Expect(svc.Annotations).Should(BeEmpty())
}, timeout, interval).Should(Succeed())

By("Adding a service annotation")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(q), q)).To(Succeed())
q.Spec.ServiceAnnotations = map[string]string{
"test-key": "test-value",
}
g.Expect(k8sClient.Update(ctx, q)).To(Succeed())
}, timeout, interval).Should(Succeed())

By("Verifying that the service has been updated")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKey{Name: q.Name, Namespace: q.Namespace}, svc)).Should(Succeed())
g.Expect(svc.Annotations).ShouldNot(BeEmpty())
g.Expect(svc.Annotations).Should(HaveKeyWithValue("test-key", "test-value"))
}, timeout, interval).Should(Succeed())
})

})

Context("statefulset updated", func() {
Expand Down