Skip to content

Commit

Permalink
feat(service): add support for custom service name (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhra303 authored May 29, 2024
1 parent d50c4e3 commit 3991ffa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/dragonfly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ type ServiceSpec struct {
// +kubebuilder:validation:Optional
Type corev1.ServiceType `json:"type,omitempty"`

// (Optional) Dragonfly Service name
// +optional
// +kubebuilder:validation:Optional
Name string `json:"name,omitempty"`

// (Optional) Dragonfly Service Annotations
// +optional
// +kubebuilder:validation:Optional
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/dragonflydb.io_dragonflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ spec:
type: string
description: (Optional) Dragonfly Service Annotations
type: object
name:
description: (Optional) Dragonfly Service name
type: string
type:
description: (Optional) Dragonfly Service type
type: string
Expand Down
3 changes: 2 additions & 1 deletion e2e/dragonfly_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func()
}
df.Spec.ServiceSpec = &resourcesv1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Name: "test-svc",
Annotations: newAnnotations,
}

Expand All @@ -518,7 +519,7 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func()

var svc corev1.Service
err = k8sClient.Get(ctx, types.NamespacedName{
Name: name,
Name: "test-svc",
Namespace: namespace,
}, &svc)
Expect(err).To(BeNil())
Expand Down
7 changes: 6 additions & 1 deletion internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,14 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl

resources = append(resources, &statefulset)

serviceName := df.Name
if df.Spec.ServiceSpec != nil && df.Spec.ServiceSpec.Name != "" {
serviceName = df.Spec.ServiceSpec.Name
}

service := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: df.Name,
Name: serviceName,
Namespace: df.Namespace,
// Useful for automatically deleting the resources when the Dragonfly object is deleted
OwnerReferences: []metav1.OwnerReference{
Expand Down

0 comments on commit 3991ffa

Please sign in to comment.