Skip to content

Commit 8876bfa

Browse files
authored
feat(load-balancer): emit warning if unsupported port protocol is configured (#828)
If an unsupported port protocol is configured a warning event and log message is emitted.
1 parent 1fad1a5 commit 8876bfa

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

internal/hcops/load_balancer.go

+15
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,21 @@ func (l *LoadBalancerOps) ReconcileHCLBServices(
866866
portExists := hclbListenPorts[portNo]
867867
delete(hclbListenPorts, portNo)
868868

869+
if port.Protocol != "" && port.Protocol != corev1.ProtocolTCP {
870+
warnMsg := fmt.Sprintf(
871+
"configured unsupported Hetzner Cloud load balancer protocol %s for service with name %s",
872+
port.Protocol,
873+
svc.Name,
874+
)
875+
l.Recorder.Event(
876+
svc,
877+
corev1.EventTypeWarning,
878+
"UnsupportedProtocolConfigured",
879+
warnMsg,
880+
)
881+
klog.Warning(warnMsg)
882+
}
883+
869884
b := &hclbServiceOptsBuilder{Port: port, Service: svc, CertOps: l.CertOps}
870885
if portExists {
871886
klog.InfoS("update service", "op", op, "port", portNo, "loadBalancerID", lb.ID)

internal/hcops/load_balancer_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,48 @@ func TestLoadBalancerOps_ReconcileHCLBTargets(t *testing.T) {
14481448

14491449
func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
14501450
tests := []LBReconcilementTestCase{
1451+
{
1452+
name: "configure unsupported protocol",
1453+
servicePorts: []corev1.ServicePort{
1454+
{Port: 80, NodePort: 8080, Protocol: corev1.ProtocolUDP},
1455+
{Port: 443, NodePort: 8443, Protocol: corev1.ProtocolUDP},
1456+
},
1457+
initialLB: &hcloud.LoadBalancer{
1458+
ID: 4,
1459+
LoadBalancerType: &hcloud.LoadBalancerType{
1460+
MaxTargets: 25,
1461+
},
1462+
},
1463+
mock: func(_ *testing.T, tt *LBReconcilementTestCase) {
1464+
opts := hcloud.LoadBalancerAddServiceOpts{
1465+
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
1466+
ListenPort: hcloud.Ptr(80),
1467+
DestinationPort: hcloud.Ptr(8080),
1468+
HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
1469+
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
1470+
Port: hcloud.Ptr(8080),
1471+
},
1472+
}
1473+
action := tt.fx.MockAddService(opts, tt.initialLB, nil)
1474+
tt.fx.ActionClient.On("WaitFor", tt.fx.Ctx, action).Return(nil)
1475+
1476+
opts = hcloud.LoadBalancerAddServiceOpts{
1477+
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
1478+
ListenPort: hcloud.Ptr(443),
1479+
DestinationPort: hcloud.Ptr(8443),
1480+
HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
1481+
Protocol: hcloud.LoadBalancerServiceProtocolTCP,
1482+
Port: hcloud.Ptr(8443),
1483+
},
1484+
}
1485+
action = tt.fx.MockAddService(opts, tt.initialLB, nil)
1486+
tt.fx.ActionClient.On("WaitFor", tt.fx.Ctx, action).Return(nil)
1487+
},
1488+
perform: func(t *testing.T, tt *LBReconcilementTestCase) {
1489+
_, err := tt.fx.LBOps.ReconcileHCLBServices(tt.fx.Ctx, tt.initialLB, tt.service)
1490+
assert.NoError(t, err)
1491+
},
1492+
},
14511493
{
14521494
name: "add services to hc Load Balancer",
14531495
servicePorts: []corev1.ServicePort{

0 commit comments

Comments
 (0)