From 723f5a2f62b98ec1dbb6f44289d49aa17a2d32cc Mon Sep 17 00:00:00 2001 From: qicz Date: Thu, 1 Aug 2024 17:56:19 +0800 Subject: [PATCH 1/2] bugfix: fix egctl experimental translate with error ns. Signed-off-by: qicz --- internal/cmd/egctl/translate.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/internal/cmd/egctl/translate.go b/internal/cmd/egctl/translate.go index 2bf4cda177f..f3fa03921e8 100644 --- a/internal/cmd/egctl/translate.go +++ b/internal/cmd/egctl/translate.go @@ -63,47 +63,48 @@ func newTranslateCommand() *cobra.Command { addMissingResources bool outTypes []string dnsDomain string + namespace string ) translateCommand := &cobra.Command{ Use: "translate", Short: "Translate Configuration from an input type to an output type", Example: ` # Translate Gateway API Resources into All xDS Resources. - egctl experimental translate --from gateway-api --to xds --file + egctl experimental translate --from gateway-api --to xds --file -n # Translate Gateway API Resources into All xDS Resources in JSON output. - egctl experimental translate --from gateway-api --to xds --type all --output json --file + egctl experimental translate --from gateway-api --to xds --type all --output json --file -n # Translate Gateway API Resources into All xDS Resources in YAML output. - egctl experimental translate --from gateway-api --to xds --type all --output yaml --file + egctl experimental translate --from gateway-api --to xds --type all --output yaml --file -n # Translate Gateway API Resources into Bootstrap xDS Resources. - egctl experimental translate --from gateway-api --to xds --type bootstrap --file + egctl experimental translate --from gateway-api --to xds --type bootstrap --file -n # Translate Gateway API Resources into Cluster xDS Resources. - egctl experimental translate --from gateway-api --to xds --type cluster --file + egctl experimental translate --from gateway-api --to xds --type cluster --file -n # Translate Gateway API Resources into Listener xDS Resources. - egctl experimental translate --from gateway-api --to xds --type listener --file + egctl experimental translate --from gateway-api --to xds --type listener --file -n # Translate Gateway API Resources into Route xDS Resources. - egctl experimental translate --from gateway-api --to xds --type route --file + egctl experimental translate --from gateway-api --to xds --type route --file -n # Translate Gateway API Resources into Cluster xDS Resources with short syntax. - egctl x translate --from gateway-api --to xds -t cluster -o yaml -f + egctl x translate --from gateway-api --to xds -t cluster -o yaml -f -n # Translate Gateway API Resources into All xDS Resources with dummy resources added. - egctl x translate --from gateway-api --to xds -t cluster --add-missing-resources -f + egctl x translate --from gateway-api --to xds -t cluster --add-missing-resources -f -n # Translate Gateway API Resources into All xDS Resources in YAML output, # also print the Gateway API Resources with updated status in the same output. - egctl experimental translate --from gateway-api --to gateway-api,xds --type all --output yaml --file + egctl experimental translate --from gateway-api --to gateway-api,xds --type all --output yaml --file -n # Translate Gateway API Resources into IR in YAML output, egctl experimental translate --from gateway-api --to ir --output yaml --file `, RunE: func(cmd *cobra.Command, args []string) error { - return translate(cmd.OutOrStdout(), inFile, inType, outTypes, output, resourceType, addMissingResources, dnsDomain) + return translate(cmd.OutOrStdout(), inFile, inType, outTypes, output, resourceType, addMissingResources, namespace, dnsDomain) }, } @@ -117,6 +118,8 @@ func newTranslateCommand() *cobra.Command { translateCommand.PersistentFlags().StringVarP(&resourceType, "type", "t", string(AllEnvoyConfigType), getValidResourceTypesStr()) translateCommand.PersistentFlags().BoolVarP(&addMissingResources, "add-missing-resources", "", false, "Provides dummy resources if missed") translateCommand.PersistentFlags().StringVarP(&dnsDomain, "dns-domain", "", "cluster.local", "DNS domain used by k8s services, default is cluster.local") + translateCommand.PersistentFlags().StringVarP(&namespace, "namespace", "n", "envoy-gateway-system", "Namespace where envoy proxy pod are installed.") + return translateCommand } @@ -220,7 +223,7 @@ func validate(inFile, inType string, outTypes []string, resourceType string) err return nil } -func translate(w io.Writer, inFile, inType string, outTypes []string, output, resourceType string, addMissingResources bool, dnsDomain string) error { +func translate(w io.Writer, inFile, inType string, outTypes []string, output, resourceType string, addMissingResources bool, namespace, dnsDomain string) error { if err := validate(inFile, inType, outTypes, resourceType); err != nil { return err } @@ -247,7 +250,7 @@ func translate(w io.Writer, inFile, inType string, outTypes []string, output, re } } if outType == xdsType { - res, err := translateGatewayAPIToXds(dnsDomain, resourceType, resources) + res, err := translateGatewayAPIToXds(namespace, dnsDomain, resourceType, resources) if err != nil { return err } @@ -333,7 +336,7 @@ func translateGatewayAPIToGatewayAPI(resources *gatewayapi.Resources) (gatewayap return gRes.Resources, nil } -func translateGatewayAPIToXds(dnsDomain string, resourceType string, resources *gatewayapi.Resources) (map[string]any, error) { +func translateGatewayAPIToXds(namespace, dnsDomain string, resourceType string, resources *gatewayapi.Resources) (map[string]any, error) { if resources.GatewayClass == nil { return nil, fmt.Errorf("the GatewayClass resource is required") } @@ -363,7 +366,7 @@ func translateGatewayAPIToXds(dnsDomain string, resourceType string, resources * xTranslator := &translator.Translator{ // Set some default settings for translation GlobalRateLimit: &translator.GlobalRateLimitSettings{ - ServiceURL: ratelimit.GetServiceURL("envoy-gateway", dnsDomain), + ServiceURL: ratelimit.GetServiceURL(namespace, dnsDomain), }, } if resources.EnvoyProxyForGatewayClass != nil { From 22720760bd57f5bf997179da42cfacdc6697ca53 Mon Sep 17 00:00:00 2001 From: qi Date: Fri, 2 Aug 2024 10:06:11 +0800 Subject: [PATCH 2/2] Update internal/cmd/egctl/translate.go Co-authored-by: Arko Dasgupta Signed-off-by: qi --- internal/cmd/egctl/translate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/egctl/translate.go b/internal/cmd/egctl/translate.go index f3fa03921e8..ceb4e9deee3 100644 --- a/internal/cmd/egctl/translate.go +++ b/internal/cmd/egctl/translate.go @@ -118,7 +118,7 @@ func newTranslateCommand() *cobra.Command { translateCommand.PersistentFlags().StringVarP(&resourceType, "type", "t", string(AllEnvoyConfigType), getValidResourceTypesStr()) translateCommand.PersistentFlags().BoolVarP(&addMissingResources, "add-missing-resources", "", false, "Provides dummy resources if missed") translateCommand.PersistentFlags().StringVarP(&dnsDomain, "dns-domain", "", "cluster.local", "DNS domain used by k8s services, default is cluster.local") - translateCommand.PersistentFlags().StringVarP(&namespace, "namespace", "n", "envoy-gateway-system", "Namespace where envoy proxy pod are installed.") + translateCommand.PersistentFlags().StringVarP(&namespace, "namespace", "n", "envoy-gateway-system", "Namespace where envoy gateway is installed.") return translateCommand }