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

feat: support online validation with Konnect #1335

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
29 changes: 20 additions & 9 deletions cmd/gateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ var (

func executeValidate(cmd *cobra.Command, _ []string) error {
mode := getMode(nil)
if validateOnline && mode == modeKonnect {
return fmt.Errorf("online validation not yet supported in konnect mode")
}
_ = sendAnalytics("validate", "", mode)
// read target file
// this does json schema validation as well
Expand All @@ -45,7 +42,7 @@ func executeValidate(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
var kongClient *kong.Client
if validateOnline {
kongClient, err = getKongClient(ctx, targetContent)
kongClient, err = getKongClient(ctx, targetContent, mode)
if err != nil {
return err
}
Expand Down Expand Up @@ -285,7 +282,9 @@ func validateWithKong(
return validator.Validate(parsedFormatVersion)
}

func getKongClient(ctx context.Context, targetContent *file.Content) (*kong.Client, error) {
func getKongClient(
ctx context.Context, targetContent *file.Content, mode mode,
) (*kong.Client, error) {
workspaceName := validateWorkspace
if validateWorkspace != "" {
// check if workspace exists
Expand All @@ -299,10 +298,22 @@ func getKongClient(ctx context.Context, targetContent *file.Content) (*kong.Clie
}
}

wsConfig := rootConfig.ForWorkspace(workspaceName)
kongClient, err := reconcilerUtils.GetKongClient(wsConfig)
if err != nil {
return nil, err
var (
kongClient *kong.Client
err error
)
if mode == modeKonnect {
kongClient, err = GetKongClientForKonnectMode(ctx, &konnectConfig)
if err != nil {
return nil, err
}
dumpConfig.KonnectControlPlane = konnectControlPlane
} else {
wsConfig := rootConfig.ForWorkspace(workspaceName)
kongClient, err = reconcilerUtils.GetKongClient(wsConfig)
if err != nil {
return nil, err
}
}
return kongClient, nil
}
Expand Down
3 changes: 3 additions & 0 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func (v *Validator) Validate(formatVersion semver.Version) []error {
if err := v.entities(v.state.FilterChains, "filter_chains"); err != nil {
allErr = append(allErr, err...)
}
if err := v.entities(v.state.Vaults, "vaults"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I lack some context here. How is this addition related to this PR? @GGabriele

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping: @GGabriele. Do you mind chiming in here? 🙇

allErr = append(allErr, err...)
}

// validate routes format with Kong 3.x
parsed30, err := semver.ParseTolerant(utils.FormatVersion30)
Expand Down
Loading