github.com/cilium/cilium@v1.16.2/clustermesh-apiserver/clustermesh-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  	"time"
    10  
    11  	"github.com/spf13/cobra"
    12  
    13  	"github.com/cilium/cilium/pkg/kvstore"
    14  )
    15  
    16  var Troubleshoot = func() *cobra.Command {
    17  	var etcdcfg string
    18  	var timeout time.Duration
    19  
    20  	cmd := &cobra.Command{
    21  		Use:   "troubleshoot",
    22  		Short: "Troubleshoot connectivity towards the local etcd kvstore",
    23  		Run: func(cmd *cobra.Command, args []string) {
    24  			stdout := cmd.OutOrStdout()
    25  
    26  			fmt.Fprintf(stdout, "Local etcd kvstore:\n")
    27  			cctx, cancel := context.WithTimeout(cmd.Context(), timeout)
    28  			kvstore.EtcdDbg(cctx, etcdcfg, kvstore.DefaultEtcdDbgDialer{}, stdout)
    29  			cancel()
    30  		},
    31  	}
    32  
    33  	RootCmd.AddCommand(cmd)
    34  
    35  	flags := cmd.Flags()
    36  	flags.StringVar(&etcdcfg, "etcd-config", "/var/lib/cilium/etcd-config.yaml", "Path to the etcd configuration")
    37  	flags.DurationVar(&timeout, "timeout", 5*time.Second, "Timeout when checking connectivity to the etcd kvstore")
    38  
    39  	return cmd
    40  }()