Skip to content

Commit

Permalink
fix(Kong#5658): handle edge cases for tag filtering detection
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Quoc Trung <trung.hoang@pricehubble.com>
  • Loading branch information
ichbinfrog committed Mar 6, 2024
1 parent 9783552 commit 7d28faf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
30 changes: 21 additions & 9 deletions internal/dataplane/sendconfig/kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sendconfig

import (
"context"
"errors"
"fmt"

"github.com/blang/semver/v4"
Expand All @@ -11,6 +12,11 @@ import (
"github.com/kong/kubernetes-ingress-controller/v3/internal/adminapi"
)

var (
ErrAdminAPIUnreachable = errors.New("Kong Admin API is unreachable")
ErrAdminAPITagsDisabled = errors.New("Kong Admin API does not support tags")
)

// Config gathers parameters that are needed for sending configuration to Kong Admin APIs.
type Config struct {
// Currently, this assumes that all underlying clients are using the same version
Expand Down Expand Up @@ -47,13 +53,18 @@ func (c *Config) Init(
ctx context.Context,
logger logr.Logger,
kongClients []*adminapi.Client,
) {
) error {
if err := tagsFilteringEnabled(ctx, kongClients); err != nil {
logger.Error(err, "Tag filtering disabled")
c.FilterTags = nil
} else {
logger.Info("Tag filtering enabled", "tags", c.FilterTags)
if errors.Is(err, ErrAdminAPITagsDisabled) {
logger.Error(err, "Tag filtering disabled")
c.FilterTags = nil
return nil
}
return err
}

logger.Info("Tag filtering enabled", "tags", c.FilterTags)
return nil
}

func tagsFilteringEnabled(ctx context.Context, kongClients []*adminapi.Client) error {
Expand All @@ -62,11 +73,12 @@ func tagsFilteringEnabled(ctx context.Context, kongClients []*adminapi.Client) e
cl := cl
errg.Go(func() error {
ok, err := cl.AdminAPIClient().Tags.Exists(ctx)
if err != nil {
return fmt.Errorf("Kong Admin API (%s) does not support tags: %w", cl.BaseRootURL(), err)
}

if !ok {
return fmt.Errorf("Kong Admin API (%s) does not support tags", cl.BaseRootURL())
if err == nil {
return fmt.Errorf("%w", ErrAdminAPIUnreachable)
}
return fmt.Errorf("%w: %w", ErrAdminAPIUnreachable, err)
}
return nil
})
Expand Down
4 changes: 3 additions & 1 deletion internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func Run(
ExpressionRoutes: dpconf.ShouldEnableExpressionRoutes(routerFlavor),
SanitizeKonnectConfigDumps: featureGates.Enabled(featuregates.SanitizeKonnectConfigDumps),
}
kongConfig.Init(ctx, setupLog, initialKongClients)
if err := kongConfig.Init(ctx, setupLog, initialKongClients); err != nil {
return fmt.Errorf("unable to check if tags filtering is enabled: %w", err)
}

setupLog.Info("Configuring and building the controller manager")
managerOpts, err := setupManagerOptions(ctx, setupLog, c, dbMode)
Expand Down

0 comments on commit 7d28faf

Please sign in to comment.