@@ -16,49 +16,63 @@ package config
16
16
17
17
import (
18
18
"fmt"
19
- "github.com/spf13/cobra"
20
19
"log"
21
20
"path/filepath"
21
+
22
+ "github.com/spf13/cobra"
22
23
)
23
24
24
25
// configCmd represents the config command
25
26
var configCmd = & cobra.Command {
26
27
Use : "config" ,
27
28
Short : "Generate installation config for the API" ,
28
- Long : `Generate installation config for the API. Includes:
29
- - Namespace
30
- - RBAC ClusterRole
31
- - RBAC ClusterRoleBinding
32
- - CRDs
33
- - Controller Deployment
29
+ Long : `Generate installation config for the API.
30
+
31
+ May create config for just CRDs or for controller-manager and CRDs.
32
+ ` ,
33
+ Example : `# Generate config to install controller-manager and CRDs into a cluster
34
+ kubebuilder create config --controller-image myimage:v1 --name myextensionname
35
+
36
+ # Generate config to install only CRDs
37
+ kubebuilder create config --crds
38
+
39
+ # Generate config to install controller-manager and CRDs using a Deployment
40
+ kubebuilder create config --controller-image myimage:v1 --name myextensionname --controller-type deployment
41
+
42
+ # Generate config file at a specific location
43
+ kubebuilder create config --crds --output myextensionname.yaml
44
+
34
45
` ,
35
46
Run : func (cmd * cobra.Command , args []string ) {
36
47
if controllerType != "statefulset" && controllerType != "deployment" {
37
48
fmt .Printf (
38
- "Invalid value %s for --controller-type, must be statefulset or deployment\n " , controllerType )
49
+ "Invalid value %s for --controller-type, must be statefulset or deployment. \n " , controllerType )
39
50
return
40
51
}
41
- if controllerImage == "" {
42
- fmt .Printf ("Must specify --controller-image\n " )
52
+ if controllerImage == "" && ! crds {
53
+ fmt .Printf ("Must either specify --controller-image or set --crds. \n " )
43
54
return
44
55
}
45
- if name == "" {
46
- fmt .Printf ("Must specify --name\n " )
56
+ if name == "" && ! crds {
57
+ fmt .Printf ("Must either specify the name of the extension with --name or set --crds. \n " )
47
58
return
48
59
}
49
60
CodeGenerator {}.Execute ()
50
- log .Printf ("Config written to hack/install.yaml" )
61
+ log .Printf ("Config written to %s" , output )
51
62
},
52
63
}
53
64
54
65
var (
55
- controllerType , controllerImage , name , output string
66
+ controllerType , controllerImage , name , output , crdNamespace string
67
+ crds bool
56
68
)
57
69
58
70
func AddCreateConfig (cmd * cobra.Command ) {
59
71
cmd .AddCommand (configCmd )
60
72
configCmd .Flags ().StringVar (& controllerType , "controller-type" , "statefulset" , "either statefulset or deployment." )
73
+ configCmd .Flags ().BoolVar (& crds , "crds" , false , "if set to true, only generate crd definitions" )
74
+ configCmd .Flags ().StringVar (& crdNamespace , "crd-namespace" , "" , "if set, install CRDs to this namespace." )
61
75
configCmd .Flags ().StringVar (& controllerImage , "controller-image" , "" , "name of the controller container to run." )
62
- configCmd .Flags ().StringVar (& name , "name" , "" , "name of the installation." )
76
+ configCmd .Flags ().StringVar (& name , "name" , "" , "name of the installation. used to generate the namespace and resource names. " )
63
77
configCmd .Flags ().StringVar (& output , "output" , filepath .Join ("hack" , "install.yaml" ), "location to write yaml to" )
64
78
}
0 commit comments