mirror of
https://github.com/alibaba/higress.git
synced 2026-04-22 04:27:26 +08:00
feat: support summary output for route/cluster/listener in hgctl gateway-config command (#995) (#996)
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alibaba/higress/pkg/cmd/hgctl/kubernetes"
|
"github.com/alibaba/higress/pkg/cmd/hgctl/kubernetes"
|
||||||
"github.com/alibaba/higress/pkg/cmd/options"
|
"github.com/alibaba/higress/pkg/cmd/options"
|
||||||
|
"istio.io/istio/istioctl/pkg/writer/envoy/configdump"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
@@ -61,6 +62,23 @@ func NewDefaultGetEnvoyConfigOptions() *GetEnvoyConfigOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupConfigdumpEnvoyConfigWriter(debug []byte, stdout io.Writer) (*configdump.ConfigWriter, error) {
|
||||||
|
cw := &configdump.ConfigWriter{Stdout: stdout}
|
||||||
|
err := cw.Prime(debug)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return cw, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetEnvoyConfigWriter(config *GetEnvoyConfigOptions, stdout io.Writer) (*configdump.ConfigWriter, error) {
|
||||||
|
configDump, err := retrieveConfigDump(config.PodName, config.PodNamespace, config.BindAddress, config.IncludeEds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return setupConfigdumpEnvoyConfigWriter(configDump, stdout)
|
||||||
|
}
|
||||||
|
|
||||||
func GetEnvoyConfig(config *GetEnvoyConfigOptions) ([]byte, error) {
|
func GetEnvoyConfig(config *GetEnvoyConfigOptions) ([]byte, error) {
|
||||||
configDump, err := retrieveConfigDump(config.PodName, config.PodNamespace, config.BindAddress, config.IncludeEds)
|
configDump, err := retrieveConfigDump(config.PodName, config.PodNamespace, config.BindAddress, config.IncludeEds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -144,14 +162,12 @@ func formatGatewayConfig(configDump any, output string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if output == "yaml" {
|
if output == "yaml" {
|
||||||
out, err = yaml.JSONToYAML(out)
|
out, err = yaml.JSONToYAML(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
package hgctl
|
package hgctl
|
||||||
|
|
||||||
const (
|
const (
|
||||||
yamlOutput = "yaml"
|
summaryOutput = "short"
|
||||||
jsonOutput = "json"
|
yamlOutput = "yaml"
|
||||||
flagsOutput = "flags"
|
jsonOutput = "json"
|
||||||
|
flagsOutput = "flags"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alibaba/higress/cmd/hgctl/config"
|
"github.com/alibaba/higress/cmd/hgctl/config"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"istio.io/istio/istioctl/pkg/writer/envoy/configdump"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,17 +50,23 @@ func runClusterConfig(c *cobra.Command, args []string) error {
|
|||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
podName = args[0]
|
podName = args[0]
|
||||||
}
|
}
|
||||||
envoyConfig, err := config.GetEnvoyConfig(&config.GetEnvoyConfigOptions{
|
configWriter, err := config.GetEnvoyConfigWriter(&config.GetEnvoyConfigOptions{
|
||||||
PodName: podName,
|
PodName: podName,
|
||||||
PodNamespace: podNamespace,
|
PodNamespace: podNamespace,
|
||||||
BindAddress: bindAddress,
|
BindAddress: bindAddress,
|
||||||
Output: output,
|
Output: output,
|
||||||
EnvoyConfigType: config.ClusterEnvoyConfigType,
|
EnvoyConfigType: config.ClusterEnvoyConfigType,
|
||||||
IncludeEds: true,
|
IncludeEds: true,
|
||||||
})
|
}, c.OutOrStdout())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprintln(c.OutOrStdout(), string(envoyConfig))
|
switch output {
|
||||||
return err
|
case summaryOutput:
|
||||||
|
return configWriter.PrintClusterSummary(configdump.ClusterFilter{})
|
||||||
|
case jsonOutput, yamlOutput:
|
||||||
|
return configWriter.PrintClusterDump(configdump.ClusterFilter{}, output)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("output format %q not supported", output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func newConfigCommand() *cobra.Command {
|
|||||||
flags := cfgCommand.Flags()
|
flags := cfgCommand.Flags()
|
||||||
options.AddKubeConfigFlags(flags)
|
options.AddKubeConfigFlags(flags)
|
||||||
|
|
||||||
cfgCommand.PersistentFlags().StringVarP(&output, "output", "o", "json", "One of 'yaml' or 'json'")
|
cfgCommand.PersistentFlags().StringVarP(&output, "output", "o", "json", "Output format: one of json|yaml|short")
|
||||||
cfgCommand.PersistentFlags().StringVarP(&podNamespace, "namespace", "n", "higress-system", "Namespace where envoy proxy pod are installed.")
|
cfgCommand.PersistentFlags().StringVarP(&podNamespace, "namespace", "n", "higress-system", "Namespace where envoy proxy pod are installed.")
|
||||||
|
|
||||||
return cfgCommand
|
return cfgCommand
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alibaba/higress/cmd/hgctl/config"
|
"github.com/alibaba/higress/cmd/hgctl/config"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"istio.io/istio/istioctl/pkg/writer/envoy/configdump"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,17 +50,23 @@ func runListenerConfig(c *cobra.Command, args []string) error {
|
|||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
podName = args[0]
|
podName = args[0]
|
||||||
}
|
}
|
||||||
envoyConfig, err := config.GetEnvoyConfig(&config.GetEnvoyConfigOptions{
|
configWriter, err := config.GetEnvoyConfigWriter(&config.GetEnvoyConfigOptions{
|
||||||
PodName: podName,
|
PodName: podName,
|
||||||
PodNamespace: podNamespace,
|
PodNamespace: podNamespace,
|
||||||
BindAddress: bindAddress,
|
BindAddress: bindAddress,
|
||||||
Output: output,
|
Output: output,
|
||||||
EnvoyConfigType: config.ListenerEnvoyConfigType,
|
EnvoyConfigType: config.ListenerEnvoyConfigType,
|
||||||
IncludeEds: true,
|
IncludeEds: true,
|
||||||
})
|
}, c.OutOrStdout())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprintln(c.OutOrStdout(), string(envoyConfig))
|
switch output {
|
||||||
return err
|
case summaryOutput:
|
||||||
|
return configWriter.PrintListenerSummary(configdump.ListenerFilter{Verbose: true})
|
||||||
|
case jsonOutput, yamlOutput:
|
||||||
|
return configWriter.PrintListenerDump(configdump.ListenerFilter{Verbose: true}, output)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("output format %q not supported", output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alibaba/higress/cmd/hgctl/config"
|
"github.com/alibaba/higress/cmd/hgctl/config"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"istio.io/istio/istioctl/pkg/writer/envoy/configdump"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,17 +50,23 @@ func runRouteConfig(c *cobra.Command, args []string) error {
|
|||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
podName = args[0]
|
podName = args[0]
|
||||||
}
|
}
|
||||||
envoyConfig, err := config.GetEnvoyConfig(&config.GetEnvoyConfigOptions{
|
configWriter, err := config.GetEnvoyConfigWriter(&config.GetEnvoyConfigOptions{
|
||||||
PodName: podName,
|
PodName: podName,
|
||||||
PodNamespace: podNamespace,
|
PodNamespace: podNamespace,
|
||||||
BindAddress: bindAddress,
|
BindAddress: bindAddress,
|
||||||
Output: output,
|
Output: output,
|
||||||
EnvoyConfigType: config.RouteEnvoyConfigType,
|
EnvoyConfigType: config.RouteEnvoyConfigType,
|
||||||
IncludeEds: true,
|
IncludeEds: true,
|
||||||
})
|
}, c.OutOrStdout())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprintln(c.OutOrStdout(), string(envoyConfig))
|
switch output {
|
||||||
return err
|
case summaryOutput:
|
||||||
|
return configWriter.PrintRouteSummary(configdump.RouteFilter{Verbose: true})
|
||||||
|
case jsonOutput, yamlOutput:
|
||||||
|
return configWriter.PrintRouteDump(configdump.RouteFilter{Verbose: true}, output)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("output format %q not supported", output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user