From f399e7ecbdd698a2a168bd269943b3b7cd4ae787 Mon Sep 17 00:00:00 2001 From: TheCodeAssassin Date: Tue, 18 Jun 2024 13:30:01 +0200 Subject: [PATCH] added labels to serviceSpec (#202) --- api/v1alpha1/dragonfly_types.go | 5 +++++ api/v1alpha1/zz_generated.deepcopy.go | 8 +++++++- config/crd/bases/dragonflydb.io_dragonflies.yaml | 8 ++++++-- config/rbac/role.yaml | 1 - e2e/dragonfly_controller_test.go | 5 +++++ internal/resources/resources.go | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/api/v1alpha1/dragonfly_types.go b/api/v1alpha1/dragonfly_types.go index e5afaff2..a1ca46f7 100644 --- a/api/v1alpha1/dragonfly_types.go +++ b/api/v1alpha1/dragonfly_types.go @@ -145,6 +145,11 @@ type ServiceSpec struct { // +optional // +kubebuilder:validation:Optional Annotations map[string]string `json:"annotations,omitempty"` + + // (Optional) Dragonfly Service Labels + // +optional + // +kubebuilder:validation:Optional + Labels map[string]string `json:"labels,omitempty"` } type Snapshot struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index b5986276..a29946c6 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* Copyright 2023 DragonflyDB authors. @@ -232,6 +231,13 @@ func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { (*out)[key] = val } } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceSpec. diff --git a/config/crd/bases/dragonflydb.io_dragonflies.yaml b/config/crd/bases/dragonflydb.io_dragonflies.yaml index 1e5ff69b..4d189b71 100644 --- a/config/crd/bases/dragonflydb.io_dragonflies.yaml +++ b/config/crd/bases/dragonflydb.io_dragonflies.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.11.1 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.13.0 name: dragonflies.dragonflydb.io spec: group: dragonflydb.io @@ -1130,6 +1129,11 @@ spec: type: string description: (Optional) Dragonfly Service Annotations type: object + labels: + additionalProperties: + type: string + description: (Optional) Dragonfly Service Labels + type: object name: description: (Optional) Dragonfly Service name type: string diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index c659c23e..e49c6eba 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - creationTimestamp: null name: manager-role rules: - apiGroups: diff --git a/e2e/dragonfly_controller_test.go b/e2e/dragonfly_controller_test.go index db6f7f67..0ec00577 100644 --- a/e2e/dragonfly_controller_test.go +++ b/e2e/dragonfly_controller_test.go @@ -502,10 +502,14 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() newAnnotations := map[string]string{ "service-annotaions": "true", } + newLabels := map[string]string{ + "service-labels": "true", + } df.Spec.ServiceSpec = &resourcesv1.ServiceSpec{ Type: corev1.ServiceTypeLoadBalancer, Name: "test-svc", Annotations: newAnnotations, + Labels: newLabels, } err = k8sClient.Update(ctx, &df) @@ -526,6 +530,7 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() Expect(svc.Spec.Type).To(Equal(corev1.ServiceTypeLoadBalancer)) Expect(svc.Annotations).To(Equal(newAnnotations)) + Expect(svc.Labels).To(Equal(newLabels)) }) It("Cleanup", func() { diff --git a/internal/resources/resources.go b/internal/resources/resources.go index afdaa365..2b142baf 100644 --- a/internal/resources/resources.go +++ b/internal/resources/resources.go @@ -384,6 +384,7 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl if df.Spec.ServiceSpec != nil { service.Spec.Type = df.Spec.ServiceSpec.Type service.Annotations = df.Spec.ServiceSpec.Annotations + service.Labels = df.Spec.ServiceSpec.Labels } if df.Spec.MemcachedPort != 0 { service.Spec.Ports = append(service.Spec.Ports, corev1.ServicePort{