generated from kyma-project/template-repository
/
cmdKymaCreate.go
47 lines (37 loc) · 1.04 KB
/
cmdKymaCreate.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
package main
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/kyma-project/cloud-manager/cmd/cli/helper"
"github.com/kyma-project/cloud-manager/pkg/util"
"github.com/spf13/cobra"
)
func init() {
cmdKymaCreate.Flags().StringVarP(&shootName, "shoot", "s", "", "Shoot name")
cmdKyma.AddCommand(cmdKymaCreate)
}
var cmdKymaCreate = &cobra.Command{
Use: "create",
Aliases: []string{"c"},
RunE: func(cmd *cobra.Command, args []string) error {
c := helper.NewKcpClient()
kyma := util.NewKymaUnstructured()
if kymaName == "" {
fmt.Println("Kyma name not specified it will be generated.")
kymaName = uuid.NewString()
}
kyma.SetName(kymaName)
kyma.SetNamespace("kcp-system")
if shootName != "" {
fmt.Println("Adding kyma-project.io/shoot-name label")
kyma.SetLabels(map[string]string{"kyma-project.io/shoot-name": shootName})
}
err := c.Create(context.Background(), kyma)
if err != nil {
return fmt.Errorf("error creating Kyma: %w", err)
}
fmt.Printf("Created Kyma %v\n", kymaName)
return nil
},
}