@@ -39,7 +39,7 @@ import (
39
39
40
40
// Waiter is an interface for waiting for criteria in Kubernetes to happen
41
41
type Waiter interface {
42
- // WaitForControlPlaneComponents waits for all control plane components to report "ok" on /healthz
42
+ // WaitForControlPlaneComponents waits for all control plane components to be ready.
43
43
WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error
44
44
// WaitForAPI waits for the API Server's /healthz endpoint to become "ok"
45
45
// TODO: remove WaitForAPI once WaitForAllControlPlaneComponents goes GA:
@@ -81,31 +81,58 @@ type controlPlaneComponent struct {
81
81
url string
82
82
}
83
83
84
+ const (
85
+ // TODO: switch to /livez once all components support it
86
+ // and delete the endpointHealthz constant.
87
+ // https://github.com/kubernetes/kubernetes/issues/118158
88
+ endpointHealthz = "healthz"
89
+ endpointLivez = "livez"
90
+ )
91
+
84
92
// getControlPlaneComponents takes a ClusterConfiguration and returns a slice of
85
- // control plane components and their secure ports .
93
+ // control plane components and their health check URLs .
86
94
func getControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) []controlPlaneComponent {
87
- portArg := "secure-port"
95
+ const (
96
+ portArg = "secure-port"
97
+ addressArg = "bind-address"
98
+ defaultAddress = "127.0.0.1"
99
+ )
100
+
88
101
portAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , portArg , - 1 )
89
102
if idx == - 1 {
90
- portAPIServer = "6443"
103
+ portAPIServer = fmt . Sprintf ( "%d" , constants . KubeAPIServerPort )
91
104
}
92
105
portKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , portArg , - 1 )
93
106
if idx == - 1 {
94
- portKCM = "10257"
107
+ portKCM = fmt . Sprintf ( "%d" , constants . KubeControllerManagerPort )
95
108
}
96
109
portScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , portArg , - 1 )
97
110
if idx == - 1 {
98
- portScheduler = "10259"
111
+ portScheduler = fmt .Sprintf ("%d" , constants .KubeSchedulerPort )
112
+ }
113
+
114
+ addressAPIServer , idx := kubeadmapi .GetArgValue (cfg .APIServer .ExtraArgs , addressArg , - 1 )
115
+ if idx == - 1 {
116
+ addressAPIServer = defaultAddress
117
+ }
118
+ addressKCM , idx := kubeadmapi .GetArgValue (cfg .ControllerManager .ExtraArgs , addressArg , - 1 )
119
+ if idx == - 1 {
120
+ addressKCM = defaultAddress
99
121
}
100
- urlFormat := "https://127.0.0.1:%s/healthz"
122
+ addressScheduler , idx := kubeadmapi .GetArgValue (cfg .Scheduler .ExtraArgs , addressArg , - 1 )
123
+ if idx == - 1 {
124
+ addressScheduler = defaultAddress
125
+ }
126
+
127
+ urlFormat := "https://%s:%s/%s"
101
128
return []controlPlaneComponent {
102
- {name : "kube-apiserver" , url : fmt .Sprintf (urlFormat , portAPIServer )},
103
- {name : "kube-controller-manager" , url : fmt .Sprintf (urlFormat , portKCM )},
104
- {name : "kube-scheduler" , url : fmt .Sprintf (urlFormat , portScheduler )},
129
+ {name : "kube-apiserver" , url : fmt .Sprintf (urlFormat , addressAPIServer , portAPIServer , endpointLivez )},
130
+ {name : "kube-controller-manager" , url : fmt .Sprintf (urlFormat , addressKCM , portKCM , endpointHealthz )},
131
+ {name : "kube-scheduler" , url : fmt .Sprintf (urlFormat , addressScheduler , portScheduler , endpointLivez )},
105
132
}
106
133
}
107
134
108
- // WaitForControlPlaneComponents waits for all control plane components to report "ok" on /healthz
135
+ // WaitForControlPlaneComponents waits for all control plane components to report "ok".
109
136
func (w * KubeWaiter ) WaitForControlPlaneComponents (cfg * kubeadmapi.ClusterConfiguration ) error {
110
137
fmt .Printf ("[control-plane-check] Waiting for healthy control plane components." +
111
138
" This can take up to %v\n " , w .timeout )
@@ -133,15 +160,16 @@ func (w *KubeWaiter) WaitForControlPlaneComponents(cfg *kubeadmapi.ClusterConfig
133
160
true , func (ctx context.Context ) (bool , error ) {
134
161
resp , err := client .Get (comp .url )
135
162
if err != nil {
136
- lastError = errors .WithMessagef (err , "%s /healthz check failed" , comp .name )
163
+ lastError = errors .WithMessagef (err , "%s check failed at %s " , comp .name , comp . url )
137
164
return false , nil
138
165
}
139
166
140
167
defer func () {
141
168
_ = resp .Body .Close ()
142
169
}()
143
170
if resp .StatusCode != http .StatusOK {
144
- lastError = errors .Errorf ("%s /healthz check failed with status: %d" , comp .name , resp .StatusCode )
171
+ lastError = errors .Errorf ("%s check failed at %s with status: %d" ,
172
+ comp .name , comp .url , resp .StatusCode )
145
173
return false , nil
146
174
}
147
175
0 commit comments