-
Notifications
You must be signed in to change notification settings - Fork 26
/
cluster.go
42 lines (34 loc) · 1007 Bytes
/
cluster.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
package delete
import (
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/sapcc/kubernikus/pkg/cmd"
)
func (o *DeleteOptions) NewClusterCommand() *cobra.Command {
c := &cobra.Command{
Use: "cluster [name]",
Short: "Deletes the cluster with the given name",
Aliases: []string{"clusters"},
PreRun: o.clusterPreRun,
Run: o.clusterRun,
}
return c
}
func (o *DeleteOptions) clusterPreRun(c *cobra.Command, args []string) {
cmd.CheckError(validateClusterCommandArgs(args))
cmd.CheckError(o.SetupKubernikusClient())
}
func (o *DeleteOptions) clusterRun(c *cobra.Command, args []string) {
cmd.CheckError(o.Kubernikus.DeleteCluster(args[0]))
fmt.Printf("Cluster %v scheduled for deletion.", args[0])
}
func validateClusterCommandArgs(args []string) error {
if len(args) > 1 {
return errors.Errorf("Surplus arguments to cluster delete.")
}
if len(args) < 1 {
return errors.Errorf("Please supply the name of the cluster to be deleted.")
}
return nil
}