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

merge kic test #1049

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
uses: actions/checkout@v3
- name: Setup golangci-lint
uses: golangci/[email protected]
with:
args: --timeout=30m
- name: Verify Codegen
run: make verify-codegen
- name: Run tests with Coverage
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ _testmain.go
*.test
*.prof

# Apple cruft
.DS_Store

# for this repo only
deck
dist/
docs/cli-docs/
.idea/
92 changes: 92 additions & 0 deletions cmd/file_kong2kic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package cmd

import (
"fmt"
"log"
"strings"

"github.com/kong/deck/file"
"github.com/kong/go-apiops/logbasics"
"github.com/spf13/cobra"
)

var (
cmdKong2KicInputFilename string
cmdKong2KicOutputFilename string
// cmdKong2KicApi string
cmdKong2KicOutputFormat string
cmdKong2KicManifestStyle string
)

// Executes the CLI command "kong2kic"
func executeKong2Kic(cmd *cobra.Command, _ []string) error {
var (
outputContent *file.Content
err error
outputFileFormat file.Format
)

verbosity, _ := cmd.Flags().GetInt("verbose")
logbasics.Initialize(log.LstdFlags, verbosity)

inputContent, err := file.GetContentFromFiles([]string{cmdKong2KicInputFilename}, false)
if err != nil {
return fmt.Errorf("failed reding input file '%s'; %w", cmdKong2KicInputFilename, err)
}

outputContent = inputContent.DeepCopy()
if strings.ToUpper(cmdKong2KicOutputFormat) == "JSON" &&
strings.ToUpper(cmdKong2KicManifestStyle) == "CRD" {
outputFileFormat = file.KICJSONCrd
} else if strings.ToUpper(cmdKong2KicOutputFormat) == "JSON" &&
strings.ToUpper(cmdKong2KicManifestStyle) == "ANNOTATION" {
outputFileFormat = file.KICJSONAnnotation
} else if strings.ToUpper(cmdKong2KicOutputFormat) == "YAML" &&
strings.ToUpper(cmdKong2KicManifestStyle) == "CRD" {
outputFileFormat = file.KICYAMLCrd
} else if strings.ToUpper(cmdKong2KicOutputFormat) == "YAML" &&
strings.ToUpper(cmdKong2KicManifestStyle) == "ANNOTATION" {
outputFileFormat = file.KICYAMLAnnotation
} else {
return fmt.Errorf("invalid combination of output format and manifest style")
}

err = file.WriteContentToFile(outputContent, cmdKong2KicOutputFilename, outputFileFormat)

if err != nil {
return fmt.Errorf("failed converting Kong to Ingress '%s'; %w", cmdKong2KicInputFilename, err)
}

return nil
}

//
//
// Define the CLI data for the openapi2kong command
//
//

func newKong2KicCmd() *cobra.Command {
kong2KicCmd := &cobra.Command{
Use: "kong2kic",
Short: "Convert Kong configuration files to Kong Ingress Controller (KIC) manifests",
Long: `Convert Kong configuration files to Kong Ingress Controller (KIC) manifests.

Manifests can be generated using annotations in Ingress and Service objects (recommended) or
using the KongIngress CRD. Output in YAML or JSON format.`,
RunE: executeKong2Kic,
Args: cobra.NoArgs,
}

kong2KicCmd.Flags().StringVarP(&cmdKong2KicInputFilename, "state", "s", "-",
"decK file to process. Use - to read from stdin.")
kong2KicCmd.Flags().StringVarP(&cmdKong2KicOutputFilename, "output-file", "o", "-",
"Output file to write. Use - to write to stdout.")
kong2KicCmd.Flags().StringVar(&cmdKong2KicManifestStyle, "style", "annotation",
"Generate manifests with annotations in Service and Ingress, or using the KongIngress CRD: annotation or crd.")
kong2KicCmd.Flags().StringVarP(&cmdKong2KicOutputFormat, "format", "f", "yaml",
"output file format: json or yaml.")
// kong2KicCmd.Flags().StringVarP(&cmdKong2KicApi, "api", "a", "ingress", "[ingress|gateway]")

return kong2KicCmd
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ It can be used to export, import, or sync entities to Kong.`,
fileCmd.AddCommand(newPatchCmd())
fileCmd.AddCommand(newOpenapi2KongCmd())
fileCmd.AddCommand(newFileRenderCmd())
fileCmd.AddCommand(newKong2KicCmd())
}
return rootCmd
}
Expand Down
1 change: 1 addition & 0 deletions convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func Test_Convert(t *testing.T) {
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inputFiles := tt.args.inputFilenames
Expand Down
Loading
Loading