MCPcopy
hub / github.com/redspread/spread / Add

Method Add

cli/add.go:14–98  ·  view source on GitHub ↗

Add sets up a Spread repository for versioning.

()

Source from the content-addressed store, hash-verified

12
13// Add sets up a Spread repository for versioning.
14func (s SpreadCli) Add() *cli.Command {
15 return &cli.Command{
16 Name: "add",
17 Usage: "spread add <path>",
18 Description: "Stage objects to the index",
19 Flags: []cli.Flag{
20 cli.StringFlag{
21 Name: "namespace",
22 Value: "default",
23 Usage: "namespace to look for objects",
24 },
25 cli.StringFlag{
26 Name: "context",
27 Value: "",
28 Usage: "kubectl context to use for requests",
29 },
30 cli.BoolFlag{
31 Name: "no-export",
32 Usage: "don't request Kube API server to export objects",
33 },
34 cli.BoolFlag{
35 Name: "clean",
36 Usage: "Removes fields that are known to cause issues with reproducibility",
37 },
38 },
39 Action: func(c *cli.Context) {
40 // Download specified object from Kubernetes cluster
41 // example: spread add rc/mattermost
42 resource := c.Args().First()
43 if len(resource) == 0 {
44 s.fatalf("A resource to be added must be specified")
45 }
46
47 context := c.String("context")
48 cluster, err := deploy.NewKubeClusterFromContext(context)
49 if err != nil {
50 s.fatalf("Failed to connect to Kubernetes cluster: %v", err)
51 }
52
53 // parse resource type and name
54 parts := strings.Split(resource, "/")
55 if len(parts) != 2 {
56 s.fatalf("Unrecognized resource format")
57 }
58
59 kind, name := parts[0], parts[1]
60 namespace := c.String("namespace")
61 export := !c.Bool("no-export")
62
63 kubeObj, err := cluster.Get(kind, namespace, name, export)
64 if err != nil {
65 s.fatalf("Could not get object from cluster: %v", err)
66 }
67
68 if c.Bool("clean") {
69 err = cleanObj(kubeObj)
70 if err != nil {
71 s.fatalf("Could not get object from cluster: %v", err)

Callers 1

objectOnlyDeployFunction · 0.45

Calls 6

fatalfMethod · 0.95
projectOrDieMethod · 0.95
cleanObjFunction · 0.85
AddDocumentToIndexMethod · 0.80
StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected