-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck-cronjob-status.go
57 lines (49 loc) · 1.46 KB
/
check-cronjob-status.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 main
import (
"fmt"
"io"
cronjob "github.com/benkeil/check-k8s/pkg/checks/cronjob"
"github.com/benkeil/check-k8s/pkg/environment"
"github.com/benkeil/check-k8s/pkg/kube"
"github.com/benkeil/icinga-checks-library"
"k8s.io/client-go/kubernetes"
"github.com/spf13/cobra"
)
type (
checkCronjobStatusCmd struct {
out io.Writer
Client kubernetes.Interface
Name string
Namespace string
}
)
func newCheckCronjobStatusCmd(settings environment.EnvSettings, out io.Writer) *cobra.Command {
c := &checkCronjobStatusCmd{out: out}
cmd := &cobra.Command{
Use: "status",
Short: "check if a k8s cronjob is running properly",
SilenceUsage: true,
Args: NameArgs(),
PreRun: func(cmd *cobra.Command, args []string) {
c.Name = args[0]
client, err := kube.GetKubeClient(settings.KubeContext)
if err != nil {
icinga.NewResult("GetKubeClient", icinga.ServiceStatusUnknown, fmt.Sprintf("can't get client: %v", err)).Exit()
}
c.Client = client
},
Run: func(cmd *cobra.Command, args []string) {
c.run()
},
}
cmd.PersistentFlags().StringVarP(&c.Namespace, "namespace", "n", "", "the namespace of the cronjob")
cmd.MarkPersistentFlagRequired("namespace")
return cmd
}
func (c *checkCronjobStatusCmd) run() {
checkCronjob := cronjob.NewCheckCronjob(c.Client, c.Name, c.Namespace)
result := checkCronjob.CheckStatus(
cronjob.CheckStatusOptions{
})
result.Exit()
}