From 6a04135caec0b1db3f7828b2346672adb5796b72 Mon Sep 17 00:00:00 2001 From: Mikael Johansson Date: Wed, 18 Jun 2025 09:12:51 +0200 Subject: [PATCH] fix(f5): validate virtualservers and transportservers based on IP only (#5532) --- source/f5_transportserver.go | 10 +++------- source/f5_transportserver_test.go | 16 +++++++++++++--- source/f5_virtualserver.go | 10 +++------- source/f5_virtualserver_test.go | 16 +++++++++++++--- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/source/f5_transportserver.go b/source/f5_transportserver.go index 70b5736e9..6b08f6288 100644 --- a/source/f5_transportserver.go +++ b/source/f5_transportserver.go @@ -145,8 +145,8 @@ func (ts *f5TransportServerSource) endpointsFromTransportServers(transportServer var endpoints []*endpoint.Endpoint for _, transportServer := range transportServers { - if !isTransportServerReady(transportServer) { - log.Warnf("F5 TransportServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.", + if !hasValidTransportServerIP(transportServer) { + log.Warnf("F5 TransportServer %s/%s is missing a valid IP address, skipping endpoint creation.", transportServer.Namespace, transportServer.Name) continue } @@ -213,11 +213,7 @@ func (ts *f5TransportServerSource) filterByAnnotations(transportServers []*f5.Tr return filteredList, nil } -func isTransportServerReady(vs *f5.TransportServer) bool { - if strings.ToLower(vs.Status.Status) != "ok" { - return false - } - +func hasValidTransportServerIP(vs *f5.TransportServer) bool { normalizedAddress := strings.ToLower(vs.Status.VSAddress) return normalizedAddress != "none" && normalizedAddress != "" } diff --git a/source/f5_transportserver_test.go b/source/f5_transportserver_test.go index 3b06dfd97..c6e154ddb 100644 --- a/source/f5_transportserver_test.go +++ b/source/f5_transportserver_test.go @@ -265,7 +265,7 @@ func TestF5TransportServerEndpoints(t *testing.T) { }, }, { - name: "F5 TransportServer with error status", + name: "F5 TransportServer with error status but valid IP", transportServer: f5.TransportServer{ TypeMeta: metav1.TypeMeta{ APIVersion: f5TransportServerGVR.GroupVersion().String(), @@ -283,12 +283,22 @@ func TestF5TransportServerEndpoints(t *testing.T) { VirtualServerAddress: "192.168.1.100", }, Status: f5.CustomResourceStatus{ - VSAddress: "", + VSAddress: "192.168.1.100", Status: "ERROR", Error: "Some error status message", }, }, - expected: nil, + expected: []*endpoint.Endpoint{ + { + DNSName: "www.example.com", + Targets: []string{"192.168.1.100"}, + RecordType: endpoint.RecordTypeA, + RecordTTL: 600, + Labels: endpoint.Labels{ + "resource": "f5-transportserver/transportserver/test-ts", + }, + }, + }, }, { name: "F5 TransportServer with missing IP address and OK status", diff --git a/source/f5_virtualserver.go b/source/f5_virtualserver.go index febc5dd6f..7d28f6e7b 100644 --- a/source/f5_virtualserver.go +++ b/source/f5_virtualserver.go @@ -150,8 +150,8 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f var endpoints []*endpoint.Endpoint for _, virtualServer := range virtualServers { - if !isVirtualServerReady(virtualServer) { - log.Warnf("F5 VirtualServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.", + if !hasValidVirtualServerIP(virtualServer) { + log.Warnf("F5 VirtualServer %s/%s is missing a valid IP address, skipping endpoint creation.", virtualServer.Namespace, virtualServer.Name) continue } @@ -219,11 +219,7 @@ func (vs *f5VirtualServerSource) filterByAnnotations(virtualServers []*f5.Virtua return filteredList, nil } -func isVirtualServerReady(vs *f5.VirtualServer) bool { - if strings.ToLower(vs.Status.Status) != "ok" { - return false - } - +func hasValidVirtualServerIP(vs *f5.VirtualServer) bool { normalizedAddress := strings.ToLower(vs.Status.VSAddress) return normalizedAddress != "none" && normalizedAddress != "" } diff --git a/source/f5_virtualserver_test.go b/source/f5_virtualserver_test.go index c9583e1a2..eb0866470 100644 --- a/source/f5_virtualserver_test.go +++ b/source/f5_virtualserver_test.go @@ -265,7 +265,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) { }, }, { - name: "F5 VirtualServer with error status", + name: "F5 VirtualServer with error status but valid IP", virtualServer: f5.VirtualServer{ TypeMeta: metav1.TypeMeta{ APIVersion: f5VirtualServerGVR.GroupVersion().String(), @@ -283,12 +283,22 @@ func TestF5VirtualServerEndpoints(t *testing.T) { VirtualServerAddress: "192.168.1.100", }, Status: f5.CustomResourceStatus{ - VSAddress: "", + VSAddress: "192.168.1.100", Status: "ERROR", Error: "Some error status message", }, }, - expected: nil, + expected: []*endpoint.Endpoint{ + { + DNSName: "www.example.com", + Targets: []string{"192.168.1.100"}, + RecordType: endpoint.RecordTypeA, + RecordTTL: 600, + Labels: endpoint.Labels{ + "resource": "f5-virtualserver/virtualserver/test-vs", + }, + }, + }, }, { name: "F5 VirtualServer with missing IP address and OK status",