-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmd.go
76 lines (65 loc) · 2.15 KB
/
cmd.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
// Copyright Contributors to the Open Cluster Management project
package cluster
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/stolostron/cm-cli/pkg/cmd/scale/cluster/scenario"
genericclioptionscm "github.com/stolostron/cm-cli/pkg/genericclioptions"
"github.com/stolostron/cm-cli/pkg/helpers"
clusteradmhelpers "open-cluster-management.io/clusteradm/pkg/helpers"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
var example = `
# Scale a cluster
%[1]s scale cluster --cluster clustername --machinepool poolname --replicas 4
`
const (
scenarioDirectory = "scale"
)
var valuesTemplatePath = filepath.Join(scenarioDirectory, "values-template.yaml")
var valuesDefaultPath = filepath.Join(scenarioDirectory, "values-default.yaml")
// NewCmd ...
func NewCmd(cmFlags *genericclioptionscm.CMFlags, streams genericclioptions.IOStreams) *cobra.Command {
o := newOptions(cmFlags, streams)
cluster := &cobra.Command{
Use: "cluster",
Short: "Scale a cluster",
Example: fmt.Sprintf(example, helpers.GetExampleHeader()),
SilenceUsage: true,
PreRunE: func(c *cobra.Command, args []string) error {
isSupported, err := helpers.IsSupported(o.CMFlags)
if err != nil {
return err
}
if !isSupported {
return fmt.Errorf("this command '%s %s' is only available on %s or %s",
helpers.GetExampleHeader(),
strings.Join(os.Args[1:], " "),
helpers.RHACM,
helpers.MCE)
}
clusteradmhelpers.DryRunMessage(cmFlags.DryRun)
return nil
},
RunE: func(c *cobra.Command, args []string) error {
if err := o.complete(c, args); err != nil {
return err
}
if err := o.validate(); err != nil {
return err
}
if err := o.run(); err != nil {
return err
}
return nil
},
}
cluster.SetUsageTemplate(clusteradmhelpers.UsageTempate(cluster, scenario.GetScenarioResourcesReader(), valuesTemplatePath))
cluster.Flags().StringVar(&o.valuesPath, "values", "", "The files containing the values")
cluster.Flags().StringVar(&o.clusterName, "cluster", "", "Name of the cluster")
cluster.Flags().IntVar(&o.replicas, "replicas", 3, "number of workers for the pool")
return cluster
}