-
Notifications
You must be signed in to change notification settings - Fork 541
/
root.go
103 lines (87 loc) · 3.09 KB
/
root.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"flag"
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/ami"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/bootstrap"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/controller"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/eks"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/resource"
"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/cmd/version"
"sigs.k8s.io/cluster-api/cmd/clusterctl/cmd"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
)
var (
verbosity *int
)
// RootCmd is the Cobra root command.
func RootCmd() *cobra.Command {
newCmd := &cobra.Command{
Use: "clusterawsadm",
Short: "Kubernetes Cluster API Provider AWS Management Utility",
Long: cmd.LongDesc(`
clusterawsadm provides helpers for bootstrapping Kubernetes Cluster
API Provider AWS. Use clusterawsadm to view required AWS Identity and Access Management
(IAM) policies as JSON docs, or create IAM roles and instance profiles automatically
using AWS CloudFormation.
clusterawsadm additionally helps provide credentials for use with clusterctl.
`),
Example: cmd.Examples(`
# Create AWS Identity and Access Management (IAM) roles for use with
# Kubernetes Cluster API Provider AWS.
clusterawsadm bootstrap iam create-cloudformation-stack
# Encode credentials for use with clusterctl init
export AWS_B64ENCODED_CREDENTIALS=$(clusterawsadm bootstrap credentials encode-as-profile)
clusterctl init --infrastructure aws
`),
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
newCmd.AddCommand(bootstrap.RootCmd())
newCmd.AddCommand(version.Cmd(os.Stdout))
newCmd.AddCommand(ami.RootCmd())
newCmd.AddCommand(eks.RootCmd())
newCmd.AddCommand(controller.RootCmd())
newCmd.AddCommand(resource.RootCmd())
return newCmd
}
// Execute starts the process.
func Execute() {
if err := flag.CommandLine.Parse([]string{}); err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, "")
os.Exit(1)
}
if err := RootCmd().Execute(); err != nil {
os.Exit(1)
}
}
func init() {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
verbosity := flag.CommandLine.Int("v", 2, "Set the log level verbosity.")
_ = flag.Set("v", strconv.Itoa(*verbosity))
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
}
func init() {
cobra.OnInitialize(initConfig)
}
func initConfig() {
logf.SetLogger(logf.NewLogger(logf.WithThreshold(verbosity)))
}