Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit cb2c55c

Browse files
authored
Merge pull request #307 from JoshVanL/cluster-set-cluster
Adds set-current cluster subcommand
2 parents f0ade64 + 84300d8 commit cb2c55c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Jetstack Ltd. See LICENSE for details.
2+
package cmd
3+
4+
import (
5+
"github.com/spf13/cobra"
6+
7+
"github.com/jetstack/tarmak/pkg/tarmak"
8+
)
9+
10+
var clusterSetCurrentCmd = &cobra.Command{
11+
Use: "set-current",
12+
Short: "Set current cluster in config",
13+
Run: func(cmd *cobra.Command, args []string) {
14+
t := tarmak.New(globalFlags)
15+
defer t.Cleanup()
16+
17+
if len(args) != 1 {
18+
t.Log().Fatalf("Only one cluster can be set as current cluster")
19+
}
20+
21+
found := false
22+
LOOP:
23+
for _, env := range t.Environments() {
24+
for _, cluster := range env.Clusters() {
25+
if args[0] == cluster.ClusterName() {
26+
found = true
27+
break LOOP
28+
}
29+
}
30+
}
31+
32+
if !found {
33+
t.Log().Fatalf("Failed to find cluster '%s' in config", args[0])
34+
}
35+
36+
if err := t.Config().SetCurrentCluster(args[0]); err != nil {
37+
t.Log().Fatalf("Failed to set current cluster in config: %v", err)
38+
}
39+
40+
},
41+
}
42+
43+
func init() {
44+
clusterCmd.AddCommand(clusterSetCurrentCmd)
45+
}

0 commit comments

Comments
 (0)