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

Use Plugins (GetSchema), Workspaces (Exists,Create), Tags (Exists) me… #1321

Merged
merged 19 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
7 changes: 2 additions & 5 deletions cli/ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,10 @@ func main() {
"you must migrate to a Postgres-backed or DB-less deployment")
}

req, _ := http.NewRequest("GET",
cliConfig.KongAdminURL+"/tags", nil)
res, err := kongClient.Do(ctx, req, nil)
if err == nil && res.StatusCode == 200 {
exists, err := kongClient.Tags.Exists(ctx)
if err == nil && exists {
controllerConfig.Kong.HasTagSupport = true
}

// setup workspace in Kong Enterprise
if cliConfig.KongWorkspace != "" {
// ensure the workspace exists or try creating it
Expand Down
27 changes: 10 additions & 17 deletions cli/ingress-controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,24 @@ func getSemVerVer(v string) (semver.Version, error) {
return semver.Make(v)
}

func ensureWorkspace(ctx context.Context, client *kong.Client, workspace string) error {
req, err := client.NewRequest("GET", "/workspaces/"+workspace, nil, nil)
func ensureWorkspace(ctx context.Context, client *kong.Client, workspaceName string) error {
exists, err := client.Workspaces.Exists(ctx, &workspaceName)
if err != nil {
return err
return fmt.Errorf("looking up workspace '%v': %w", workspaceName, err)
}
_, err = client.Do(ctx, req, nil)
if err != nil {
if kong.IsNotFoundErr(err) {
if err := createWorkspace(ctx, client, workspace); err != nil {
return fmt.Errorf("creating workspace '%v': %w", workspace, err)
}
return nil
if !exists {
if err := createWorkspace(ctx, client, workspaceName); err != nil {
return fmt.Errorf("creating workspace '%v': %w", workspaceName, err)
}
return fmt.Errorf("looking up workspace '%v': %w", workspace, err)
}
return nil
}

func createWorkspace(ctx context.Context, client *kong.Client, workspace string) error {
body := map[string]string{"name": workspace}
req, err := client.NewRequest("POST", "/workspaces", nil, body)
if err != nil {
return err
func createWorkspace(ctx context.Context, client *kong.Client, workspaceName string) error {
workspace := &kong.Workspace{
Name: kong.String(workspaceName),
}
_, err = client.Do(ctx, req, nil)
_, err := client.Workspaces.Create(ctx, workspace)
return err
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/util/plugin_schema_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ func (p *PluginSchemaStore) Schema(ctx context.Context, pluginName string) (map[
}

// not present in cache, lookup
req, err := p.client.NewRequest("GET", "/plugins/schema/"+pluginName,
nil, nil)
if err != nil {
return nil, err
}
schema := make(map[string]interface{})
_, err = p.client.Do(ctx, req, &schema)
schema, err := p.client.Plugins.GetSchema(ctx, &pluginName)
if err != nil {
return nil, err
}
Expand Down