forked from pachyderm/pachyderm
/
cmds.go
379 lines (363 loc) · 16.1 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
package cmds
import (
"bufio"
"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"
)
var defaultDashImage = "pachyderm/dash:0.4.0"
func maybeKcCreate(dryRun bool, manifest *bytes.Buffer, opts *assets.AssetOpts) error {
if dryRun {
_, err := os.Stdout.Write(manifest.Bytes())
return err
}
ret := cmdutil.RunIO(
cmdutil.IO{
Stdin: manifest,
Stdout: os.Stdout,
Stderr: os.Stderr,
}, "kubectl", "create", "-f", "-")
if !dryRun {
fmt.Println("\nPachyderm is launching. Check it's status with \"kubectl get all\"")
if opts.DashOnly || opts.EnableDash {
fmt.Println("Once launched, access the dashboard by running \"pachctl port-forward\"")
}
fmt.Println("")
}
return ret
}
// DeployCmd returns a cobra.Command to deploy pachyderm.
func DeployCmd(noMetrics *bool) *cobra.Command {
metrics := !*noMetrics
var pachdShards int
var hostPath string
var dev bool
var dryRun bool
var secure bool
var etcdNodes int
var etcdVolume string
var pachdCPURequest string
var pachdNonCacheMemRequest string
var blockCacheSize string
var etcdCPURequest string
var etcdMemRequest string
var logLevel string
var persistentDiskBackend string
var objectStoreBackend string
var opts *assets.AssetOpts
var enableDash bool
var dashOnly bool
var dashImage string
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.RunFixedArgs(0, func(args []string) (retErr error) {
if metrics && !dev {
start := time.Now()
startMetricsWait := _metrics.StartReportAndFlushUserAction("Deploy", start)
defer startMetricsWait()
defer func() {
finishMetricsWait := _metrics.FinishReportAndFlushUserAction("Deploy", retErr, start)
finishMetricsWait()
}()
}
manifest := &bytes.Buffer{}
if dev {
// Use dev build instead of release build
opts.Version = deploy.DevVersionTag
// we turn metrics off this is a dev cluster. The default is set by
// deploy.PersistentPreRun, below.
opts.Metrics = false
// Disable authentication, for tests
opts.DisableAuthentication = true
}
if err := assets.WriteLocalAssets(manifest, opts, hostPath); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest, opts)
}),
}
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, "Deploy pachd built locally, disable metrics, and use insecure authentication")
deployGoogle := &cobra.Command{
Use: "google <GCS bucket> <size of disk(s) (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 etcd node (see --etcd-nodes).\n" +
" <size of disks>: Size of GCE persistent disks in GB (assumed to all be the same).\n",
Run: cmdutil.RunFixedArgs(2, func(args []string) (retErr error) {
if metrics && !dev {
start := time.Now()
startMetricsWait := _metrics.StartReportAndFlushUserAction("Deploy", start)
defer startMetricsWait()
defer func() {
finishMetricsWait := _metrics.FinishReportAndFlushUserAction("Deploy", retErr, start)
finishMetricsWait()
}()
}
volumeSize, err := strconv.Atoi(args[1])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[1])
}
manifest := &bytes.Buffer{}
opts.BlockCacheSize = "0G" // GCS is fast so we want to disable the block cache. See issue #1650
if err = assets.WriteGoogleAssets(manifest, opts, args[0], volumeSize); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest, opts)
}),
}
deployCustom := &cobra.Command{
Use: "custom --persistent-disk <persistent disk backend> --object-store <object store backend> <persistent disk args> <object store args>",
Short: "(in progress) Deploy a custom Pachyderm cluster configuration",
Long: "(in progress) Deploy a custom Pachyderm cluster configuration.\n" +
"If <object store backend> is \"s3\", then the arguments are:\n" +
" <volumes> <size of volumes (in GB)> <bucket> <id> <secret> <endpoint>\n",
Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 4, Max: 7}, func(args []string) (retErr error) {
if metrics && !dev {
start := time.Now()
startMetricsWait := _metrics.StartReportAndFlushUserAction("Deploy", start)
defer startMetricsWait()
defer func() {
finishMetricsWait := _metrics.FinishReportAndFlushUserAction("Deploy", retErr, start)
finishMetricsWait()
}()
}
manifest := &bytes.Buffer{}
err := assets.WriteCustomAssets(manifest, opts, args, objectStoreBackend, persistentDiskBackend, secure)
if err != nil {
return err
}
return maybeKcCreate(dryRun, manifest, opts)
}),
}
deployCustom.Flags().BoolVarP(&secure, "secure", "s", false, "Enable secure access to a Minio server.")
deployCustom.Flags().StringVar(&persistentDiskBackend, "persistent-disk", "aws",
"(required) Backend providing persistent local volumes to stateful pods. "+
"One of: aws, google, or azure.")
deployCustom.Flags().StringVar(&objectStoreBackend, "object-store", "s3",
"(required) Backend providing an object-storage API to pachyderm. One of: "+
"s3, gcs, or azure-blob.")
var cloudfrontDistribution string
deployAmazon := &cobra.Command{
Use: "amazon <S3 bucket> <id> <secret> <token> <region> <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" +
" <size of volumes>: Size of EBS volumes, in GB (assumed to all be the same).\n",
Run: cmdutil.RunFixedArgs(6, func(args []string) (retErr error) {
if metrics && !dev {
start := time.Now()
startMetricsWait := _metrics.StartReportAndFlushUserAction("Deploy", start)
defer startMetricsWait()
defer func() {
finishMetricsWait := _metrics.FinishReportAndFlushUserAction("Deploy", retErr, start)
finishMetricsWait()
}()
}
volumeSize, err := strconv.Atoi(args[5])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[5])
}
if strings.TrimSpace(cloudfrontDistribution) != "" {
fmt.Printf("WARNING: You specified a cloudfront distribution. Deploying on AWS with cloudfront is currently " +
"an alpha feature. No security restrictions have been applied to cloudfront, making all data public (obscured but not secured)\n")
}
manifest := &bytes.Buffer{}
if err = assets.WriteAmazonAssets(manifest, opts, args[0], args[1], args[2], args[3], args[4], volumeSize, cloudfrontDistribution); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest, opts)
}),
}
deployAmazon.Flags().StringVar(&cloudfrontDistribution, "cloudfront-distribution", "",
"Deploying on AWS with cloudfront is currently "+
"an alpha feature. No security restrictions have been"+
"applied to cloudfront, making all data public (obscured but not secured)")
deployMicrosoft := &cobra.Command{
Use: "microsoft <container> <storage account name> <storage account key> <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" +
" <size of volumes>: Size of persistent volumes, in GB (assumed to all be the same).\n",
Run: cmdutil.RunFixedArgs(4, func(args []string) (retErr error) {
if metrics && !dev {
start := time.Now()
startMetricsWait := _metrics.StartReportAndFlushUserAction("Deploy", start)
defer startMetricsWait()
defer func() {
finishMetricsWait := _metrics.FinishReportAndFlushUserAction("Deploy", retErr, start)
finishMetricsWait()
}()
}
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])
}
if opts.EtcdVolume != "" {
tempURI, err := url.ParseRequestURI(opts.EtcdVolume)
if err != nil {
return fmt.Errorf("Volume URI needs to be a well-formed URI; instead got '%v'", opts.EtcdVolume)
}
opts.EtcdVolume = tempURI.String()
}
volumeSize, err := strconv.Atoi(args[3])
if err != nil {
return fmt.Errorf("volume size needs to be an integer; instead got %v", args[3])
}
manifest := &bytes.Buffer{}
if err = assets.WriteMicrosoftAssets(manifest, opts, args[0], args[1], args[2], volumeSize); err != nil {
return err
}
return maybeKcCreate(dryRun, manifest, opts)
}),
}
deploy := &cobra.Command{
Use: "deploy amazon|google|microsoft|local|custom",
Short: "Deploy a Pachyderm cluster.",
Long: "Deploy a Pachyderm cluster.",
PersistentPreRun: cmdutil.Run(func([]string) error {
opts = &assets.AssetOpts{
PachdShards: uint64(pachdShards),
Version: version.PrettyPrintVersion(version.Version),
LogLevel: logLevel,
Metrics: metrics,
PachdCPURequest: pachdCPURequest,
PachdNonCacheMemRequest: pachdNonCacheMemRequest,
BlockCacheSize: blockCacheSize,
EtcdCPURequest: etcdCPURequest,
EtcdMemRequest: etcdMemRequest,
EtcdNodes: etcdNodes,
EtcdVolume: etcdVolume,
EnableDash: enableDash,
DashOnly: dashOnly,
DashImage: dashImage,
}
return nil
}),
}
deploy.PersistentFlags().IntVar(&pachdShards, "shards", 16, "(rarely set) The maximum number of pachd nodes allowed in the cluster; increasing this number blindly can result in degraded performance.")
deploy.PersistentFlags().IntVar(&etcdNodes, "dynamic-etcd-nodes", 0, "Deploy etcd as a StatefulSet with the given number of pods. The persistent volumes used by these pods are provisioned dynamically. Note that StatefulSet is currently a beta kubernetes feature, which might be unavailable in older versions of kubernetes.")
deploy.PersistentFlags().StringVar(&etcdVolume, "static-etcd-volume", "", "Deploy etcd as a ReplicationController with one pod. The pod uses the given persistent volume.")
deploy.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Don't actually deploy pachyderm to Kubernetes, instead just print the manifest.")
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(&enableDash, "dashboard", false, "Deploy the Pachyderm UI along with Pachyderm (experimental). After deployment, run \"pachctl port-forward\" to connect")
deploy.PersistentFlags().BoolVar(&dashOnly, "dashboard-only", false, "Only deploy the Pachyderm UI (experimental), without the rest of pachyderm. This is for launching the UI adjacent to an existing Pachyderm cluster. After deployment, run \"pachctl port-forward\" to connect")
deploy.PersistentFlags().StringVar(&dashImage, "dash-image", defaultDashImage, "Image URL for pachyderm dashboard")
deploy.AddCommand(deployLocal)
deploy.AddCommand(deployAmazon)
deploy.AddCommand(deployGoogle)
deploy.AddCommand(deployMicrosoft)
deploy.AddCommand(deployCustom)
// Flags for setting pachd resource requests. These should rarely be set --
// only if we get the defaults wrong, or users have an unusual access pattern
//
// All of these are empty by default, because the actual default values depend
// on the backend to which we're. The defaults are set in
// s/s/pkg/deploy/assets/assets.go
deploy.PersistentFlags().StringVar(&pachdCPURequest,
"pachd-cpu-request", "", "(rarely set) The size of Pachd's CPU "+
"request, which we give to Kubernetes. Size is in cores (with partial "+
"cores allowed and encouraged).")
deploy.PersistentFlags().StringVar(&blockCacheSize, "block-cache-size", "",
"Size of pachd's in-memory cache for PFS files. Size is specified in "+
"bytes, with allowed SI suffixes (M, K, G, Mi, Ki, Gi, etc).")
deploy.PersistentFlags().StringVar(&pachdNonCacheMemRequest,
"pachd-memory-request", "", "(rarely set) The size of PachD's memory "+
"request in addition to its block cache (set via --block-cache-size). "+
"Size is in bytes, with SI suffixes (M, K, G, Mi, Ki, Gi, etc).")
deploy.PersistentFlags().StringVar(&etcdCPURequest,
"etcd-cpu-request", "", "(rarely set) The size of etcd's CPU request, "+
"which we give to Kubernetes. Size is in cores (with partial cores "+
"allowed and encouraged).")
deploy.PersistentFlags().StringVar(&etcdMemRequest,
"etcd-memory-request", "", "(rarely set) The size of etcd's memory "+
"request. Size is in bytes, with SI suffixes (M, K, G, Mi, Ki, Gi, "+
"etc).")
return deploy
}
// Cmds returns a list of cobra commands for deploying Pachyderm clusters.
func Cmds(noMetrics *bool) []*cobra.Command {
deploy := DeployCmd(noMetrics)
var all bool
undeploy := &cobra.Command{
Use: "undeploy",
Short: "Tear down a deployed Pachyderm cluster.",
Long: "Tear down a deployed Pachyderm cluster.",
Run: cmdutil.RunFixedArgs(0, func(args []string) error {
if all {
fmt.Printf(`
By using the --all flag, you are going to delete everything, including the
persistent volumes where metadata is stored. If your persistent volumes
were dynamically provisioned (i.e. if you used the "--dynamic-etcd-nodes"
flag), the underlying volumes will be removed, making metadata such repos,
commits, pipelines, and jobs unrecoverable. If your persistent volume was
manually provisioned (i.e. if you used the "--static-etcd-volume" flag), the
underlying volume will not be removed.
Are you sure you want to proceed? yN
`)
r := bufio.NewReader(os.Stdin)
bytes, err := r.ReadBytes('\n')
if err != nil {
return err
}
if !(bytes[0] == 'y' || bytes[0] == 'Y') {
return nil
}
}
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", "sa", "-l", "suite=pachyderm"); err != nil {
return err
}
if err := cmdutil.RunIO(io, "kubectl", "delete", "secret", "-l", "suite=pachyderm"); err != nil {
return err
}
if all {
if err := cmdutil.RunIO(io, "kubectl", "delete", "storageclass", "-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", "pv", "-l", "suite=pachyderm"); err != nil {
return err
}
}
return nil
}),
}
undeploy.Flags().BoolVarP(&all, "all", "a", false, `
Delete everything, including the persistent volumes where metadata
is stored. If your persistent volumes were dynamically provisioned (i.e. if
you used the "--dynamic-etcd-nodes" flag), the underlying volumes will be
removed, making metadata such repos, commits, pipelines, and jobs
unrecoverable. If your persistent volume was manually provisioned (i.e. if
you used the "--static-etcd-volume" flag), the underlying volume will not be
removed.`)
return []*cobra.Command{deploy, undeploy}
}