Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager) lock client creation #2070

Merged
merged 4 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ the `configuration.konghq.com` API group.
credentials secrets on update of secrets, and on create or update of
KongConsumers.
[#729](https://github.com/Kong/kubernetes-ingress-controller/issues/729)
- Fixed a race condition where multiple actors may simultaneously attempt to
create the configured Enterprise workspaces.
[#2070](https://github.com/Kong/kubernetes-ingress-controller/pull/2070)

## [2.0.6]

Expand Down
5 changes: 5 additions & 0 deletions internal/adminapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"fmt"
"net/http"
"os"
"sync"

"github.com/kong/go-kong/kong"
)

var clientSetup sync.Mutex

// HTTPClientOpts defines parameters that configure an HTTP client.
type HTTPClientOpts struct {
TLSSkipVerify bool
Expand Down Expand Up @@ -89,6 +92,7 @@ func GetKongClientForWorkspace(ctx context.Context, adminURL string, wsName stri
}

// if a workspace was provided, verify whether or not it exists.
clientSetup.Lock()
exists, err := client.Workspaces.ExistsByName(ctx, kong.String(wsName))
if err != nil {
return nil, fmt.Errorf("looking up workspace: %w", err)
Expand All @@ -104,6 +108,7 @@ func GetKongClientForWorkspace(ctx context.Context, adminURL string, wsName stri
return nil, fmt.Errorf("creating workspace: %w", err)
}
}
clientSetup.Unlock()

// ensure that we set the workspace appropriately
client.SetWorkspace(wsName)
Expand Down