Skip to content

Commit

Permalink
set lvscare health path for registry server
Browse files Browse the repository at this point in the history
set lvscare health path for registry server
  • Loading branch information
kakzhou719 committed Dec 22, 2022
1 parent 0a06259 commit 668b9f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
5 changes: 3 additions & 2 deletions pkg/ipvs/ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
37 changes: 23 additions & 14 deletions pkg/ipvs/ipvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
})
Expand Down
12 changes: 7 additions & 5 deletions pkg/registry/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (
"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"
)

// Installer provide registry lifecycle management.
Expand Down Expand Up @@ -76,7 +76,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
Expand Down Expand Up @@ -229,9 +229,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
}
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/registry/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/runtime/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 668b9f6

Please sign in to comment.