@@ -98,3 +98,84 @@ func TestLogPatternFlag(t *testing.T) {
98
98
})
99
99
}
100
100
}
101
+
102
+ func TestKubeEndpointConfiguration (t * testing.T ) {
103
+ testCases := []struct {
104
+ name string
105
+ envConfig map [string ]string
106
+ expectedKubeletEndpoint string
107
+ expectedKubeProxyEndpoint string
108
+ }{
109
+ {
110
+ name : "no overrides supplied" ,
111
+ envConfig : map [string ]string {},
112
+ expectedKubeletEndpoint : "http://127.0.0.1:10248/healthz" ,
113
+ expectedKubeProxyEndpoint : "http://127.0.0.1:10256/healthz" ,
114
+ }, {
115
+ name : "HOST_ADDRESS override supplied" ,
116
+ envConfig : map [string ]string {
117
+ "HOST_ADDRESS" : "samplehost.testdomain.com" ,
118
+ },
119
+ expectedKubeletEndpoint : "http://samplehost.testdomain.com:10248/healthz" ,
120
+ expectedKubeProxyEndpoint : "http://samplehost.testdomain.com:10256/healthz" ,
121
+ },
122
+ {
123
+ name : "KUBELET_PORT override supplied" ,
124
+ envConfig : map [string ]string {
125
+ "KUBELET_PORT" : "12345" ,
126
+ },
127
+ expectedKubeletEndpoint : "http://127.0.0.1:12345/healthz" ,
128
+ expectedKubeProxyEndpoint : "http://127.0.0.1:10256/healthz" ,
129
+ },
130
+ {
131
+ name : "KUBEPROXY_PORT override supplied" ,
132
+ envConfig : map [string ]string {
133
+ "KUBEPROXY_PORT" : "12345" ,
134
+ },
135
+ expectedKubeletEndpoint : "http://127.0.0.1:10248/healthz" ,
136
+ expectedKubeProxyEndpoint : "http://127.0.0.1:12345/healthz" ,
137
+ },
138
+ {
139
+ name : "HOST_ADDRESS and KUBELET_PORT override supplied" ,
140
+ envConfig : map [string ]string {
141
+ "HOST_ADDRESS" : "samplehost.testdomain.com" ,
142
+ "KUBELET_PORT" : "12345" ,
143
+ },
144
+ expectedKubeletEndpoint : "http://samplehost.testdomain.com:12345/healthz" ,
145
+ expectedKubeProxyEndpoint : "http://samplehost.testdomain.com:10256/healthz" ,
146
+ },
147
+ {
148
+ name : "HOST_ADDRESS and KUBEPROXY_PORT override supplied" ,
149
+ envConfig : map [string ]string {
150
+ "HOST_ADDRESS" : "samplehost.testdomain.com" ,
151
+ "KUBEPROXY_PORT" : "12345" ,
152
+ },
153
+ expectedKubeletEndpoint : "http://samplehost.testdomain.com:10248/healthz" ,
154
+ expectedKubeProxyEndpoint : "http://samplehost.testdomain.com:12345/healthz" ,
155
+ },
156
+ {
157
+ name : "HOST_ADDRESS, KUBELET_PORT and KUBEPROXY_PORT override supplied" ,
158
+ envConfig : map [string ]string {
159
+ "HOST_ADDRESS" : "10.0.10.1" ,
160
+ "KUBELET_PORT" : "12345" ,
161
+ "KUBEPROXY_PORT" : "12346" ,
162
+ },
163
+ expectedKubeletEndpoint : "http://10.0.10.1:12345/healthz" ,
164
+ expectedKubeProxyEndpoint : "http://10.0.10.1:12346/healthz" ,
165
+ },
166
+ }
167
+ for _ , test := range testCases {
168
+ t .Run (test .name , func (t * testing.T ) {
169
+ for key , val := range test .envConfig {
170
+ t .Setenv (key , val )
171
+ }
172
+ setKubeEndpoints ()
173
+
174
+ kubeProxyHCEndpoint := KubeProxyHealthCheckEndpoint ()
175
+ kubeletHCEndpoint := KubeletHealthCheckEndpoint ()
176
+
177
+ assert .Equal (t , kubeProxyHCEndpoint , test .expectedKubeProxyEndpoint )
178
+ assert .Equal (t , kubeletHCEndpoint , test .expectedKubeletEndpoint )
179
+ })
180
+ }
181
+ }
0 commit comments