Skip to content

Commit

Permalink
Merge pull request #188 from sawsa307/ir-interface
Browse files Browse the repository at this point in the history
Create IR structs, and merge functions for IRs.
  • Loading branch information
k8s-ci-robot authored Sep 10, 2024
2 parents 7556614 + 859f2c9 commit a7628a8
Show file tree
Hide file tree
Showing 58 changed files with 3,650 additions and 1,769 deletions.
33 changes: 32 additions & 1 deletion cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
"github.com/samber/lo"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -203,6 +205,17 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
}
}

for _, r := range gatewayResources {
resourceCount += len(r.GatewayExtensions)
for _, gatewayExtension := range r.GatewayExtensions {
gatewayExtension := gatewayExtension
fmt.Println("---")
if err := PrintUnstructuredAsYaml(&gatewayExtension); err != nil {
fmt.Printf("# Error printing %s gatewayExtension: %v\n", gatewayExtension.GetName(), err)
}
}
}

if resourceCount == 0 {
msg := "No resources found"
if pr.namespaceFilter != "" {
Expand Down Expand Up @@ -269,7 +282,7 @@ func newPrintCommand() *cobra.Command {
Use: "print",
Short: "Prints Gateway API objects generated from ingress and provider-specific resources.",
RunE: pr.PrintGatewayAPIObjects,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(_ *cobra.Command, _ []string) error {
openAPIExist := slices.Contains(pr.providers, "openapi3")
if openAPIExist && len(pr.providers) != 1 {
return fmt.Errorf("openapi3 must be the only provider when specified")
Expand Down Expand Up @@ -334,3 +347,21 @@ func (pr *PrintRunner) getProviderSpecificFlags() map[string]map[string]string {
}
return providerSpecificFlags
}

func PrintUnstructuredAsYaml(obj *unstructured.Unstructured) error {
// Create a YAML serializer
serializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, nil, nil,
json.SerializerOptions{
Yaml: true,
Pretty: true, // Optional: for better readability
Strict: true,
})

// Encode the unstructured object to YAML
err := serializer.Encode(obj, os.Stdout)
if err != nil {
return err
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "ingress2gateway",
Short: "Convert Ingress manifests to Gateway API manifests",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(_ *cobra.Command, _ []string) {
getKubeconfig()
},
}
Expand Down
58 changes: 30 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/kubernetes-sigs/ingress2gateway

go 1.21
go 1.22.0

require (
github.com/GoogleCloudPlatform/gke-gateway-api v1.3.0
github.com/getkin/kin-openapi v0.124.0
github.com/google/go-cmp v0.6.0
github.com/kong/kubernetes-ingress-controller/v2 v2.12.3
Expand All @@ -11,38 +12,40 @@ require (
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
istio.io/api v1.20.0
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/cli-runtime v0.28.4
k8s.io/client-go v0.28.4
k8s.io/utils v0.0.0-20231121161247-cf03d44ff3cf
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/gateway-api v1.0.0
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/cli-runtime v0.29.0
k8s.io/client-go v0.30.0
k8s.io/ingress-gce v1.30.0
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
sigs.k8s.io/controller-runtime v0.18.0
sigs.k8s.io/gateway-api v1.1.0
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand All @@ -64,24 +67,23 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.33.0
gopkg.in/evanphx/json-patch.v5 v5.7.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
istio.io/client-go v1.19.0-alpha.1.0.20231130185426-9f1859c8ff42
k8s.io/klog/v2 v2.110.1
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
k8s.io/klog/v2 v2.120.1
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.15.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
Expand Down
Loading

0 comments on commit a7628a8

Please sign in to comment.