Skip to content

LoadBalancer Kill Switch #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 20, 2025
Merged
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
23 changes: 21 additions & 2 deletions api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (
SpiloRoleLabelValueMaster = "master"
SpiloRoleLabelValueStandbyLeader = "standby_leader"
StatefulsetPodNameLabelName = "statefulset.kubernetes.io/pod-name"
ClusterNameLabelName = "cluster-name"

teamIDPrefix = "pg"

Expand All @@ -84,6 +85,7 @@ const (
defaultPostgresParamValueWalKeepSegments = "64"
defaultPostgresParamValueWalKeepSize = "1GB"
defaultPostgresParamValuePGStatStatementsMax = "500"
defaultSelectorDisableValue = "selector-disabled"
defaultPostgresParamValuePasswordEncryption = "scram-sha-256" // nolint
defaultPostgresParamValueLogMinErrorStatement = "WARNING"
defaultPostgresParamValueLogErrorVerbosity = "VERBOSE"
Expand Down Expand Up @@ -211,6 +213,9 @@ type PostgresSpec struct {

// DedicatedLoadBalancerPort The port to use for the load balancer
DedicatedLoadBalancerPort *int32 `json:"dedicatedLoadBalancerPort,omitempty"`

// DisableLoadBalancers enable or disable the Load Balancers (Services)
DisableLoadBalancers *bool `json:"disableLoadBalancers,omitempty"`
}

// AccessList defines the type of restrictions to access the database
Expand Down Expand Up @@ -385,7 +390,7 @@ func (p *Postgres) ToSharedSvcLB(lbIP string, lbPort int32, enableStandbyLeaderS

lb.Spec.Selector = map[string]string{
ApplicationLabelName: ApplicationLabelValue,
"cluster-name": p.ToPeripheralResourceName(),
ClusterNameLabelName: p.ToPeripheralResourceName(),
"team": p.generateTeamID(),
}
if p.IsReplicationPrimaryOrStandalone() {
Expand All @@ -401,6 +406,9 @@ func (p *Postgres) ToSharedSvcLB(lbIP string, lbPort int32, enableStandbyLeaderS
lb.Spec.Selector[StatefulsetPodNameLabelName] = p.ToPeripheralResourceName() + "-0"
}
}
if p.DisableLoadBalancers() {
lb.Spec.Selector[ClusterNameLabelName] = defaultSelectorDisableValue
}

if len(lbIP) > 0 {
// if no ip is set, a new loadbalancer will be created automatically
Expand Down Expand Up @@ -479,7 +487,7 @@ func (p *Postgres) ToDedicatedSvcLB(lbIP string, lbPort int32, standbyClustersSo

lb.Spec.Selector = map[string]string{
ApplicationLabelName: ApplicationLabelValue,
"cluster-name": p.ToPeripheralResourceName(),
ClusterNameLabelName: p.ToPeripheralResourceName(),
"team": p.generateTeamID(),
}
if p.IsReplicationPrimaryOrStandalone() {
Expand All @@ -488,6 +496,9 @@ func (p *Postgres) ToDedicatedSvcLB(lbIP string, lbPort int32, standbyClustersSo
// select the first pod in the statefulset
lb.Spec.Selector[StatefulsetPodNameLabelName] = p.ToPeripheralResourceName() + "-0"
}
if p.DisableLoadBalancers() {
lb.Spec.Selector[ClusterNameLabelName] = defaultSelectorDisableValue
}

if len(lbIP) > 0 {
lb.Spec.LoadBalancerIP = lbIP
Expand Down Expand Up @@ -1068,3 +1079,11 @@ func (p *Postgres) ToStandbyClusterEgressCWNP() (*firewall.ClusterwideNetworkPol

return standbyEgressCWNP, nil
}

func (p *Postgres) DisableLoadBalancers() bool {
if p.Spec.DisableLoadBalancers == nil {
return false
}

return *p.Spec.DisableLoadBalancers
}
5 changes: 5 additions & 0 deletions api/v1/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/database.fits.cloud_postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ spec:
description:
description: Description
type: string
disableLoadBalancers:
description: DisableLoadBalancers enable or disable the Load Balancers
(Services)
type: boolean
maintenance:
description: |-
todo: add default
Expand Down
Loading