-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcapten.go
202 lines (167 loc) · 8.99 KB
/
capten.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "capten",
Short: "",
Long: `command line tool for building cluster`,
}
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
var clusterCmd = &cobra.Command{
Use: "cluster",
Short: "cluster operations",
Long: ``,
}
var clusterShowCmd = &cobra.Command{
Use: "show",
Short: "cluster show details",
Long: ``,
}
var clusterAppsCmd = &cobra.Command{
Use: "apps",
Short: "cluster apps operations",
Long: ``,
}
var pluginCmd = &cobra.Command{
Use: "plugin",
Short: "plugin operations",
Long: ``,
}
var pluginStoreCmd = &cobra.Command{
Use: "store",
Short: "plugin store operations",
Long: ``,
}
var clusterResourcesCmd = &cobra.Command{
Use: "resources",
Short: "cluster resources operations",
Long: ``,
}
func readAndValidClusterFlags(cmd *cobra.Command) (cloudService string, clusterType string, err error) {
cloudService, err = cmd.Flags().GetString("cloud")
if len(cloudService) == 0 {
return "", "", fmt.Errorf("specify the cloud service either azure or aws in the command line %v", err)
}
clusterType, _ = cmd.Flags().GetString("type")
if len(clusterType) == 0 {
clusterType = "talos"
}
err = validateClusterFlags(cloudService, clusterType)
return
}
func validateClusterFlags(cloudService, clusterType string) (err error) {
if cloudService != "aws" && cloudService != "azure" {
err = fmt.Errorf("cloud service '%s' is not supported, supported cloud serivces: aws", cloudService)
return
}
if clusterType != "talos" {
err = fmt.Errorf("cluster type '%s' is not supported, supported types: talos", clusterType)
return
}
return
}
func init() {
rootCmd.AddCommand(clusterCmd)
rootCmd.AddCommand(pluginCmd)
//cluster optons
clusterCmd.AddCommand(clusterShowCmd)
clusterCmd.AddCommand(clusterAppsCmd)
clusterCmd.AddCommand(clusterResourcesCmd)
//cluster create options
clusterCreateSubCmd.PersistentFlags().String("cloud", "", "cloud service (default: azure)")
clusterCreateSubCmd.PersistentFlags().String("type", "", "type of cluster (default: talos)")
clusterCmd.AddCommand(clusterCreateSubCmd)
//cluster destroy options
clusterCmd.AddCommand(clusterDestroySubCmd)
//cluster show options
clusterShowCmd.AddCommand(showClusterInfoSubCmd)
//cluster apps options
clusterAppsCmd.AddCommand(appsInstallSubCmd)
clusterAppsCmd.AddCommand(appsListSubCmd)
appsShowSubCmd.PersistentFlags().String("app-name", "", "name of app")
clusterAppsCmd.AddCommand(appsShowSubCmd)
//cluster resources create options
resourceCreateSubCmd.PersistentFlags().String("resource-type", "", "type of resource ('git-project', 'container-registry', 'cloud-provider')")
resourceCreateSubCmd.PersistentFlags().String("git-project-url", "", "url of git project resource")
resourceCreateSubCmd.PersistentFlags().String("access-token", "", "access token of git project resource")
resourceCreateSubCmd.PersistentFlags().String("user-id", "", "user id of git project resource")
resourceCreateSubCmd.PersistentFlags().String("labels", "", "labels of resource (e.g. 'crossplane,tekton')")
resourceCreateSubCmd.PersistentFlags().String("registry-url", "", "registry url of container registry resource")
resourceCreateSubCmd.PersistentFlags().String("registry-type", "", "registry type of container registry resource")
resourceCreateSubCmd.PersistentFlags().String("cloud-type", "", "cloud type of cloud provider resource (aws, azure)")
resourceCreateSubCmd.PersistentFlags().String("registry-username", "", "registry user name of container registry resource")
resourceCreateSubCmd.PersistentFlags().String("registry-password", "", "registry password of container registry resource")
resourceCreateSubCmd.PersistentFlags().String("access-key", "", "access key of aws cloud provider resource")
resourceCreateSubCmd.PersistentFlags().String("secret-key", "", "secret key of aws cloud provider resource")
resourceCreateSubCmd.PersistentFlags().String("client-id", "", "client id of azure cloud provider resource")
resourceCreateSubCmd.PersistentFlags().String("client-secret", "", "client secret of azure cloud provider resource")
clusterResourcesCmd.AddCommand(resourceCreateSubCmd)
//cluster resources update options
resourceUpdateSubCmd.PersistentFlags().String("resource-type", "", "type of resource ('git-project', 'container-registry', 'cloud-provider')")
resourceUpdateSubCmd.PersistentFlags().String("id", "", "id of resource")
resourceUpdateSubCmd.PersistentFlags().String("git-project-url", "", "url of git project resource")
resourceUpdateSubCmd.PersistentFlags().String("access-token", "", "access token of git project resource")
resourceUpdateSubCmd.PersistentFlags().String("user-id", "", "user id of git project resource")
resourceUpdateSubCmd.PersistentFlags().String("labels", "", "labels of resource (e.g. 'crossplane,tekton')")
resourceUpdateSubCmd.PersistentFlags().String("registry-url", "", "registry url of container registry resource")
resourceUpdateSubCmd.PersistentFlags().String("registry-type", "", "registry type of container registry resource")
resourceUpdateSubCmd.PersistentFlags().String("cloud-type", "", "cloud type of cloud provider resource")
resourceUpdateSubCmd.PersistentFlags().String("registry-username", "", "registry user name of container registry resource")
resourceUpdateSubCmd.PersistentFlags().String("registry-password", "", "registry password of container registry resource")
resourceUpdateSubCmd.PersistentFlags().String("access-key", "", "access key of aws cloud provider resource")
resourceUpdateSubCmd.PersistentFlags().String("secret-key", "", "secret key of aws cloud provider resource")
resourceUpdateSubCmd.PersistentFlags().String("client-id", "", "client id of azure cloud provider resource")
resourceUpdateSubCmd.PersistentFlags().String("client-secret", "", "client secret of azure cloud provider resource")
clusterResourcesCmd.AddCommand(resourceUpdateSubCmd)
//cluster resources delete options
resourceDeleteSubCmd.PersistentFlags().String("resource-type", "", "type of resource ('git-project', 'container-registry', 'cloud-provider')")
resourceDeleteSubCmd.PersistentFlags().String("id", "", "id of resource")
clusterResourcesCmd.AddCommand(resourceDeleteSubCmd)
//cluster resources list options
resourceListSubCmd.PersistentFlags().String("resource-type", "", "type of resource ('git-project', 'container-registry', 'cloud-provider')")
clusterResourcesCmd.AddCommand(resourceListSubCmd)
//plugin deploy options
pluginDeploySubCmd.PersistentFlags().String("store-type", "", "store type (local, central, default)")
pluginDeploySubCmd.PersistentFlags().String("plugin-name", "", "name of the plugin")
pluginDeploySubCmd.PersistentFlags().String("version", "", "version of the plugin")
pluginCmd.AddCommand(pluginDeploySubCmd)
//plugin undeploy options
pluginUnDeploySubCmd.PersistentFlags().String("store-type", "", "store type (local, central, default)")
pluginUnDeploySubCmd.PersistentFlags().String("plugin-name", "", "name of the plugin")
pluginCmd.AddCommand(pluginUnDeploySubCmd)
//plugin list options
pluginCmd.AddCommand(pluginListSubCmd)
//plugin show options
pluginShowSubCmd.PersistentFlags().String("plugin-name", "", "name of the plugin")
pluginCmd.AddCommand(pluginShowSubCmd)
//plugin config options
pluginConfigSubCmd.PersistentFlags().String("plugin-name", "", "name of the plugin")
pluginConfigSubCmd.PersistentFlags().Bool("list-actions", false, "list of actions supported by the plugin")
pluginConfigSubCmd.PersistentFlags().String("action", "", "action of the plugin")
pluginConfigSubCmd.PersistentFlags().String("cloud-provider-id", "", "cloud provider identifier")
pluginConfigSubCmd.PersistentFlags().String("crossplane-provider-id", "", "crossplane provider identifier")
pluginConfigSubCmd.PersistentFlags().String("crossplane-provider-name", "", "crossplane provider name")
pluginConfigSubCmd.PersistentFlags().String("cloud-type", "", "cloud type (aws, azure)")
pluginConfigSubCmd.PersistentFlags().String("managed-cluster-id", "", "managed cluster identifier")
pluginCmd.AddCommand(pluginConfigSubCmd)
//plugin store options
pluginCmd.AddCommand(pluginStoreCmd)
//plugin store list options
pluginStoreListSubCmd.PersistentFlags().String("store-type", "", "store type (local, central, default)")
pluginStoreCmd.AddCommand(pluginStoreListSubCmd)
//plugin store show options
pluginStoreShowSubCmd.PersistentFlags().String("store-type", "", "store type (local, central, default)")
pluginStoreShowSubCmd.PersistentFlags().String("plugin-name", "", "name of the plugin")
pluginStoreCmd.AddCommand(pluginStoreShowSubCmd)
//plugin store synch options
pluginStoreSynchSubCmd.PersistentFlags().String("store-type", "", "store type (local, central, default)")
pluginStoreCmd.AddCommand(pluginStoreSynchSubCmd)
//plugin store config options
pluginStoreConfigSubCmd.PersistentFlags().String("store-type", "", "store type (local)")
pluginStoreConfigSubCmd.PersistentFlags().String("git-project-id", "", "git project identifier")
pluginStoreCmd.AddCommand(pluginStoreConfigSubCmd)
}