From e8ba79aae6e14f5b70daf30febf3e31bbf795a58 Mon Sep 17 00:00:00 2001 From: Howard Lau Date: Fri, 30 Oct 2020 09:15:16 +0000 Subject: [PATCH 1/2] add filer peers on filer startup Signed-off-by: Howard Lau --- controllers/controller_filer_statefulset.go | 1 + controllers/helper.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/controllers/controller_filer_statefulset.go b/controllers/controller_filer_statefulset.go index 5de5557..71ae7ec 100644 --- a/controllers/controller_filer_statefulset.go +++ b/controllers/controller_filer_statefulset.go @@ -16,6 +16,7 @@ func buildFilerStartupScript(m *seaweedv1.Seaweed) string { commands := []string{"weed", "filer"} commands = append(commands, fmt.Sprintf("-port=%d", seaweedv1.FilerHTTPPort)) commands = append(commands, fmt.Sprintf("-ip=$(POD_NAME).%s-filer-peer", m.Name)) + commands = append(commands, fmt.Sprintf("-peers=%s", getFilerPeersString(m.Name, m.Spec.Volume.Replicas))) commands = append(commands, fmt.Sprintf("-master=%s", getMasterPeersString(m.Name, m.Spec.Master.Replicas))) commands = append(commands, "-s3") diff --git a/controllers/helper.go b/controllers/helper.go index 12b7c6b..e00695a 100644 --- a/controllers/helper.go +++ b/controllers/helper.go @@ -10,6 +10,7 @@ import ( const ( masterPeerAddressPattern = "%s-master-%d.%s-master-peer:9333" + filerPeerAddressPattern = "%s-filer-%d.%s-filer-peer:9333" masterPeerAddressWithNamespacePattern = "%s-master-%d.%s-master-peer.%s:9333" filerServiceAddressWithNamespacePattern = "%s-filer.%s:8888" masterServiceAddressWithNamespacePattern = "%s-master.%s:9333" @@ -51,6 +52,18 @@ func ReconcileResult(err error) (bool, ctrl.Result, error) { return false, ctrl.Result{}, nil } +func getFilerAddresses(name string, replicas int32) []string { + peersAddresses := make([]string, 0, replicas) + for i := int32(0); i < replicas; i++ { + peersAddresses = append(peersAddresses, fmt.Sprintf(filerPeerAddressPattern, name, i, name)) + } + return peersAddresses +} + +func getFilerPeersString(name string, replicas int32) string { + return strings.Join(getFilerAddresses(name, replicas), ",") +} + func getMasterAddresses(name string, replicas int32) []string { peersAddresses := make([]string, 0, replicas) for i := int32(0); i < replicas; i++ { @@ -62,6 +75,7 @@ func getMasterAddresses(name string, replicas int32) []string { func getMasterPeersString(name string, replicas int32) string { return strings.Join(getMasterAddresses(name, replicas), ",") } + func getMasterAddressesWithNamespace(name, namespace string, replicas int32) []string { peersAddresses := make([]string, 0, replicas) for i := int32(0); i < replicas; i++ { From a9ea14b3998bb93d55eb7b7ec1b79ef21f0894c1 Mon Sep 17 00:00:00 2001 From: Howard Lau Date: Fri, 30 Oct 2020 09:23:54 +0000 Subject: [PATCH 2/2] fix port Signed-off-by: Howard Lau --- controllers/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/helper.go b/controllers/helper.go index e00695a..f449876 100644 --- a/controllers/helper.go +++ b/controllers/helper.go @@ -10,7 +10,7 @@ import ( const ( masterPeerAddressPattern = "%s-master-%d.%s-master-peer:9333" - filerPeerAddressPattern = "%s-filer-%d.%s-filer-peer:9333" + filerPeerAddressPattern = "%s-filer-%d.%s-filer-peer:8888" masterPeerAddressWithNamespacePattern = "%s-master-%d.%s-master-peer.%s:9333" filerServiceAddressWithNamespacePattern = "%s-filer.%s:8888" masterServiceAddressWithNamespacePattern = "%s-master.%s:9333"