mirror of
https://github.com/alibaba/higress.git
synced 2026-04-22 04:27:26 +08:00
feat: add support for hgctl gateway-config to retrieve higress gateway config (#274)
Signed-off-by: bitliu <bitliu@tencent.com>
This commit is contained in:
79
pkg/cmd/hgctl/configCmd.go
Normal file
79
pkg/cmd/hgctl/configCmd.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2022 Alibaba Group Holding Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package hgctl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/alibaba/higress/pkg/cmd/options"
|
||||
"github.com/spf13/cobra"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
)
|
||||
|
||||
func newConfigCommand() *cobra.Command {
|
||||
cfgCommand := &cobra.Command{
|
||||
Use: "gateway-config",
|
||||
Aliases: []string{"gc"},
|
||||
Short: "Retrieve Higress Gateway configuration.",
|
||||
Long: "Retrieve information about Higress Gateway Configuration.",
|
||||
}
|
||||
|
||||
cfgCommand.AddCommand(allConfigCmd())
|
||||
cfgCommand.AddCommand(bootstrapConfigCmd())
|
||||
cfgCommand.AddCommand(clusterConfigCmd())
|
||||
cfgCommand.AddCommand(endpointConfigCmd())
|
||||
cfgCommand.AddCommand(listenerConfigCmd())
|
||||
cfgCommand.AddCommand(routeConfigCmd())
|
||||
|
||||
flags := cfgCommand.Flags()
|
||||
options.AddKubeConfigFlags(flags)
|
||||
|
||||
cfgCommand.PersistentFlags().StringVarP(&output, "output", "o", "json", "One of 'yaml' or 'json'")
|
||||
cfgCommand.PersistentFlags().StringVarP(&podNamespace, "namespace", "n", "higress-system", "Namespace where envoy proxy pod are installed.")
|
||||
|
||||
return cfgCommand
|
||||
}
|
||||
|
||||
func allConfigCmd() *cobra.Command {
|
||||
configCmd := &cobra.Command{
|
||||
Use: "all <pod-name>",
|
||||
Short: "Retrieves all Envoy xDS resources from the specified Higress Gateway Pod",
|
||||
Long: `Retrieves information about all Envoy xDS resources from the specified Higress Gateway Pod`,
|
||||
Example: ` # Retrieve summary about all configuration for a given pod from Envoy.
|
||||
hgctl gateway-config all <pod-name> -n <pod-namespace>
|
||||
|
||||
# Retrieve full configuration dump as YAML
|
||||
hgctl gateway-config all <pod-name> -n <pod-namespace> -o yaml
|
||||
|
||||
# Retrieve full configuration dump with short syntax
|
||||
hgctl gc all <pod-name> -n <pod-namespace>
|
||||
`,
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(runAllConfig(c, args))
|
||||
},
|
||||
}
|
||||
|
||||
return configCmd
|
||||
}
|
||||
|
||||
func runAllConfig(c *cobra.Command, args []string) error {
|
||||
configDump, err := retrieveConfigDump(args, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintln(c.OutOrStdout(), string(configDump))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user