From d56ad7f6830334464706a117a8ccedd4eff8d84d Mon Sep 17 00:00:00 2001 From: ricoberger Date: Tue, 8 Nov 2022 12:50:15 +0100 Subject: [PATCH] Fix deletion of DNS Records for VirtualServices on error --- source/istio_virtualservice.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/istio_virtualservice.go b/source/istio_virtualservice.go index 55ec39567..934490a80 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -187,16 +187,16 @@ func (sc *virtualServiceSource) AddEventHandler(ctx context.Context, handler fun sc.virtualserviceInformer.Informer().AddEventHandler(eventHandlerFunc(handler)) } -func (sc *virtualServiceSource) getGateway(ctx context.Context, gatewayStr string, virtualService *networkingv1alpha3.VirtualService) *networkingv1alpha3.Gateway { +func (sc *virtualServiceSource) getGateway(ctx context.Context, gatewayStr string, virtualService *networkingv1alpha3.VirtualService) (*networkingv1alpha3.Gateway, error) { if gatewayStr == "" || gatewayStr == IstioMeshGateway { // This refers to "all sidecars in the mesh"; ignore. - return nil + return nil, nil } namespace, name, err := parseGateway(gatewayStr) if err != nil { log.Debugf("Failed parsing gatewayStr %s of VirtualService %s/%s", gatewayStr, virtualService.Namespace, virtualService.Name) - return nil + return nil, err } if namespace == "" { namespace = virtualService.Namespace @@ -205,14 +205,14 @@ func (sc *virtualServiceSource) getGateway(ctx context.Context, gatewayStr strin gateway, err := sc.istioClient.NetworkingV1alpha3().Gateways(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { log.Errorf("Failed retrieving gateway %s referenced by VirtualService %s/%s: %v", gatewayStr, virtualService.Namespace, virtualService.Name, err) - return nil + return nil, err } if gateway == nil { log.Debugf("Gateway %s referenced by VirtualService %s/%s not found: %v", gatewayStr, virtualService.Namespace, virtualService.Name, err) - return nil + return nil, nil } - return gateway + return gateway, nil } func (sc *virtualServiceSource) endpointsFromTemplate(ctx context.Context, virtualService *networkingv1alpha3.VirtualService) ([]*endpoint.Endpoint, error) { @@ -290,7 +290,10 @@ func (sc *virtualServiceSource) targetsFromVirtualService(ctx context.Context, v var targets []string // for each host we need to iterate through the gateways because each host might match for only one of the gateways for _, gateway := range virtualService.Spec.Gateways { - gateway := sc.getGateway(ctx, gateway, virtualService) + gateway, err := sc.getGateway(ctx, gateway, virtualService) + if err != nil { + return nil, err + } if gateway == nil { continue }