-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathinit.go
51 lines (45 loc) · 1.33 KB
/
init.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
package cmd
import (
"context"
"github.com/aquasecurity/starboard/pkg/kube"
"github.com/spf13/cobra"
extensionsapi "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
)
func NewInitCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Create custom resource definitions used by starboard",
Long: `
Create all the resources used by starboard. It will create the following
in the cluster:
- custom resource definitions
- starboard namespace
- starboard service account
- starboard cluster role and cluster role binding
- config map
The config map contains the default configuration parameters. However this
can be modified to change the behaviour of the scanner.
These resources can be removed from the cluster using the "cleanup" command.
`,
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
}
clientsetext, err := extensionsapi.NewForConfig(config)
if err != nil {
return
}
err = kube.NewCRManager(clientset, clientsetext).Init(ctx)
return
},
}
return cmd
}