-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpolaris.go
64 lines (59 loc) · 1.54 KB
/
polaris.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
64
package cmd
import (
"context"
starboard "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/aquasecurity/starboard/pkg/polaris"
"github.com/aquasecurity/starboard/pkg/polaris/crd"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
)
func NewPolarisCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "polaris",
Short: "Run a variety of checks to ensure that Kubernetes pods and controllers are configured using best practices",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
ns, _, err := cf.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}
mapper, err := cf.ToRESTMapper()
if err != nil {
return
}
workload, gvk, err := WorkloadFromArgs(mapper, ns, args)
if err != nil {
return err
}
config, err := cf.ToRESTConfig()
if err != nil {
return
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return
}
opts, err := getScannerOpts(cmd)
if err != nil {
return
}
report, owner, err := polaris.NewScanner(opts, clientset).Scan(ctx, workload, gvk)
if err != nil {
return
}
starboardClientset, err := starboard.NewForConfig(config)
if err != nil {
return
}
err = crd.NewReadWriter(GetScheme(), starboardClientset).Write(ctx, report, owner)
if err != nil {
return
}
return
},
}
registerScannerOpts(cmd)
return cmd
}