From e54d4ebe9911ca899f56c3c078175a12ab624d27 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Fri, 8 Oct 2021 15:18:09 +0200 Subject: [PATCH] fix apiproduct status field for optional resources --- pkg/authproviders/authorino/provider.go | 22 +++++----- pkg/ratelimitproviders/limitador/provider.go | 45 +++++++++++--------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/pkg/authproviders/authorino/provider.go b/pkg/authproviders/authorino/provider.go index 23d3af4..01920d0 100644 --- a/pkg/authproviders/authorino/provider.go +++ b/pkg/authproviders/authorino/provider.go @@ -158,17 +158,19 @@ func (a *Provider) Status(ctx context.Context, apip *networkingv1beta1.APIProduc // If any object is missing/not-created, Status returns false. authConfig := buildAuthConfig(apip) - existingAuthConfig := &authorino.AuthConfig{} - err := a.Client().Get(ctx, client.ObjectKeyFromObject(authConfig), existingAuthConfig) - if err != nil && errors.IsNotFound(err) { - return false, nil - } else if err != nil { - return false, err + if !common.IsObjectTaggedToDelete(authConfig) { + existingAuthConfig := &authorino.AuthConfig{} + err := a.Client().Get(ctx, client.ObjectKeyFromObject(authConfig), existingAuthConfig) + if err != nil && errors.IsNotFound(err) { + return false, nil + } else if err != nil { + return false, err + } + // TODO(jmprusi): No status in authorino serviceConfig objects, yet. + //if !existingServiceConfig.Status.Ready { + // return false, nil + //} } - // TODO(jmprusi): No status in authorino serviceConfig objects, yet. - //if !existingServiceConfig.Status.Ready { - // return false, nil - //} return true, nil } diff --git a/pkg/ratelimitproviders/limitador/provider.go b/pkg/ratelimitproviders/limitador/provider.go index e1040a2..2a44019 100644 --- a/pkg/ratelimitproviders/limitador/provider.go +++ b/pkg/ratelimitproviders/limitador/provider.go @@ -110,37 +110,40 @@ func (p *Provider) Delete(ctx context.Context, apip *networkingv1beta1.APIProduc func (p *Provider) Status(ctx context.Context, apip *networkingv1beta1.APIProduct) (bool, error) { log := p.Logger().WithValues("apiproduct", client.ObjectKeyFromObject(apip)) log.V(1).Info("Status") - if apip.Spec.RateLimit == nil { - return true, nil - } // Right now, we just try to get all the objects that should have been created, and check their status. // If any object is missing/not-created, Status returns false. desiredGlobalRateLimit := p.globalRateLimit(apip) - existing := &limitadorv1alpha1.RateLimit{} - err := p.GetResource(ctx, client.ObjectKeyFromObject(desiredGlobalRateLimit), existing) - if err != nil && apierrors.IsNotFound(err) { - return false, nil - } else if err != nil { - return false, err + if !common.IsObjectTaggedToDelete(desiredGlobalRateLimit) { + existing := &limitadorv1alpha1.RateLimit{} + err := p.GetResource(ctx, client.ObjectKeyFromObject(desiredGlobalRateLimit), existing) + if err != nil && apierrors.IsNotFound(err) { + return false, nil + } else if err != nil { + return false, err + } } desiredperRemoteIPRateLimit := p.perRemoteIPRateLimit(apip) - existing = &limitadorv1alpha1.RateLimit{} - err = p.GetResource(ctx, client.ObjectKeyFromObject(desiredperRemoteIPRateLimit), existing) - if err != nil && apierrors.IsNotFound(err) { - return false, nil - } else if err != nil { - return false, err + if !common.IsObjectTaggedToDelete(desiredperRemoteIPRateLimit) { + existing := &limitadorv1alpha1.RateLimit{} + err := p.GetResource(ctx, client.ObjectKeyFromObject(desiredperRemoteIPRateLimit), existing) + if err != nil && apierrors.IsNotFound(err) { + return false, nil + } else if err != nil { + return false, err + } } authenticatedAuthRateLimit := p.authenticatedRateLimit(apip) - existing = &limitadorv1alpha1.RateLimit{} - err = p.GetResource(ctx, client.ObjectKeyFromObject(authenticatedAuthRateLimit), existing) - if err != nil && apierrors.IsNotFound(err) { - return false, nil - } else if err != nil { - return false, err + if !common.IsObjectTaggedToDelete(authenticatedAuthRateLimit) { + existing := &limitadorv1alpha1.RateLimit{} + err := p.GetResource(ctx, client.ObjectKeyFromObject(authenticatedAuthRateLimit), existing) + if err != nil && apierrors.IsNotFound(err) { + return false, nil + } else if err != nil { + return false, err + } } return true, nil