-
Notifications
You must be signed in to change notification settings - Fork 40
/
certgen.go
44 lines (39 loc) · 1.44 KB
/
certgen.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 certgen
import (
"github.com/spf13/cobra"
)
func Setup(parent *cobra.Command) error {
cmd := &cobra.Command{
Use: "certgen",
Short: "tools for generating certificates for webhooks",
}
createCmd := &cobra.Command{
Use: "create [name]",
Short: "Generate ca, server cert and key and store it in a secret",
Args: cobra.ExactArgs(1),
RunE: create,
}
flags := createCmd.PersistentFlags()
flags.StringP(flagNamespace, "n", "default", "Namespace for certificate secret")
flags.StringSlice(flagHosts, nil, "IPs and DNS names to include in the certificate")
cmd.AddCommand(createCmd)
patchCmd := &cobra.Command{
Use: "patch",
Args: cobra.ExactArgs(0),
Short: "Patch validating/mutating webhook configurations and CRDs",
RunE: patch,
}
flags = patchCmd.PersistentFlags()
flags.Bool(flagValidating, true, "wether to patch ValidatingWebhookConfiguration with given name")
flags.Bool(flagMutating, true, "wether to patch MutatingWebhookConfiguration with given name")
flags.Bool(flagCRDs, true, "wether to patch CRDs")
flags.String(flagWebhookCFGName, "", "Name of *WebhookConfiguration resources")
flags.String(flagSecretName, "", "Name of certificate secret containing the ca")
flags.String(flagSecretNamespace, "default", "Namespace of certificate secret containing the ca")
if err := cobra.MarkFlagRequired(flags, flagSecretName); err != nil {
return err
}
cmd.AddCommand(patchCmd)
parent.AddCommand(cmd)
return nil
}