Skip to content

Commit

Permalink
apply updates based on changes in decK and Koko
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefero committed Dec 12, 2023
1 parent 08fd55d commit 6768b91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
5 changes: 1 addition & 4 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ func syncMain(ctx context.Context, filenames []string, dry bool, parallelism,
var kongVersion string
var parsedKongVersion semver.Version
if mode == modeKonnect {
kongVersion, err = fetchKonnectKongVersion(ctx, kongClient)
if err != nil {
return fmt.Errorf("reading Konnect Kong version: %w", err)
}
kongVersion = fetchKonnectKongVersion()
} else {
kongVersion, err = fetchKongVersion(ctx, wsConfig)
if err != nil {
Expand Down
26 changes: 7 additions & 19 deletions cmd/common_konnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -172,10 +171,6 @@ func dumpKonnectV2(ctx context.Context) error {
if dumpConfig.KonnectRuntimeGroup == "" {
dumpConfig.KonnectRuntimeGroup = defaultRuntimeGroupName
}
kongVersion, err := fetchKonnectKongVersion(ctx, client)
if err != nil {
return fmt.Errorf("reading Konnect Kong version: %w", err)
}
rawState, err := dump.Get(ctx, client, dumpConfig)
if err != nil {
return fmt.Errorf("reading configuration from Kong: %w", err)
Expand All @@ -190,7 +185,7 @@ func dumpKonnectV2(ctx context.Context) error {
FileFormat: file.Format(strings.ToUpper(konnectDumpCmdStateFormat)),
WithID: dumpWithID,
RuntimeGroupName: konnectRuntimeGroup,
KongVersion: kongVersion,
KongVersion: fetchKonnectKongVersion(),
})
}

Expand Down Expand Up @@ -386,17 +381,10 @@ func getKonnectState(ctx context.Context,
return ks, nil
}

func fetchKonnectKongVersion(ctx context.Context, client *kong.Client) (string, error) {
req, err := http.NewRequest("GET",
utils.CleanAddress(client.BaseRootURL())+"/v1", nil)
if err != nil {
return "", err
}

var resp map[string]interface{}
_, err = client.Do(ctx, req, &resp)
if err != nil {
return "", err
}
return resp["version"].(string), nil
func fetchKonnectKongVersion() string {
// Returning an hardcoded version for now. decK only needs the version
// to determine the format_version expected in the state file. Since
// Konnect is always on the latest version, we can safely return the
// latest version here and avoid making an extra and unnecessary request.
return "3.5.0.0"
}
4 changes: 2 additions & 2 deletions cmd/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ can connect to Kong's Admin API.`,
func pingKonnect(ctx context.Context) error {
// get Konnect client
httpClient := utils.HTTPClient()
kongClient, err := GetKongClientForKonnectMode(ctx, &konnectConfig)
_, err := GetKongClientForKonnectMode(ctx, &konnectConfig)
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func pingKonnect(ctx context.Context) error {
}
u, _ := url.Parse(konnectConfig.Address)
if konnectConfig.Dev {
version, err := fetchKonnectKongVersion(ctx, kongClient)
version := fetchKonnectKongVersion()
if err != nil {
return fmt.Errorf("reading Konnect Kong version: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kong/deck
go 1.18

replace github.com/yudai/gojsondiff v1.0.0 => github.com/Kong/gojsondiff v1.3.0
replace github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662 => /home/aboudreault/dev/kong/go-kong
replace github.com/kong/go-kong v0.34.1-0.20221222170410-6c81ce561662 => ./go-kong

require (
github.com/Kong/gojsondiff v1.3.2
Expand Down

0 comments on commit 6768b91

Please sign in to comment.