-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathprune.go
61 lines (51 loc) · 1.78 KB
/
prune.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"fmt"
"strings"
"time"
pkgCmd "github.com/linkerd/linkerd2/pkg/cmd"
"github.com/linkerd/linkerd2/pkg/flags"
"github.com/linkerd/linkerd2/pkg/healthcheck"
"github.com/linkerd/linkerd2/pkg/k8s"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/cli/values"
)
func newCmdPrune() *cobra.Command {
var cniEnabled bool
var wait time.Duration
var options values.Options
var output string
cmd := &cobra.Command{
Use: "prune [flags]",
Args: cobra.NoArgs,
Short: "Output extraneous Kubernetes resources in the linkerd-jaeger extension",
Long: `Output extraneous Kubernetes resources in the linkerd-jaeger extension.`,
Example: ` # Prune extraneous resources.
linkerd jaeger prune | kubectl delete -f -
`,
RunE: func(cmd *cobra.Command, _ []string) error {
hc := healthcheck.NewWithCoreChecks(&healthcheck.Options{
ControlPlaneNamespace: controlPlaneNamespace,
KubeConfig: kubeconfigPath,
KubeContext: kubeContext,
Impersonate: impersonate,
ImpersonateGroup: impersonateGroup,
APIAddr: apiAddr,
RetryDeadline: time.Now().Add(wait),
})
hc.RunWithExitOnError()
cniEnabled = hc.CNIEnabled
manifests := strings.Builder{}
err := install(&manifests, options, "", cniEnabled, "yaml")
if err != nil {
return err
}
label := fmt.Sprintf("%s=%s", k8s.LinkerdExtensionLabel, JaegerExtensionName)
return pkgCmd.Prune(cmd.Context(), hc.KubeAPIClient(), manifests.String(), label, output)
},
}
cmd.Flags().DurationVar(&wait, "wait", 300*time.Second, "Wait for extension components to be available")
cmd.PersistentFlags().StringVarP(&output, "output", "o", "yaml", "Output format. One of: json|yaml")
flags.AddValueOptionsFlags(cmd.Flags(), &options)
return cmd
}