mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-20 04:36:41 +00:00
Merge pull request #733 from raghu-nandan-bs/variablize-kube-endpoints
optionally read node and port information from env variables for kube* services
This commit is contained in:
@@ -138,9 +138,9 @@ func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (b
|
||||
func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error) {
|
||||
switch hco.Component {
|
||||
case types.KubeletComponent:
|
||||
return healthCheckEndpointOKFunc(types.KubeletHealthCheckEndpoint, hco.HealthCheckTimeout)
|
||||
return healthCheckEndpointOKFunc(types.KubeletHealthCheckEndpoint(), hco.HealthCheckTimeout)
|
||||
case types.KubeProxyComponent:
|
||||
return healthCheckEndpointOKFunc(types.KubeProxyHealthCheckEndpoint, hco.HealthCheckTimeout)
|
||||
return healthCheckEndpointOKFunc(types.KubeProxyHealthCheckEndpoint(), hco.HealthCheckTimeout)
|
||||
case types.DockerComponent:
|
||||
return func() (bool, error) {
|
||||
if _, err := execCommand(hco.HealthCheckTimeout, getDockerPath(), "ps"); err != nil {
|
||||
|
||||
@@ -18,6 +18,7 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -38,12 +39,57 @@ const (
|
||||
ContainerdService = "containerd"
|
||||
KubeProxyComponent = "kube-proxy"
|
||||
|
||||
KubeletHealthCheckEndpoint = "http://127.0.0.1:10248/healthz"
|
||||
KubeProxyHealthCheckEndpoint = "http://127.0.0.1:10256/healthz"
|
||||
|
||||
LogPatternFlagSeparator = ":"
|
||||
hostAddressKey = "HOST_ADDRESS"
|
||||
kubeletPortKey = "KUBELET_PORT"
|
||||
kubeProxyPortKey = "KUBEPROXY_PORT"
|
||||
|
||||
defaultHostAddress = "127.0.0.1"
|
||||
defaultKubeletPort = "10248"
|
||||
defaultKubeproxyPort = "10256"
|
||||
)
|
||||
|
||||
var (
|
||||
kubeletHealthCheckEndpoint string
|
||||
kubeProxyHealthCheckEndpoint string
|
||||
)
|
||||
|
||||
func init() {
|
||||
setKubeEndpoints()
|
||||
}
|
||||
|
||||
func setKubeEndpoints() {
|
||||
var o string
|
||||
|
||||
hostAddress := defaultHostAddress
|
||||
kubeletPort := defaultKubeletPort
|
||||
kubeProxyPort := defaultKubeproxyPort
|
||||
|
||||
o = os.Getenv(hostAddressKey)
|
||||
if o != "" {
|
||||
hostAddress = o
|
||||
}
|
||||
o = os.Getenv(kubeletPortKey)
|
||||
if o != "" {
|
||||
kubeletPort = o
|
||||
}
|
||||
o = os.Getenv(kubeProxyPortKey)
|
||||
if o != "" {
|
||||
kubeProxyPort = o
|
||||
}
|
||||
|
||||
kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeletPort)
|
||||
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s:%s/healthz", hostAddress, kubeProxyPort)
|
||||
|
||||
}
|
||||
|
||||
func KubeProxyHealthCheckEndpoint() string {
|
||||
return kubeProxyHealthCheckEndpoint
|
||||
}
|
||||
func KubeletHealthCheckEndpoint() string {
|
||||
return kubeletHealthCheckEndpoint
|
||||
}
|
||||
|
||||
type HealthChecker interface {
|
||||
CheckHealth() (bool, error)
|
||||
}
|
||||
|
||||
@@ -98,3 +98,84 @@ func TestLogPatternFlag(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeEndpointConfiguration(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
envConfig map[string]string
|
||||
expectedKubeletEndpoint string
|
||||
expectedKubeProxyEndpoint string
|
||||
}{
|
||||
{
|
||||
name: "no overrides supplied",
|
||||
envConfig: map[string]string{},
|
||||
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
|
||||
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
|
||||
}, {
|
||||
name: "HOST_ADDRESS override supplied",
|
||||
envConfig: map[string]string{
|
||||
"HOST_ADDRESS": "samplehost.testdomain.com",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://samplehost.testdomain.com:10248/healthz",
|
||||
expectedKubeProxyEndpoint: "http://samplehost.testdomain.com:10256/healthz",
|
||||
},
|
||||
{
|
||||
name: "KUBELET_PORT override supplied",
|
||||
envConfig: map[string]string{
|
||||
"KUBELET_PORT": "12345",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://127.0.0.1:12345/healthz",
|
||||
expectedKubeProxyEndpoint: "http://127.0.0.1:10256/healthz",
|
||||
},
|
||||
{
|
||||
name: "KUBEPROXY_PORT override supplied",
|
||||
envConfig: map[string]string{
|
||||
"KUBEPROXY_PORT": "12345",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://127.0.0.1:10248/healthz",
|
||||
expectedKubeProxyEndpoint: "http://127.0.0.1:12345/healthz",
|
||||
},
|
||||
{
|
||||
name: "HOST_ADDRESS and KUBELET_PORT override supplied",
|
||||
envConfig: map[string]string{
|
||||
"HOST_ADDRESS": "samplehost.testdomain.com",
|
||||
"KUBELET_PORT": "12345",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://samplehost.testdomain.com:12345/healthz",
|
||||
expectedKubeProxyEndpoint: "http://samplehost.testdomain.com:10256/healthz",
|
||||
},
|
||||
{
|
||||
name: "HOST_ADDRESS and KUBEPROXY_PORT override supplied",
|
||||
envConfig: map[string]string{
|
||||
"HOST_ADDRESS": "samplehost.testdomain.com",
|
||||
"KUBEPROXY_PORT": "12345",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://samplehost.testdomain.com:10248/healthz",
|
||||
expectedKubeProxyEndpoint: "http://samplehost.testdomain.com:12345/healthz",
|
||||
},
|
||||
{
|
||||
name: "HOST_ADDRESS, KUBELET_PORT and KUBEPROXY_PORT override supplied",
|
||||
envConfig: map[string]string{
|
||||
"HOST_ADDRESS": "10.0.10.1",
|
||||
"KUBELET_PORT": "12345",
|
||||
"KUBEPROXY_PORT": "12346",
|
||||
},
|
||||
expectedKubeletEndpoint: "http://10.0.10.1:12345/healthz",
|
||||
expectedKubeProxyEndpoint: "http://10.0.10.1:12346/healthz",
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
for key, val := range test.envConfig {
|
||||
t.Setenv(key, val)
|
||||
}
|
||||
setKubeEndpoints()
|
||||
|
||||
kubeProxyHCEndpoint := KubeProxyHealthCheckEndpoint()
|
||||
kubeletHCEndpoint := KubeletHealthCheckEndpoint()
|
||||
|
||||
assert.Equal(t, kubeProxyHCEndpoint, test.expectedKubeProxyEndpoint)
|
||||
assert.Equal(t, kubeletHCEndpoint, test.expectedKubeletEndpoint)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user