Skip to content

Commit

Permalink
zookeeper - use service with pod-name selector
Browse files Browse the repository at this point in the history
The zookeeper sts is not supposed to scale up. So ensure service can
only redirect traffic to pod-0.

Change-Id: Ie9080d896a2ee7c90c46e29b72b66805d0612888
  • Loading branch information
morucci committed Nov 29, 2023
1 parent 1be7899 commit 7ebb290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 8 additions & 0 deletions controllers/libs/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ func MkHeadlessService(name string, ns string, selector string, ports []int32, p
return service
}

// MkHeadlessServicePod produces a headless service.
func MkHeadlessServicePod(name string, ns string, podName string, ports []int32, portName string) apiv1.Service {
service := MkServicePod(name, ns, podName, ports, portName)
service.ObjectMeta.Name = name + "-headless"
service.Spec.ClusterIP = "None"
return service
}

// MkHTTPSRoute produces a Route on top of a Service
func MkHTTPSRoute(
name string, ns string, host string, serviceName string, path string,
Expand Down
10 changes: 4 additions & 6 deletions controllers/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ func (r *SFController) DeployZookeeper() bool {
},
}

servicePorts := []int32{zkSSLPort}
srv := base.MkService(zkIdent, r.ns, zkIdent, servicePorts, zkIdent)
r.GetOrCreate(&srv)
srv := base.MkServicePod(zkIdent, r.ns, zkIdent+"-0", []int32{zkSSLPort}, zkIdent)
r.EnsureService(&srv)

headlessPorts := []int32{zkSSLPort, zkElectionPort, zkServerPort}
srvZK := base.MkHeadlessService(zkIdent, r.ns, zkIdent, headlessPorts, zkIdent)
r.GetOrCreate(&srvZK)
srvZK := base.MkHeadlessServicePod(zkIdent, r.ns, zkIdent+"-0", []int32{zkSSLPort, zkElectionPort, zkServerPort}, zkIdent)
r.EnsureService(&srvZK)

storageConfig := r.getStorageConfOrDefault(r.cr.Spec.Zookeeper.Storage)
zk := r.mkHeadlessSatefulSet(
Expand Down

0 comments on commit 7ebb290

Please sign in to comment.