-
Notifications
You must be signed in to change notification settings - Fork 568
/
cmds.go
271 lines (260 loc) · 11.7 KB
/
cmds.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package cmds
import (
"bytes"
"encoding/base64"
"fmt"
"net/url"
"os"
"strconv"
"strings"
"time"
"github.com/pachyderm/pachyderm/src/client/version"
"github.com/pachyderm/pachyderm/src/server/pkg/cmdutil"
"github.com/pachyderm/pachyderm/src/server/pkg/deploy"
"github.com/pachyderm/pachyderm/src/server/pkg/deploy/assets"
_metrics "github.com/pachyderm/pachyderm/src/server/pkg/metrics"
"github.com/spf13/cobra"
"go.pedge.io/pkg/cobra"
)
func maybeKcCreate(dryRun bool, manifest *bytes.Buffer) error {
if dryRun {
_, err := os.Stdout.Write(manifest.Bytes())
return err
}
return cmdutil.RunIO(
cmdutil.IO{
Stdin: manifest,
Stdout: os.Stdout,
Stderr: os.Stderr,
}, "kubectl", "create", "-f", "-")
}
// DeployCmd returns a cobra.Command to deploy pachyderm.
func DeployCmd(noMetrics *bool) *cobra.Command {
metrics := !*noMetrics
var pachdShards int
var rethinkShards int
var hostPath string
var dev bool
var dryRun bool
var secure bool
var deployRethinkAsRc bool
var deployRethinkAsStatefulSet bool
var rethinkdbCacheSize string
var logLevel string
var opts *assets.AssetOpts
deployLocal := &cobra.Command{
Use: "local",
Short: "Deploy a single-node Pachyderm cluster with local metadata storage.",
Long: "Deploy a single-node Pachyderm cluster with local metadata storage.",
Run: cmdutil.RunBoundedArgs(0, 0, func(args []string) (retErr error) {
if metrics && !dev {
metricsFn := _metrics.ReportAndFlushUserAction("Deploy")
defer func(start time.Time) { metricsFn(start, retErr) }(time.Now())
}
manifest := &bytes.Buffer{}
if dev {
opts.Version = deploy.DevVersionTag
}
if err := assets.WriteLocalAssets(manifest, opts, hostPath); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest)
}),
}
deployLocal.Flags().StringVar(&hostPath, "host-path", "/var/pachyderm", "Location on the host machine where PFS metadata will be stored.")
deployLocal.Flags().BoolVarP(&dev, "dev", "d", false, "Don't use a specific version of pachyderm/pachd.")
deployGoogle := &cobra.Command{
Use: "google <GCS bucket> <GCE persistent disks> <size of disks (in GB)>",
Short: "Deploy a Pachyderm cluster running on GCP.",
Long: "Deploy a Pachyderm cluster running on GCP.\n" +
"Arguments are:\n" +
" <GCS bucket>: A GCS bucket where Pachyderm will store PFS data.\n" +
" <GCE persistent disks>: A comma-separated list of GCE persistent disks, one per rethink shard (see --rethink-shards).\n" +
" <size of disks>: Size of GCE persistent disks in GB (assumed to all be the same).\n",
Run: cmdutil.RunBoundedArgs(3, 3, func(args []string) (retErr error) {
if metrics && !dev {
metricsFn := _metrics.ReportAndFlushUserAction("Deploy")
defer func(start time.Time) { metricsFn(start, retErr) }(time.Now())
}
volumeNames := strings.Split(args[1], ",")
volumeSize, err := strconv.Atoi(args[2])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[2])
}
manifest := &bytes.Buffer{}
if err = assets.WriteGoogleAssets(manifest, opts, args[0], volumeNames, volumeSize); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest)
}),
}
deployMinio := &cobra.Command{
Use: "minio [-s] <S3 bucket> <id> <secret> <endpoint>",
Short: "Deploy a Pachyderm cluster running locally.",
Long: "Deploy a Pachyderm cluster running locally. Arguments are:\n" +
" <Minio bucket>: A Minio bucket where Pachyderm will store PFS data.\n" +
" <id>, <secret>, <endpoint>: Access credentials.\n" +
" <secure>: Secure connection.\n",
Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 4, Max: 4}, func(args []string) (retErr error) {
if metrics && !dev {
metricsFn := _metrics.ReportAndFlushUserAction("Deploy")
defer func(start time.Time) { metricsFn(start, retErr) }(time.Now())
}
manifest := &bytes.Buffer{}
err := assets.WriteMinioAssets(manifest, opts, hostPath, args[0], args[1], args[2], args[3], secure)
if err != nil {
return err
}
return maybeKcCreate(dryRun, manifest)
}),
}
deployMinio.Flags().BoolVarP(&secure, "secure", "s", false, "Enable secure access to Minio server.")
deployAmazon := &cobra.Command{
Use: "amazon <S3 bucket> <id> <secret> <token> <region> <EBS volume names> <size of volumes (in GB)>",
Short: "Deploy a Pachyderm cluster running on AWS.",
Long: "Deploy a Pachyderm cluster running on AWS. Arguments are:\n" +
" <S3 bucket>: An S3 bucket where Pachyderm will store PFS data.\n" +
" <id>, <secret>, <token>: Session token details, used for authorization. You can get these by running 'aws sts get-session-token'\n" +
" <region>: The aws region where pachyderm is being deployed (e.g. us-west-1)\n" +
" <EBS volume names>: A comma-separated list of EBS volumes, one per rethink shard (see --rethink-shards).\n" +
" <size of volumes>: Size of EBS volumes, in GB (assumed to all be the same).\n",
Run: cmdutil.RunBoundedArgs(7, 7, func(args []string) (retErr error) {
if metrics && !dev {
metricsFn := _metrics.ReportAndFlushUserAction("Deploy")
defer func(start time.Time) { metricsFn(start, retErr) }(time.Now())
}
volumeNames := strings.Split(args[5], ",")
volumeSize, err := strconv.Atoi(args[6])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[6])
}
manifest := &bytes.Buffer{}
if err = assets.WriteAmazonAssets(manifest, opts, args[0], args[1], args[2], args[3], args[4], volumeNames, volumeSize); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest)
}),
}
deployMicrosoft := &cobra.Command{
Use: "microsoft <container> <storage account name> <storage account key> <volume URIs> <size of volumes (in GB)>",
Short: "Deploy a Pachyderm cluster running on Microsoft Azure.",
Long: "Deploy a Pachyderm cluster running on Microsoft Azure. Arguments are:\n" +
" <container>: An Azure container where Pachyderm will store PFS data.\n" +
" <volume URIs>: A comma-separated list of persistent volumes, one per rethink shard (see --rethink-shards).\n" +
" <size of volumes>: Size of persistent volumes, in GB (assumed to all be the same).\n",
Run: cmdutil.RunBoundedArgs(5, 5, func(args []string) (retErr error) {
if metrics && !dev {
metricsFn := _metrics.ReportAndFlushUserAction("Deploy")
defer func(start time.Time) { metricsFn(start, retErr) }(time.Now())
}
if _, err := base64.StdEncoding.DecodeString(args[2]); err != nil {
return fmt.Errorf("storage-account-key needs to be base64 encoded; instead got '%v'", args[2])
}
volumeURIs := strings.Split(args[3], ",")
for i, uri := range volumeURIs {
tempURI, err := url.ParseRequestURI(uri)
if err != nil {
return fmt.Errorf("All volume-uris needs to be a well-formed URI; instead got '%v'", uri)
}
volumeURIs[i] = tempURI.String()
}
volumeSize, err := strconv.Atoi(args[4])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[4])
}
manifest := &bytes.Buffer{}
if err = assets.WriteMicrosoftAssets(manifest, opts, args[0], args[1], args[2], volumeURIs, volumeSize); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest)
}),
}
deploy := &cobra.Command{
Use: "deploy amazon|google|microsoft|basic",
Short: "Deploy a Pachyderm cluster.",
Long: "Deploy a Pachyderm cluster.",
PersistentPreRun: cmdutil.Run(func([]string) error {
if deployRethinkAsRc && deployRethinkAsStatefulSet {
return fmt.Errorf("Error: pachctl deploy received contradictory flags: " +
"--deploy-rethink-as-rc and --deploy-rethink-as-stateful-set")
}
if deployRethinkAsRc {
fmt.Fprintf(os.Stderr, "Warning: --deploy-rethink-as-rc is no longer "+
"necessary (and is ignored). The default behavior since Pachyderm "+
"1.3.2 is to manage RethinkDB with a Kubernetes Replication Controller. "+
"This flag will be removed by Pachyderm's 1.4 release, so please remove "+
"it from your scripts. Also see --deploy-rethink-as-stateful-set.\n")
}
if !deployRethinkAsStatefulSet && rethinkShards > 1 {
return fmt.Errorf("Error: --deploy-rethink-as-stateful-set was not set, " +
"but --rethink-shards was set to value >1. Since 1.3.2, 'pachctl deploy' " +
"deploys RethinkDB as a single-node instance by default, unless " +
"--deploy-rethink-as-stateful-set is set. Please set that flag if you " +
"wish to deploy RethinkDB as a multi-node cluster.")
}
opts = &assets.AssetOpts{
PachdShards: uint64(pachdShards),
RethinkShards: uint64(rethinkShards),
RethinkdbCacheSize: rethinkdbCacheSize,
DeployRethinkAsStatefulSet: deployRethinkAsStatefulSet,
Version: version.PrettyPrintVersion(version.Version),
LogLevel: logLevel,
Metrics: metrics,
}
return nil
}),
}
deploy.PersistentFlags().IntVar(&pachdShards, "shards", 1, "Number of Pachd nodes (stateless Pachyderm API servers).")
deploy.PersistentFlags().IntVar(&rethinkShards, "rethink-shards", 1, "Number of RethinkDB shards (for pfs metadata storage) if "+
"--deploy-rethink-as-stateful-set is used.")
deploy.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Don't actually deploy pachyderm to Kubernetes, instead just print the manifest.")
deploy.PersistentFlags().StringVar(&rethinkdbCacheSize, "rethinkdb-cache-size", "768M", "Size of in-memory cache to use for Pachyderm's RethinkDB instance, "+
"e.g. \"2G\". Size is specified in bytes, with allowed SI suffixes (M, K, G, Mi, Ki, Gi, etc).")
deploy.PersistentFlags().StringVar(&logLevel, "log-level", "info", "The level of log messages to print options are, from least to most verbose: \"error\", \"info\", \"debug\".")
deploy.PersistentFlags().BoolVar(&deployRethinkAsRc, "deploy-rethink-as-rc", false, "Defunct flag (does nothing). The default behavior since "+
"Pachyderm 1.3.2 is to manage RethinkDB with a Kubernetes Replication Controller.")
deploy.PersistentFlags().BoolVar(&deployRethinkAsStatefulSet, "deploy-rethink-as-stateful-set", false, "Deploy RethinkDB as a multi-node cluster "+
"controlled by kubernetes StatefulSet, instead of a single-node instance controlled by a Kubernetes Replication Controller. Note that both "+
"your local kubectl binary and the kubernetes server must be at least version 1.5.")
deploy.AddCommand(deployLocal)
deploy.AddCommand(deployAmazon)
deploy.AddCommand(deployGoogle)
deploy.AddCommand(deployMicrosoft)
deploy.AddCommand(deployMinio)
return deploy
}
// Cmds returns a cobra commands for deploying Pachyderm clusters.
func Cmds(noMetrics *bool) []*cobra.Command {
deploy := DeployCmd(noMetrics)
undeploy := &cobra.Command{
Use: "undeploy",
Short: "Tear down a deployed Pachyderm cluster.",
Long: "Tear down a deployed Pachyderm cluster.",
Run: cmdutil.RunBoundedArgs(0, 0, func(args []string) error {
io := cmdutil.IO{
Stdout: os.Stdout,
Stderr: os.Stderr,
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "job", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "all", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "pv", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "pvc", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "sa", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "secret", "-l", "suite=pachyderm"); err != nil {
return err
}
return nil
}),
}
return []*cobra.Command{deploy, undeploy}
}