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 21, 2022
1 parent 0a06259 commit 1f654c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 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
21 changes: 15 additions & 6 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,7 +162,9 @@ 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],
},
Expand All @@ -170,6 +174,8 @@ func TestLvsStaticPodYaml(t *testing.T) {
vip: "10.107.2.1:6443",
masters: []string{"172.16.228.157:6443"},
image: "fdfadf",
healthPath: "/healthz",
healthSchem: "https",
},
want: want[1],
},
Expand All @@ -179,13 +185,16 @@ func TestLvsStaticPodYaml(t *testing.T) {
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
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 1f654c3

Please sign in to comment.