Skip to content

Commit 5650cf4

Browse files
authored
Merge pull request #18182 from hakman/azure-https-kops-controller
azure: Use HTTPS health check for kops-controller
2 parents 0e81500 + 027ed72 commit 5650cf4

4 files changed

Lines changed: 34 additions & 11 deletions

File tree

cmd/kops-controller/pkg/server/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func NewServer(vfsContext *vfs.VFSContext, opt *config.Options, verifier bootstr
120120
s.challengeClient = challengeClient
121121

122122
r := http.NewServeMux()
123+
r.Handle("/healthz", http.HandlerFunc(healthCheck))
123124
r.Handle("/bootstrap", http.HandlerFunc(s.bootstrap))
124125
server.Handler = recovery(r)
125126

@@ -154,6 +155,11 @@ func (s *Server) Start(ctx context.Context) error {
154155
return s.server.ListenAndServeTLS(s.opt.Server.ServerCertificatePath, s.opt.Server.ServerKeyPath)
155156
}
156157

158+
func healthCheck(w http.ResponseWriter, r *http.Request) {
159+
w.WriteHeader(http.StatusOK)
160+
_, _ = w.Write([]byte("ok"))
161+
}
162+
157163
func (s *Server) bootstrap(w http.ResponseWriter, r *http.Request) {
158164
if r.Body == nil {
159165
klog.Infof("bootstrap %s no body", r.RemoteAddr)

tests/integration/update_cluster/minimal_azure/kubernetes.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ resource "azurerm_lb_backend_address_pool" "api-minimal-azure-example-com-backen
6161
name = "LoadBalancerBackEnd"
6262
}
6363

64-
resource "azurerm_lb_probe" "api-minimal-azure-example-com-Health-TCP-3988" {
64+
resource "azurerm_lb_probe" "api-minimal-azure-example-com-Health-HTTPS-3988" {
6565
interval_in_seconds = 15
6666
loadbalancer_id = azurerm_lb.api-minimal-azure-example-com.id
67-
name = "Health-TCP-3988"
67+
name = "Health-HTTPS-3988"
6868
number_of_probes = 4
6969
port = 3988
70-
protocol = "Tcp"
70+
protocol = "Https"
71+
request_path = "/healthz"
7172
}
7273

7374
resource "azurerm_lb_probe" "api-minimal-azure-example-com-Health-TCP-443" {
@@ -89,7 +90,7 @@ resource "azurerm_lb_rule" "api-minimal-azure-example-com-TCP-3988" {
8990
load_distribution = "Default"
9091
loadbalancer_id = azurerm_lb.api-minimal-azure-example-com.id
9192
name = "TCP-3988"
92-
probe_id = azurerm_lb_probe.api-minimal-azure-example-com-Health-TCP-3988.id
93+
probe_id = azurerm_lb_probe.api-minimal-azure-example-com-Health-HTTPS-3988.id
9394
protocol = "Tcp"
9495
}
9596

upup/pkg/fi/cloudup/azuretasks/loadbalancer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ func (*LoadBalancer) RenderAzure(t *azure.AzureAPITarget, a, e, changes *LoadBal
250250

251251
if slices.Contains(e.WellKnownServices, wellknownservices.KopsController) {
252252
lb.Properties.Probes = append(lb.Properties.Probes, &network.Probe{
253-
Name: to.Ptr("Health-TCP-3988"),
253+
Name: to.Ptr("Health-HTTPS-3988"),
254254
Properties: &network.ProbePropertiesFormat{
255-
Protocol: to.Ptr(network.ProbeProtocolTCP),
255+
Protocol: to.Ptr(network.ProbeProtocolHTTPS),
256256
Port: to.Ptr[int32](wellknownports.KopsControllerPort),
257+
RequestPath: to.Ptr("/healthz"),
257258
IntervalInSeconds: to.Ptr[int32](15),
258259
NumberOfProbes: to.Ptr[int32](4),
259260
},
@@ -274,7 +275,7 @@ func (*LoadBalancer) RenderAzure(t *azure.AzureAPITarget, a, e, changes *LoadBal
274275
ID: to.Ptr(fmt.Sprintf("/%s/loadbalancers/%s/backendAddressPools/%s", idPrefix, *e.Name, *to.Ptr("LoadBalancerBackEnd"))),
275276
},
276277
Probe: &network.SubResource{
277-
ID: to.Ptr(fmt.Sprintf("/%s/loadbalancers/%s/probes/%s", idPrefix, *e.Name, *to.Ptr("Health-TCP-3988"))),
278+
ID: to.Ptr(fmt.Sprintf("/%s/loadbalancers/%s/probes/%s", idPrefix, *e.Name, *to.Ptr("Health-HTTPS-3988"))),
278279
},
279280
},
280281
})

upup/pkg/fi/cloudup/azuretasks/loadbalancer_terraform.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type terraformAzureLoadBalancerProbe struct {
5757
LoadBalancerID *terraformWriter.Literal `cty:"loadbalancer_id"`
5858
Protocol *string `cty:"protocol"`
5959
Port *int32 `cty:"port"`
60+
RequestPath *string `cty:"request_path"`
6061
IntervalInSeconds *int32 `cty:"interval_in_seconds"`
6162
NumberOfProbes *int32 `cty:"number_of_probes"`
6263
}
@@ -118,18 +119,21 @@ func (*LoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
118119
if err != nil {
119120
return err
120121
}
121-
probeName := fmt.Sprintf("Health-TCP-%d", port)
122+
123+
probeProtocol, probeNamePrefix, probeRequestPath := wellKnownServiceProbe(service)
124+
probeName := fmt.Sprintf("Health-%s-%d", probeNamePrefix, port)
122125
ruleName := fmt.Sprintf("TCP-%d", port)
123126
probeResourceName := fmt.Sprintf("%s-%s", fi.ValueOf(e.Name), probeName)
124127
ruleResourceName := fmt.Sprintf("%s-%s", fi.ValueOf(e.Name), ruleName)
125128

126-
protocol := "Tcp"
129+
ruleProtocol := "Tcp"
127130
loadDistribution := "Default"
128131
if err := t.RenderResource("azurerm_lb_probe", probeResourceName, &terraformAzureLoadBalancerProbe{
129132
Name: &probeName,
130133
LoadBalancerID: e.terraformID(),
131-
Protocol: &protocol,
134+
Protocol: &probeProtocol,
132135
Port: fi.PtrTo(port),
136+
RequestPath: probeRequestPath,
133137
IntervalInSeconds: fi.PtrTo[int32](15),
134138
NumberOfProbes: fi.PtrTo[int32](4),
135139
}); err != nil {
@@ -139,7 +143,7 @@ func (*LoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
139143
if err := t.RenderResource("azurerm_lb_rule", ruleResourceName, &terraformAzureLoadBalancerRule{
140144
Name: &ruleName,
141145
LoadBalancerID: e.terraformID(),
142-
Protocol: &protocol,
146+
Protocol: &ruleProtocol,
143147
FrontendPort: fi.PtrTo(port),
144148
BackendPort: fi.PtrTo(port),
145149
FrontendIPConfigurationName: fi.PtrTo(terraformAzureLoadBalancerFrontendName),
@@ -164,6 +168,17 @@ func (lb *LoadBalancer) terraformBackendAddressPoolID() *terraformWriter.Literal
164168
return terraformWriter.LiteralProperty("azurerm_lb_backend_address_pool", fmt.Sprintf("%s-backend-pool", fi.ValueOf(lb.Name)), "id")
165169
}
166170

171+
// wellKnownServiceProbe returns the probe protocol (for terraform), probe name prefix (for resource naming),
172+
// and request path for the given service.
173+
func wellKnownServiceProbe(service wellknownservices.WellKnownService) (protocol string, namePrefix string, requestPath *string) {
174+
switch service {
175+
case wellknownservices.KopsController:
176+
return "Https", "HTTPS", fi.PtrTo("/healthz")
177+
default:
178+
return "Tcp", "TCP", nil
179+
}
180+
}
181+
167182
func wellKnownServicePort(service wellknownservices.WellKnownService) (int32, error) {
168183
switch service {
169184
case wellknownservices.KubeAPIServer:

0 commit comments

Comments
 (0)