Skip to content

Commit

Permalink
added labels to serviceSpec (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeassassin authored Jun 18, 2024
1 parent 64cfcba commit f399e7e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/dragonfly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 6 additions & 2 deletions config/crd/bases/dragonflydb.io_dragonflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
5 changes: 5 additions & 0 deletions e2e/dragonfly_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f399e7e

Please sign in to comment.