...

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

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

     1  package cmd
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"os"
     7  	"strings"
     8  	"time"
     9  
    10  	pkgCmd "github.com/linkerd/linkerd2/pkg/cmd"
    11  	"github.com/linkerd/linkerd2/pkg/k8s"
    12  	"github.com/spf13/cobra"
    13  	valuespkg "helm.sh/helm/v3/pkg/cli/values"
    14  )
    15  
    16  func newCmdPrune() *cobra.Command {
    17  
    18  	cmd := &cobra.Command{
    19  		Use:   "prune [flags]",
    20  		Args:  cobra.NoArgs,
    21  		Short: "Output extraneous Kubernetes resources in the linkerd control plane",
    22  		Long:  `Output extraneous Kubernetes resources in the linkerd control plane.`,
    23  		Example: `  # Prune extraneous resources.
    24    linkerd prune | kubectl delete -f -
    25    `,
    26  		RunE: func(cmd *cobra.Command, _ []string) error {
    27  
    28  			k8sAPI, err := k8s.NewAPI(kubeconfigPath, kubeContext, impersonate, impersonateGroup, 30*time.Second)
    29  			if err != nil {
    30  				return err
    31  			}
    32  
    33  			values, err := loadStoredValues(cmd.Context(), k8sAPI)
    34  			if err != nil {
    35  				fmt.Fprintf(os.Stderr, "failed to load stored values: %s\n", err)
    36  				os.Exit(1)
    37  			}
    38  
    39  			if values == nil {
    40  				return errors.New(
    41  					`Could not find the linkerd-config-overrides secret.
    42  Please note this command is only intended for instances of Linkerd that were installed via the CLI`)
    43  			}
    44  
    45  			err = validateValues(cmd.Context(), k8sAPI, values)
    46  			if err != nil {
    47  				return err
    48  			}
    49  
    50  			manifests := strings.Builder{}
    51  
    52  			if err = renderControlPlane(&manifests, values, make(map[string]interface{})); err != nil {
    53  				return err
    54  			}
    55  			if err = renderCRDs(&manifests, valuespkg.Options{}); err != nil {
    56  				return err
    57  			}
    58  
    59  			return pkgCmd.Prune(cmd.Context(), k8sAPI, manifests.String(), k8s.ControllerNSLabel)
    60  		},
    61  	}
    62  
    63  	return cmd
    64  }
    65  

View as plain text