-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck-k8s.go
63 lines (51 loc) · 1.31 KB
/
check-k8s.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
62
63
package main
import (
"errors"
"os"
"github.com/benkeil/check-k8s/pkg/environment"
"github.com/spf13/cobra"
)
var (
globalUsage = `This program tests kubernetes resources`
version string
settings environment.EnvSettings
)
func main() {
cmd := newRootCmd(os.Args[1:])
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func newRootCmd(args []string) *cobra.Command {
cmd := &cobra.Command{
Use: "check-k8s",
Short: "check-k8s checks if a k8s resource is healthy",
Long: globalUsage,
Version: version,
SilenceUsage: false,
}
settings.AddFlags(cmd.PersistentFlags())
cmd.PersistentFlags().Parse(args)
// set defaults from environment
settings.Init(cmd.PersistentFlags())
out := cmd.OutOrStdout()
cmd.AddCommand(
// check commands
newCheckDeploymentCmd(settings, out),
newCheckEndpointsCmd(settings, out),
newCheckSecretsCmd(settings, out),
newCheckConfigMapsCmd(settings, out),
newCheckCronjobCmd(settings, out),
newCheckCronjobStatusCmd(settings, out),
)
return cmd
}
// NameArgs returns an error if there are not exactly 1 arg containing the resource name.
func NameArgs() cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("resource name is required")
}
return nil
}
}