From cfda4e556d4fc62dbeacf9f0744b224e297af587 Mon Sep 17 00:00:00 2001 From: kakzhou719 Date: Wed, 21 Dec 2022 11:44:20 +0800 Subject: [PATCH] set lvscare health path for registry server set lvscare health path for registry server set lvscare health path for registry server set lvscare health path for registry server --- pkg/ipvs/ipvs.go | 5 +++-- pkg/ipvs/ipvs_test.go | 37 ++++++++++++++++++++------------- pkg/registry/installer.go | 19 +++++++++-------- pkg/registry/local.go | 16 ++++++++++---- pkg/runtime/kubernetes/utils.go | 3 ++- 5 files changed, 50 insertions(+), 30 deletions(-) diff --git a/pkg/ipvs/ipvs.go b/pkg/ipvs/ipvs.go index d6643814d3a..f64e379d20b 100644 --- a/pkg/ipvs/ipvs.go +++ b/pkg/ipvs/ipvs.go @@ -38,12 +38,13 @@ func GetCreateLvscareStaticPodCmd(content, fileName string) string { } // LvsStaticPodYaml return lvs care static pod yaml -func LvsStaticPodYaml(podName, virtualEndpoint string, realEndpoints []string, image string) (string, error) { +func LvsStaticPodYaml(podName, virtualEndpoint string, realEndpoints []string, image string, + healthPath string, healthSchem string) (string, error) { if virtualEndpoint == "" || len(realEndpoints) == 0 || image == "" { return "", fmt.Errorf("invalid args to create Lvs static pod") } - args := []string{"care", "--vs", virtualEndpoint, "--health-path", "/healthz", "--health-schem", "https"} + args := []string{"care", "--vs", virtualEndpoint, "--health-path", healthPath, "--health-schem", healthSchem} for _, re := range realEndpoints { args = append(args, "--rs", re) } diff --git a/pkg/ipvs/ipvs_test.go b/pkg/ipvs/ipvs_test.go index 7b0b679b016..2c167bdb49e 100644 --- a/pkg/ipvs/ipvs_test.go +++ b/pkg/ipvs/ipvs_test.go @@ -141,10 +141,12 @@ status: {} func TestLvsStaticPodYaml(t *testing.T) { type args struct { - podName string - vip string - masters []string - image string + podName string + vip string + masters []string + image string + healthPath string + healthSchem string } tests := []struct { name string @@ -160,32 +162,39 @@ func TestLvsStaticPodYaml(t *testing.T) { "172.16.228.158:6443", "172.16.228.159:6443", }, - image: "fdfadf", + image: "fdfadf", + healthPath: "/healthz", + healthSchem: "https", }, want: want[0], }, { args: args{ - podName: "kube-lvscare", - vip: "10.107.2.1:6443", - masters: []string{"172.16.228.157:6443"}, - image: "fdfadf", + podName: "kube-lvscare", + vip: "10.107.2.1:6443", + masters: []string{"172.16.228.157:6443"}, + image: "fdfadf", + healthPath: "/healthz", + healthSchem: "https", }, want: want[1], }, { args: args{ - podName: "reg-lvscare", - vip: "10.107.2.1:5000", - masters: []string{"172.16.228.157:5000"}, - image: "a1", + podName: "reg-lvscare", + vip: "10.107.2.1:5000", + masters: []string{"172.16.228.157:5000"}, + image: "a1", + healthPath: "/healthz", + healthSchem: "https", }, want: want[2], }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got, _ := LvsStaticPodYaml(tt.args.podName, tt.args.vip, tt.args.masters, tt.args.image); got != tt.want { + if got, _ := LvsStaticPodYaml(tt.args.podName, tt.args.vip, tt.args.masters, + tt.args.image, tt.args.healthPath, tt.args.healthSchem); got != tt.want { t.Errorf("LvsStaticPodYaml() = %v, want %v", got, tt.want) } }) diff --git a/pkg/registry/installer.go b/pkg/registry/installer.go index e30165cf250..a314b7a0beb 100644 --- a/pkg/registry/installer.go +++ b/pkg/registry/installer.go @@ -16,20 +16,19 @@ package registry import ( "fmt" - "net" - "path/filepath" - "strconv" - - "github.com/sirupsen/logrus" - "github.com/sealerio/sealer/common" "github.com/sealerio/sealer/pkg/clustercert/cert" + "github.com/sealerio/sealer/pkg/env" "github.com/sealerio/sealer/pkg/imagedistributor" "github.com/sealerio/sealer/pkg/infradriver" v2 "github.com/sealerio/sealer/types/api/v2" netutils "github.com/sealerio/sealer/utils/net" osutils "github.com/sealerio/sealer/utils/os" - "github.com/sealerio/sealer/utils/strings" + strutils "github.com/sealerio/sealer/utils/strings" + "github.com/sirupsen/logrus" + "net" + "path/filepath" + "strconv" ) // Installer provide registry lifecycle management. @@ -76,7 +75,7 @@ func (l *localInstaller) Reconcile(desiredHosts []net.IP) ([]net.IP, error) { return desiredHosts, nil } - joinedHosts, deletedHosts := strings.Diff(l.currentDeployHosts, desiredHosts) + joinedHosts, deletedHosts := strutils.Diff(l.currentDeployHosts, desiredHosts) // if targetHosts is equal deployHosts, just return. if len(joinedHosts) == 0 && len(deletedHosts) == 0 { return l.currentDeployHosts, nil @@ -229,9 +228,11 @@ func (l *localInstaller) reconcileRegistry(hosts []net.IP) error { } // bash init-registry.sh ${port} ${mountData} ${domain} + clusterEnvs := l.infraDriver.GetClusterEnv() initRegistry := fmt.Sprintf("cd %s/scripts && bash init-registry.sh %s %s %s", rootfs, strconv.Itoa(l.Port), dataDir, l.Domain) + initRegistryCmd := env.WrapperShell(initRegistry, clusterEnvs) for _, deployHost := range hosts { - if err := l.infraDriver.CmdAsync(deployHost, initRegistry); err != nil { + if err := l.infraDriver.CmdAsync(deployHost, initRegistryCmd); err != nil { return err } } diff --git a/pkg/registry/local.go b/pkg/registry/local.go index 638eb08a31d..81dbe3bcf70 100644 --- a/pkg/registry/local.go +++ b/pkg/registry/local.go @@ -170,14 +170,22 @@ func (c *localConfigurator) configureLvs(registryHosts, clientHosts []net.IP) er } vs := net.JoinHostPort(vip, strconv.Itoa(c.Port)) - y, err := ipvs.LvsStaticPodYaml(common.RegLvsCareStaticPodName, vs, realEndpoints, lvsImageURL) + // due to registry server do not have health path to check, choose "/" as default. + healthPath := "/" + healthSchem := "https" + if *c.Insecure { + healthSchem = "http" + } + + y, err := ipvs.LvsStaticPodYaml(common.RegLvsCareStaticPodName, vs, realEndpoints, lvsImageURL, healthPath, healthSchem) if err != nil { return err } lvscareStaticCmd := ipvs.GetCreateLvscareStaticPodCmd(y, LvscarePodFileName) - ipvsCmd := fmt.Sprintf("seautil ipvs --vs %s %s --health-path /healthz --health-schem https --run-once", vs, strings.Join(rs, " ")) + ipvsCmd := fmt.Sprintf("seautil ipvs --vs %s %s --health-path %s --health-schem %s --run-once", + vs, strings.Join(rs, " "), healthPath, healthSchem) // flush all cluster nodes as latest ipvs policy. eg, _ := errgroup.WithContext(context.Background()) @@ -186,12 +194,12 @@ func (c *localConfigurator) configureLvs(registryHosts, clientHosts []net.IP) er eg.Go(func() error { err := c.infraDriver.CmdAsync(n, ipvsCmd, lvscareStaticCmd) if err != nil { - return fmt.Errorf("failed to config ndoes lvs policy %s: %v", ipvsCmd, err) + return fmt.Errorf("failed to config nodes lvs policy %s: %v", ipvsCmd, err) } err = c.infraDriver.CmdAsync(n, shellcommand.CommandSetHostAlias(c.Domain, vip)) if err != nil { - return fmt.Errorf("failed to config ndoes hosts file cmd: %v", err) + return fmt.Errorf("failed to config nodes hosts file cmd: %v", err) } return nil }) diff --git a/pkg/runtime/kubernetes/utils.go b/pkg/runtime/kubernetes/utils.go index 5e3eb50647f..9cf5408a31e 100644 --- a/pkg/runtime/kubernetes/utils.go +++ b/pkg/runtime/kubernetes/utils.go @@ -191,7 +191,8 @@ func (k *Runtime) configureLvs(masterHosts, clientHosts []net.IP) error { } vs := net.JoinHostPort(k.getAPIServerVIP().String(), "6443") ipvsCmd := fmt.Sprintf("seautil ipvs --vs %s %s --health-path /healthz --health-schem https --run-once", vs, strings.Join(rs, " ")) - y, err := ipvs.LvsStaticPodYaml(common.KubeLvsCareStaticPodName, vs, realEndpoints, lvsImageURL) + y, err := ipvs.LvsStaticPodYaml(common.KubeLvsCareStaticPodName, vs, realEndpoints, lvsImageURL, + "/healthz", "https") if err != nil { return err }