-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpolaris.go
44 lines (41 loc) · 1.1 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
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",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return
}
reports, err := polaris.NewScanner(clientset).Scan(ctx)
if err != nil {
return
}
starboardClientset, err := starboard.NewForConfig(config)
if err != nil {
return
}
err = crd.NewWriter(starboardClientset).WriteAll(ctx, reports)
if err != nil {
return
}
return
},
}
return cmd
}