Skip to content

Commit 6163859

Browse files
author
corneredrat
committed
read node and port information from env varibles for kube* services
1 parent b586bd9 commit 6163859

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

pkg/healthchecker/types/types.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package types
1818

1919
import (
2020
"fmt"
21+
"os"
2122
"sort"
2223
"strconv"
2324
"strings"
@@ -38,12 +39,42 @@ const (
3839
ContainerdService = "containerd"
3940
KubeProxyComponent = "kube-proxy"
4041

42+
LogPatternFlagSeparator = ":"
43+
44+
nodeEnvKey = "HOST_IP"
45+
kubeletPort = "KUBELET_PORT"
46+
kubeProxyPort = "KUBEPROXY_PORT"
47+
)
48+
49+
var (
4150
KubeletHealthCheckEndpoint = "http://127.0.0.1:10248/healthz"
4251
KubeProxyHealthCheckEndpoint = "http://127.0.0.1:10256/healthz"
43-
44-
LogPatternFlagSeparator = ":"
4552
)
4653

54+
func init() {
55+
var o string
56+
57+
hostIP := "127.0.0.1"
58+
kubeletPort := "10248"
59+
kubeProxyPort := "10256"
60+
61+
o = os.Getenv(nodeEnvKey)
62+
if o != "" {
63+
hostIP = o
64+
}
65+
o = os.Getenv(kubeletPort)
66+
if o != "" {
67+
kubeletPort = o
68+
}
69+
o = os.Getenv(kubeProxyPort)
70+
if o != "" {
71+
kubeProxyPort = o
72+
}
73+
74+
KubeletHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostIP, kubeletPort)
75+
KubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostIP, kubeProxyPort)
76+
}
77+
4778
type HealthChecker interface {
4879
CheckHealth() (bool, error)
4980
}

0 commit comments

Comments
 (0)