Skip to content

Commit

Permalink
feat(crd): introduce loadbalancer config
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhra303 committed Oct 27, 2023
1 parent 7cf5b4b commit 0bb90ab
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/v1alpha1/dragonfly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ type DragonflySpec struct {
// +optional
// +kubebuilder:validation:Optional
Snapshot *Snapshot `json:"snapshot,omitempty"`

// (Optional) Dragonfly LoadBalancer configuration
// +optional
// +kubebuilder:validation:Optional
LoadBalancerSpec *LoadBalancerService `json:"loadbalancerSpec,omitempty"`
}

type LoadBalancerService struct {
Enabled bool `json:"enabled,omitempty"`

// (Optional) Dragonfly LoadBalancerIP
// +optional
// +kubebuilder:validation:Optional
ServiceIp string `json:"serviceIp,omitempty"`

// (Optional) Dragonfly LoadBalancerSourceRanges
// +optional
// +kubebuilder:validation:Optional
SourceRanges []string `json:"sourceRanges,omitempty"`

// (Optional) Dragonfly LoadBalancerClass
// +optional
// +kubebuilder:validation:Optional
Class string `json:"class,omitempty"`
}

type Snapshot struct {
Expand Down
17 changes: 17 additions & 0 deletions config/crd/bases/dragonflydb.io_dragonflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,23 @@ spec:
image:
description: Image is the Dragonfly image to use
type: string
loadbalancerSpec:
description: (Optional) Dragonfly LoadBalancer configuration
properties:
class:
description: (Optional) Dragonfly snapshot schedule
type: string
enabled:
type: boolean
serviceIp:
description: (Optional) Dragonfly snapshot schedule
type: string
sourceRanges:
description: (Optional) Dragonfly snapshot schedule
items:
type: string
type: array
type: object
replicas:
description: Replicas is the total number of Dragonfly instances including
the master
Expand Down
14 changes: 14 additions & 0 deletions internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl
},
}

if df.Spec.LoadBalancerSpec != nil && df.Spec.LoadBalancerSpec.Enabled {
service.Spec.Type = corev1.ServiceTypeLoadBalancer

if df.Spec.LoadBalancerSpec.ServiceIp != "" {
service.Spec.LoadBalancerIP = df.Spec.LoadBalancerSpec.ServiceIp
}
if len(df.Spec.LoadBalancerSpec.SourceRanges) != 0 {
service.Spec.LoadBalancerSourceRanges = df.Spec.LoadBalancerSpec.SourceRanges
}
if df.Spec.LoadBalancerSpec.Class != "" {
service.Spec.LoadBalancerClass = &df.Spec.LoadBalancerSpec.Class
}
}

resources = append(resources, &service)

return resources, nil
Expand Down

0 comments on commit 0bb90ab

Please sign in to comment.