Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit c9133c5

Browse files
update template
1 parent 108c403 commit c9133c5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

config/component-templates/nested-etcd/nested-etcd-statefulset-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
- --peer-key-file=/etc/kubernetes/pki/etcd/tls.key
4444
- --listen-peer-urls=https://0.0.0.0:2380
4545
- --listen-client-urls=https://0.0.0.0:2379
46-
- --initial-advertise-peer-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2380
46+
# - --initial-advertise-peer-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2380
4747
# we use a headless service to encapsulate each pod
4848
- --advertise-client-urls=https://$(HOSTNAME).{{.nestedetcdName}}:2379
4949
- --initial-cluster-state=new

controllers/controlplane/nestedetcd_controller.go

+21
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ func createNestedEtcdStatefulSet(ctx context.Context, cli ctrlcli.Client,
195195
}
196196
netcdSts = stsObj
197197
log.Info("convert runtime object to StatefulSet.")
198+
// icaVal := genInitialClusterArgs(1, netcd.GetName(), netcd.GetName())
199+
// stsArgs := append(netcdSts.Spec.Template.Spec.Containers[0].Args, "--initial-cluster", icaVal)
200+
// netcdSts.Spec.Template.Spec.Containers[0].Args = stsArgs
201+
// log.Info("set the '--initial-cluster' opt")
198202

199203
defaultSvcTmpl, err := fetchTemplate(defaultServiceURL)
200204
if err != nil {
@@ -385,6 +389,23 @@ func getOwner(netcd controlplanev1alpha4.NestedEtcd) metav1.OwnerReference {
385389
return metav1.OwnerReference{}
386390
}
387391

392+
// genInitialClusterArgs generates the values for `--inital-cluster` option of etcd based on the number of
393+
// replicas specified in etcd StatefulSet
394+
func genInitialClusterArgs(replicas int32, stsName, svcName string) (argsVal string) {
395+
for i := int32(0); i < replicas; i++ {
396+
// use 2380 as the default port for etcd peer communication
397+
peerAddr := fmt.Sprintf("%s-%d=https://%s-%d.%s:%d",
398+
stsName, i, stsName, i, svcName, 2380)
399+
if i == replicas-1 {
400+
argsVal = argsVal + peerAddr
401+
break
402+
}
403+
argsVal = argsVal + peerAddr + ","
404+
}
405+
406+
return argsVal
407+
}
408+
388409
// SetupWithManager sets up the controller with the Manager.
389410
func (r *NestedEtcdReconciler) SetupWithManager(mgr ctrl.Manager) error {
390411
if err := mgr.GetFieldIndexer().IndexField(context.TODO(),

0 commit comments

Comments
 (0)