Skip to content

Feat: ai gateway file convert#2137

Open
harshadixit12 wants to merge 11 commits into
mainfrom
feat/ai-gateway-file-convert
Open

Feat: ai gateway file convert#2137
harshadixit12 wants to merge 11 commits into
mainfrom
feat/ai-gateway-file-convert

Conversation

@harshadixit12

@harshadixit12 harshadixit12 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

In this PR, we are adding support for a new command deck file ai2kong which accepts a AI gateway declarative config, and converts it to kong 3.x format declarative config to be used with on prem AI Gateway.

Implements

#2148

@harshadixit12 harshadixit12 changed the title Feat/ai gateway file convert Feat: ai gateway file convert Jul 14, 2026
@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.32%. Comparing base (41f6c66) to head (fb7de74).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
cmd/file_ai2kong.go 0.00% 60 Missing ⚠️
tests/integration/test_utils.go 0.00% 14 Missing ⚠️
cmd/root.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2137      +/-   ##
==========================================
- Coverage   36.73%   36.32%   -0.41%     
==========================================
  Files          78       79       +1     
  Lines        7429     7504      +75     
==========================================
- Hits         2729     2726       -3     
- Misses       4455     4532      +77     
- Partials      245      246       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@harshadixit12 harshadixit12 marked this pull request as ready for review July 14, 2026 09:01
Comment thread cmd/file_ai2kong.go
// Print warnings to stderr
if len(warnings) > 0 {
for _, warning := range warnings {
fmt.Fprintf(os.Stderr, "Warning: %v\n", warning)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would break json output, right?
Are we concerned about that right now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that we are using YAML everywhere for now. We can revisit this later. Let's add a TODO comment on top so that we don't miss this when we add JSON support.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally - yes, we should - but i'll get to this once all PRs have been merged.

Comment thread cmd/file_ai2kong.go Outdated
return fmt.Errorf("failed to read source file: %w", err)
}

converted, warnings, err := convert.Convert(sourceContent, convert.Options{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Can we import this as ai2kong and call ai2kong.Convert()?
It will be more verbose and avoid the confusing repetition.

Comment thread cmd/file_ai2kong.go
}

func validateAi2KongFlags(_ *cobra.Command, _ []string) error {
if convertSourceFile == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can take only one file at a time for conversion, right?
If yes, can we add a validation for that too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For flag type of string - cobra follows "last value" wins - so additional validation is not needed. (same in openapi2kong)

Comment thread cmd/file_ai2kong.go Outdated
if docMap, ok := doc.(map[string]interface{}); ok {
if infoMap, ok := docMap["_info"].(map[string]interface{}); ok {
// _info exists, update select_tags
infoMap["select_tags"] = []string{"managed-by:deck-ai"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can over-write the existing select-tags.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is converting an ai gateway file -> deck, the ai gateway file won't have select tags at global level

Comment thread cmd/file_ai2kong.go Outdated
} else {
// _info doesn't exist, create it with select_tags
docMap["_info"] = map[string]interface{}{
"select_tags": []string{"managed-by:deck-ai"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. managed-by:deck-ai should be a constant
  2. Elsewhere, the convention I have seen is managed_by. Should we follow that or is this one a request from product?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will be made constant - this was a suggestion, not a request. I'll update it to managed_by.

Comment thread cmd/file_ai2kong.go Outdated
cmd := &cobra.Command{
Use: "ai2kong",
Short: "Generate Kong configuration from AI Gateway configuration",
Long: `This command takes an AI Gateway 2.0 entity model and converts it to a standard decK state file`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we are adding a tag ourselves for our internal working, I think we should explicitly call that out in the description. It will help endusers to know that the tag addition is expected and they shouldn't remove it.

Comment thread cmd/file_ai2kong.go Outdated
}

// Parse the converted YAML to add select_tags to _info
var doc interface{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I feel L64 to L81 can be abstracted out in a different function.

Comment thread cmd/file_ai2kong.go Outdated
defer outFile.Close()
outputWriter = outFile
} else {
outputWriter = os.Stdout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be the default IMO rather than adding a nesting here with else.

Comment thread cmd/file_ai2kong.go
}

// marshalToYAML encodes v as YAML using a two-space indent.
func marshalToYAML(v interface{}) ([]byte, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason for a separate func for this?

err = yaml.Unmarshal([]byte(output), &currentOutput)
require.NoError(t, err)

assert.Equal(t, expectedOutput, currentOutput)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we consider syncing the output to an ai gateway for validity?
We need to support the decomposed flow as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was planning to do that in the tests for sync and dump in the chained PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants