mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
fix(f5-virtualserver): skip endpoint creation when VirtualServer is not ready (#4996)
* Skip endpoint creation if VirtualServer is not considered ready Signed-off-by: Mikael Johansson <mik.json@gmail.com> * Change to warning instead Signed-off-by: Mikael Johansson <mik.json@gmail.com> * Earlier return --------- Signed-off-by: Mikael Johansson <mik.json@gmail.com>
This commit is contained in:
parent
dfe8e7806a
commit
9368a24a75
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -147,6 +148,12 @@ 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.",
|
||||
virtualServer.Namespace, virtualServer.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
resource := fmt.Sprintf("f5-virtualserver/%s/%s", virtualServer.Namespace, virtualServer.Name)
|
||||
|
||||
ttl := getTTLFromAnnotations(virtualServer.Annotations, resource)
|
||||
@ -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)
|
||||
}
|
||||
@ -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 != ""
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: f5.VirtualServerStatus{
|
||||
VSAddress: "192.168.1.200",
|
||||
Status: "OK",
|
||||
},
|
||||
},
|
||||
expected: []*endpoint.Endpoint{
|
||||
@ -97,6 +98,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: f5.VirtualServerStatus{
|
||||
VSAddress: "192.168.1.200",
|
||||
Status: "OK",
|
||||
},
|
||||
},
|
||||
expected: []*endpoint.Endpoint{
|
||||
@ -128,6 +130,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: f5.VirtualServerStatus{
|
||||
VSAddress: "192.168.1.100",
|
||||
Status: "OK",
|
||||
},
|
||||
},
|
||||
expected: []*endpoint.Endpoint{
|
||||
@ -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{
|
||||
{
|
||||
@ -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,
|
||||
},
|
||||
@ -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{
|
||||
{
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user