Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready #4996

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions source/f5_virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"sort"
"strings"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -147,6 +148,12 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f
var endpoints []*endpoint.Endpoint

for _, virtualServer := range virtualServers {
if !isVirtualServerReady(virtualServer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a suggestion

if !virtualServer.isReady()

^ This will crash if virtualServer is null))

Copy link
Contributor Author

@mikejoh mikejoh Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally understand this but we would need to embed the f5.VirtualServer struct in our own data type and then add a method to that, in this context it feels a bit overkill? A helper func (as used now) that operates on a *f5.VirtualServer feels like a good middle ground.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was simply a style suggestion, nice one.

log.Warnf("F5 VirtualServer %s/%s is not ready or is missing an IP address, skipping endpoint creation.",
virtualServer.Namespace, virtualServer.Name)
continue
}

resource := fmt.Sprintf("f5-virtualserver/%s/%s", virtualServer.Namespace, virtualServer.Name)

ttl := getTTLFromAnnotations(virtualServer.Annotations, resource)
Expand All @@ -155,6 +162,7 @@ func (vs *f5VirtualServerSource) endpointsFromVirtualServers(virtualServers []*f
if len(targets) == 0 && virtualServer.Spec.VirtualServerAddress != "" {
targets = append(targets, virtualServer.Spec.VirtualServerAddress)
}

if len(targets) == 0 && virtualServer.Status.VSAddress != "" {
targets = append(targets, virtualServer.Status.VSAddress)
}
Expand Down Expand Up @@ -211,3 +219,12 @@ 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
}

normalizedAddress := strings.ToLower(vs.Status.VSAddress)
return normalizedAddress != "none" && normalizedAddress != ""
}
66 changes: 66 additions & 0 deletions source/f5_virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -97,6 +98,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.200",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -128,6 +130,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
Expand Down Expand Up @@ -182,6 +185,10 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
{
Expand Down Expand Up @@ -214,6 +221,10 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: nil,
},
Expand All @@ -235,6 +246,10 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.VirtualServerStatus{
VSAddress: "192.168.1.100",
Status: "OK",
},
},
expected: []*endpoint.Endpoint{
{
Expand All @@ -248,6 +263,57 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
},
},
},
{
name: "F5 VirtualServer with error status",
virtualServer: f5.VirtualServer{
TypeMeta: metav1.TypeMeta{
APIVersion: f5VirtualServerGVR.GroupVersion().String(),
Kind: "VirtualServer",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-vs",
Namespace: defaultF5VirtualServerNamespace,
Annotations: map[string]string{
"external-dns.alpha.kubernetes.io/ttl": "600",
},
},
Spec: f5.VirtualServerSpec{
Host: "www.example.com",
VirtualServerAddress: "192.168.1.100",
},
Status: f5.VirtualServerStatus{
VSAddress: "",
Status: "ERROR",
Error: "Some error status message",
},
},
expected: nil,
},
{
name: "F5 VirtualServer with missing IP address and OK status",
virtualServer: f5.VirtualServer{
TypeMeta: metav1.TypeMeta{
APIVersion: f5VirtualServerGVR.GroupVersion().String(),
Kind: "VirtualServer",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-vs",
Namespace: defaultF5VirtualServerNamespace,
Annotations: map[string]string{
"external-dns.alpha.kubernetes.io/ttl": "600",
},
},
Spec: f5.VirtualServerSpec{
Host: "www.example.com",
IPAMLabel: "test",
},
Status: f5.VirtualServerStatus{
VSAddress: "None",
Status: "OK",
},
},
expected: nil,
},
}

for _, tc := range tests {
Expand Down
Loading