fix: add mikejoh's commit changes (a70d5d0, #4996) for when TSServer is not ready

This commit is contained in:
Vivian Ta 2025-01-21 11:22:21 -08:00
parent 827220fe1d
commit 5c14cd23fd
2 changed files with 82 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package source
import (
"context"
"fmt"
"strings"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
@ -141,6 +142,12 @@ 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.",
transportServer.Namespace, transportServer.Name)
continue
}
resource := fmt.Sprintf("f5-transportserver/%s/%s", transportServer.Namespace, transportServer.Name)
ttl := getTTLFromAnnotations(transportServer.Annotations, resource)
@ -205,3 +212,12 @@ 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
}
normalizedAddress := strings.ToLower(vs.Status.VSAddress)
return normalizedAddress != "none" && normalizedAddress != ""
}

View File

@ -65,6 +65,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
@ -97,6 +98,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
@ -128,6 +130,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
@ -182,6 +185,10 @@ func TestF5TransportServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
{
@ -214,6 +221,10 @@ func TestF5TransportServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: nil,
},
@ -235,6 +246,10 @@ func TestF5TransportServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
{
@ -248,6 +263,57 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
},
},
{
name: "F5 TransportServer with error status",
transportServer: f5.TransportServer{
TypeMeta: metav1.TypeMeta{
APIVersion: f5TransportServerGVR.GroupVersion().String(),
Kind: "TransportServer",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-ts",
Namespace: defaultF5TransportServerNamespace,
Annotations: map[string]string{
"external-dns.alpha.kubernetes.io/ttl": "600",
},
},
Spec: f5.TransportServerSpec{
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.TransportServerStatus{
VSAddress: "",
Status: "ERROR",
Error: "Some error status message",
},
},
expected: nil,
},
{
name: "F5 TransportServer with missing IP address and OK status",
transportServer: f5.TransportServer{
TypeMeta: metav1.TypeMeta{
APIVersion: f5TransportServerGVR.GroupVersion().String(),
Kind: "TransportServer",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-ts",
Namespace: defaultF5TransportServerNamespace,
Annotations: map[string]string{
"external-dns.alpha.kubernetes.io/ttl": "600",
},
},
Spec: f5.TransportServerSpec{
Host: "www.example.com",
IPAMLabel: "test",
},
Status: f5.TransportServerStatus{
VSAddress: "None",
Status: "OK",
},
},
expected: nil,
},
}
for _, tc := range tests {