-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathjanitor.go
57 lines (41 loc) · 1.54 KB
/
janitor.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
package cmd
import (
"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)
var cmdExample = `# List Pods that are in a pending state (waiting to be scheduled)
kubectl janitor pods unscheduled
# List Pods in an unhealthy state.
kubectl janitor pods unhealthy
# List Pods that are currently in a running phase but not ready for some reason.
kubectl janitor pods unready
# List the current statuses of the Pods and their respective count.
kubectl janitor pods status
# List Jobs that have failed to run and have restartPolicy: Never.
kubectl janitor jobs failed
# List PesistentVolumes that are available for claim.
kubectl janitor pvs unclaimed
# List PersistentVolumeClaims in an pending state (unbound).
kubectl janitor pvcs pending
`
// NewJanitorCommand provides the base command when called without any subcommands.
func NewJanitorCommand() *cobra.Command {
o := NewJanitorOptions()
cmd := &cobra.Command{
Use: "janitor",
Example: cmdExample,
Short: "Find objects in a problematic state in your Kubernetes cluster",
SilenceUsage: true,
}
cmd.PersistentFlags().Bool("no-headers", false, "Don't print headers (default print headers).")
flags := cmd.PersistentFlags()
o.ConfigFlags.AddFlags(flags)
matchVersionFlags := cmdutil.NewMatchVersionFlags(o.ConfigFlags)
matchVersionFlags.AddFlags(flags)
f := cmdutil.NewFactory(matchVersionFlags)
cmd.AddCommand(newJobsCommand(f, o))
cmd.AddCommand(newPodsCommand(f, o))
cmd.AddCommand(newPVCsCommand(f, o))
cmd.AddCommand(newPVsCommand(f, o))
return cmd
}