Skip to content

Commit

Permalink
Fix VIP expose svc
Browse files Browse the repository at this point in the history
  • Loading branch information
yaocw2020 authored and gitlawr committed Sep 9, 2021
1 parent 3eecf6b commit f846b0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
9 changes: 6 additions & 3 deletions manifests/harvester.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ spec:
webhook:
image:
imagePullPolicy: "IfNotPresent"
service:
harvester:
type: LoadBalancer
harvester-load-balancer:
enabled: true
kube-vip:
enabled: true
kube-vip-cloud-provider:
enabled: true
9 changes: 5 additions & 4 deletions pkg/config/templates/harvester-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ spec:
config:
vip_interface: "{{ .MgmtInterface }}"
service:
harvester:
vipMode: "{{ .VipMode }}"
vip: "{{ .Vip }}"
vipHwAddr: "{{ .VipHwAddr }}"
vip:
enabled: true
mode: "{{ .VipMode }}"
ip: "{{ .Vip }}"
hwAddress: "{{ .VipHwAddr }}"
25 changes: 23 additions & 2 deletions pkg/console/dashboard_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,15 @@ func syncManagementURL(ctx context.Context, g *gocui.Gui) {

func doSyncManagementURL(g *gocui.Gui) {
managementURL := "Unavailable"
if managementIP := getVIP(); managementIP != "" {
managementIP := getVIP()
if managementIP != "" {
managementURL = fmt.Sprintf("https://%s", managementIP)
} else {
if managementIP = getFirstReadyMasterIP(); managementIP != "" {
managementURL = fmt.Sprintf("https://%s:%s", managementIP, harvesterNodePort)
}
}

g.Update(func(g *gocui.Gui) error {
v, err := g.View("url")
if err != nil {
Expand All @@ -227,8 +233,23 @@ func doSyncManagementURL(g *gocui.Gui) {
})
}

func getFirstReadyMasterIP() string {
// get first ready master node's internal ip
cmd := exec.Command("/bin/sh", "-c", `kubectl get no -l 'node-role.kubernetes.io/master=true' --sort-by='.metadata.creationTimestamp' \
-o jsonpath='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{range @.status.addresses[*]}{@.type}={@.address};{end}{"\n"}{end}' 2>/dev/null \
| grep 'Ready=True' | head -n 1 | tr ';' '\n' | awk -F '=' '/InternalIP/{printf $2}'`)
cmd.Env = os.Environ()
output, err := cmd.Output()
outStr := string(output)
if err != nil {
logrus.Error(err, outStr)
return ""
}
return outStr
}

func getVIP() string {
out, err := exec.Command("/bin/sh", "-c", `kubectl get service -n harvester-system harvester -o jsonpath='{.status.loadBalancer.ingress[*].ip}'`).Output()
out, err := exec.Command("/bin/sh", "-c", `kubectl get configmap -n harvester-system vip -o jsonpath='{.data.ip}'`).Output()
outStr := string(out)
if err != nil {
logrus.Errorf(err.Error(), outStr)
Expand Down

0 comments on commit f846b0f

Please sign in to comment.