github.com/cilium/cilium@v1.16.2/clustermesh-apiserver/kvstoremesh-dbg/troubleshoot.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package dbg 5 6 import ( 7 "context" 8 "fmt" 9 "os" 10 "time" 11 12 "github.com/spf13/cobra" 13 14 ciliumdbg "github.com/cilium/cilium/cilium-dbg/cmd" 15 "github.com/cilium/cilium/pkg/kvstore" 16 ) 17 18 var Troubleshoot = func() *cobra.Command { 19 var etcdcfg, cmcfg string 20 var timeout time.Duration 21 var local bool 22 23 cmd := &cobra.Command{ 24 Use: "troubleshoot [clusters...]", 25 Short: "Troubleshoot connectivity towards the local etcd kvstore and remote clusters", 26 Run: func(cmd *cobra.Command, args []string) { 27 // KVStoreMesh runs in pod network, so we don't need any 28 // special logic for k8s service to IP resolution. 29 dialer := kvstore.DefaultEtcdDbgDialer{} 30 stdout := cmd.OutOrStdout() 31 32 if local { 33 fmt.Fprintf(stdout, "Local etcd kvstore:\n") 34 cctx, cancel := context.WithTimeout(cmd.Context(), timeout) 35 kvstore.EtcdDbg(cctx, etcdcfg, dialer, stdout) 36 fmt.Fprintf(stdout, "\n\n") 37 cancel() 38 } 39 40 // Try to retrieve the cluster name from the corresponding environment variable. 41 // It is only used to provide a hint if the configuration for the local cluster 42 // is present, hence it is not a big deal if we fail to retrieve it. 43 localClusterName, _ := os.LookupEnv("CLUSTER_NAME") 44 45 ciliumdbg.TroubleshootClusterMesh(cmd.Context(), stdout, dialer, cmcfg, timeout, localClusterName, args...) 46 }, 47 } 48 49 RootCmd.AddCommand(cmd) 50 51 flags := cmd.Flags() 52 flags.StringVar(&etcdcfg, "etcd-config", "/var/lib/cilium/etcd-config.yaml", "Path to the etcd configuration") 53 flags.StringVar(&cmcfg, "clustermesh-config", "/var/lib/cilium/clustermesh/", "Path to the ClusterMesh configuration directory") 54 flags.BoolVar(&local, "include-local", false, "Additionally troubleshoot connectivity to the local etcd instance") 55 flags.DurationVar(&timeout, "timeout", 5*time.Second, "Timeout when checking connectivity to a given etcd kvstore") 56 57 return cmd 58 }()