Skip to content

Commit 9786ecd

Browse files
committed
Allow NodePort type for master service
This commit introduces new property to a postgresql spec serviceNodePort. It enable NodePort type service for master role with automatic port allocation if value is 0. Othewise it takes desired port number like 30025. fixes: #983 Signed-off-by: Dinar Valeev <k0da@opensuse.org>
1 parent 3a49b48 commit 9786ecd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/apis/acid.zalan.do/v1/postgresql_type.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type PostgresSpec struct {
4242
EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"`
4343
EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"`
4444

45+
// User nodeport as service type
46+
ServiceNodePort *int32 `json:"serviceNodePort,omitempty"`
4547
// deprecated load balancer settings maintained for backward compatibility
4648
// see "Load balancers" operator docs
4749
UseLoadBalancer *bool `json:"useLoadBalancer,omitempty"`

pkg/cluster/k8sres.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,13 @@ func (c *Cluster) generateService(role PostgresRole, spec *acidv1.PostgresSpec)
15311531
Type: v1.ServiceTypeClusterIP,
15321532
}
15331533

1534+
if spec.ServiceNodePort != nil && role == Master {
1535+
serviceSpec.Type = v1.ServiceTypeNodePort
1536+
if *spec.ServiceNodePort > 0 {
1537+
servicePort := &serviceSpec
1538+
servicePort.Ports[0].NodePort = *spec.ServiceNodePort
1539+
}
1540+
}
15341541
if role == Replica || c.patroniKubernetesUseConfigMaps() {
15351542
serviceSpec.Selector = c.roleLabelsSet(false, role)
15361543
}

0 commit comments

Comments
 (0)