...

Source file src/github.com/linkerd/linkerd2/viz/cmd/prune.go

Documentation: github.com/linkerd/linkerd2/viz/cmd

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"time"
     7  
     8  	pkgCmd "github.com/linkerd/linkerd2/pkg/cmd"
     9  	"github.com/linkerd/linkerd2/pkg/flags"
    10  	"github.com/linkerd/linkerd2/pkg/healthcheck"
    11  	"github.com/linkerd/linkerd2/pkg/k8s"
    12  	vizHealthcheck "github.com/linkerd/linkerd2/viz/pkg/healthcheck"
    13  	"github.com/spf13/cobra"
    14  	"helm.sh/helm/v3/pkg/cli/values"
    15  )
    16  
    17  func newCmdPrune() *cobra.Command {
    18  	var ha bool
    19  	var cniEnabled bool
    20  	var wait time.Duration
    21  	var options values.Options
    22  
    23  	cmd := &cobra.Command{
    24  		Use:   "prune [flags]",
    25  		Args:  cobra.NoArgs,
    26  		Short: "Output extraneous Kubernetes resources in the linkerd-viz extension",
    27  		Long:  `Output extraneous Kubernetes resources in the linkerd-viz extension.`,
    28  		Example: `  # Prune extraneous resources.
    29    linkerd viz prune | kubectl delete -f -
    30    `,
    31  		RunE: func(cmd *cobra.Command, _ []string) error {
    32  			hc := healthcheck.NewWithCoreChecks(&healthcheck.Options{
    33  				ControlPlaneNamespace: controlPlaneNamespace,
    34  				KubeConfig:            kubeconfigPath,
    35  				KubeContext:           kubeContext,
    36  				Impersonate:           impersonate,
    37  				ImpersonateGroup:      impersonateGroup,
    38  				APIAddr:               apiAddr,
    39  				RetryDeadline:         time.Now().Add(wait),
    40  			})
    41  			hc.RunWithExitOnError()
    42  			cniEnabled = hc.CNIEnabled
    43  
    44  			manifests := strings.Builder{}
    45  
    46  			err := install(&manifests, options, ha, cniEnabled)
    47  			if err != nil {
    48  				return err
    49  			}
    50  
    51  			label := fmt.Sprintf("%s=%s", k8s.LinkerdExtensionLabel, vizHealthcheck.VizExtensionName)
    52  			return pkgCmd.Prune(cmd.Context(), hc.KubeAPIClient(), manifests.String(), label)
    53  		},
    54  	}
    55  
    56  	cmd.Flags().BoolVar(&ha, "ha", false, `Set if Linkerd Viz Extension is installed in High Availability mode.`)
    57  	cmd.Flags().DurationVar(&wait, "wait", 300*time.Second, "Wait for extension components to be available")
    58  
    59  	flags.AddValueOptionsFlags(cmd.Flags(), &options)
    60  
    61  	return cmd
    62  }
    63  

View as plain text