Skip to content

Commit

Permalink
feat(load-balancer): emit warning if unsupported port protocol is con…
Browse files Browse the repository at this point in the history
…figured (#828)

If an unsupported port protocol is configured a warning event and log
message is emitted.
  • Loading branch information
lukasmetzner authored Dec 20, 2024
1 parent 1fad1a5 commit 8876bfa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,21 @@ func (l *LoadBalancerOps) ReconcileHCLBServices(
portExists := hclbListenPorts[portNo]
delete(hclbListenPorts, portNo)

if port.Protocol != "" && port.Protocol != corev1.ProtocolTCP {
warnMsg := fmt.Sprintf(
"configured unsupported Hetzner Cloud load balancer protocol %s for service with name %s",
port.Protocol,
svc.Name,
)
l.Recorder.Event(
svc,
corev1.EventTypeWarning,
"UnsupportedProtocolConfigured",
warnMsg,
)
klog.Warning(warnMsg)
}

b := &hclbServiceOptsBuilder{Port: port, Service: svc, CertOps: l.CertOps}
if portExists {
klog.InfoS("update service", "op", op, "port", portNo, "loadBalancerID", lb.ID)
Expand Down
42 changes: 42 additions & 0 deletions internal/hcops/load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,48 @@ func TestLoadBalancerOps_ReconcileHCLBTargets(t *testing.T) {

func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
tests := []LBReconcilementTestCase{
{
name: "configure unsupported protocol",
servicePorts: []corev1.ServicePort{
{Port: 80, NodePort: 8080, Protocol: corev1.ProtocolUDP},
{Port: 443, NodePort: 8443, Protocol: corev1.ProtocolUDP},
},
initialLB: &hcloud.LoadBalancer{
ID: 4,
LoadBalancerType: &hcloud.LoadBalancerType{
MaxTargets: 25,
},
},
mock: func(_ *testing.T, tt *LBReconcilementTestCase) {
opts := hcloud.LoadBalancerAddServiceOpts{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
ListenPort: hcloud.Ptr(80),
DestinationPort: hcloud.Ptr(8080),
HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Port: hcloud.Ptr(8080),
},
}
action := tt.fx.MockAddService(opts, tt.initialLB, nil)
tt.fx.ActionClient.On("WaitFor", tt.fx.Ctx, action).Return(nil)

opts = hcloud.LoadBalancerAddServiceOpts{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
ListenPort: hcloud.Ptr(443),
DestinationPort: hcloud.Ptr(8443),
HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
Port: hcloud.Ptr(8443),
},
}
action = tt.fx.MockAddService(opts, tt.initialLB, nil)
tt.fx.ActionClient.On("WaitFor", tt.fx.Ctx, action).Return(nil)
},
perform: func(t *testing.T, tt *LBReconcilementTestCase) {
_, err := tt.fx.LBOps.ReconcileHCLBServices(tt.fx.Ctx, tt.initialLB, tt.service)
assert.NoError(t, err)
},
},
{
name: "add services to hc Load Balancer",
servicePorts: []corev1.ServicePort{
Expand Down

0 comments on commit 8876bfa

Please sign in to comment.