Skip to content

Commit

Permalink
fix: add mikejoh's commit changes (a70d5d0, kubernetes-sigs#4996) for…
Browse files Browse the repository at this point in the history
… when TSServer is not ready
  • Loading branch information
visokoo committed Jan 21, 2025
1 parent 827220f commit 5c14cd2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/f5_transportserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package source
import (
"context"
"fmt"
"strings"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 != ""
}
66 changes: 66 additions & 0 deletions source/f5_transportserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -97,6 +98,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -128,6 +130,7 @@ func TestF5TransportServerEndpoints(t *testing.T) {
},
Status: f5.TransportServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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,
},
Expand All @@ -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{
{
Expand All @@ -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 {
Expand Down

0 comments on commit 5c14cd2

Please sign in to comment.