-
Notifications
You must be signed in to change notification settings - Fork 15
/
sabakan_set_template.go
51 lines (43 loc) · 1.13 KB
/
sabakan_set_template.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
package cmd
import (
"context"
"os"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/cke/sabakan"
"github.com/cybozu-go/well"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"
)
// sabakanSetTemplateCmd represents the "sabakan set-template" command
var sabakanSetTemplateCmd = &cobra.Command{
Use: "set-template FILE",
Short: "set the cluster configuration template",
Long: `Set the cluster configuration template.
FILE should contain a YAML/JSON template of the cluster configuration.
The format is the same as the cluster configuration, but must contain
just one control-plane node and one non contorl-plane node.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
b, err := os.ReadFile(args[0])
if err != nil {
return err
}
tmpl := cke.NewCluster()
err = yaml.Unmarshal(b, tmpl)
if err != nil {
return err
}
err = sabakan.ValidateTemplate(tmpl)
if err != nil {
return err
}
well.Go(func(ctx context.Context) error {
return storage.SetSabakanTemplate(ctx, tmpl)
})
well.Stop()
return well.Wait()
},
}
func init() {
sabakanCmd.AddCommand(sabakanSetTemplateCmd)
}