Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
fix apiproduct status field for optional resources
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Oct 14, 2021
1 parent 87f5b4f commit e54d4eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
22 changes: 12 additions & 10 deletions pkg/authproviders/authorino/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
45 changes: 24 additions & 21 deletions pkg/ratelimitproviders/limitador/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e54d4eb

Please sign in to comment.