-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.go
106 lines (79 loc) · 2.13 KB
/
common.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package provisioner
import (
"fmt"
"log"
"os/exec"
"os/user"
"strings"
"github.com/blang/semver"
"github.com/kubernauts/tk8-provisioner-cattle-aws/internal/cluster"
"github.com/kubernauts/tk8/pkg/provisioner"
)
type CATTLEAWS struct {
}
// var Name string
func (p CATTLEAWS) Init(args []string) {
// Name = cluster.Name
// if len(Name) == 0 {
// Name = "TK8RKE"
// }
// cluster.KubesprayInit()
// cluster.Create()
}
func (p CATTLEAWS) Setup(args []string) {
kube, err := exec.LookPath("kubectl")
if err != nil {
log.Fatal("kubectl not found, kindly check")
}
fmt.Printf("Found kubectl at %s\n", kube)
rr, err := exec.Command("kubectl", "version", "--client", "--short").Output()
if err != nil {
log.Fatal(err)
}
log.Println(string(rr))
_, err = user.Current()
if err != nil {
log.Fatal(err)
}
//Check if kubectl version is greater or equal to 1.10
parts := strings.Split(string(rr), " ")
KubeCtlVer := strings.Replace((parts[2]), "v", "", -1)
v1, err := semver.Make("1.10.0")
v2, err := semver.Make(strings.TrimSpace(KubeCtlVer))
if v2.LT(v1) {
log.Fatalln("kubectl client version on this system is less than the required version 1.10.0")
}
if _, err := exec.LookPath("terraform"); err != nil {
log.Fatalln("Terraform binary not found in the installation folder")
}
log.Println("Terraform binary exists in the installation folder, terraform version:")
terr, err := exec.Command("terraform", "version").Output()
if err != nil {
log.Fatal(err)
}
log.Println(string(terr))
cluster.Install()
}
func (p CATTLEAWS) Scale(args []string) {
provisioner.NotImplemented()
}
func (p CATTLEAWS) Reset(args []string) {
cluster.Reset()
}
func (p CATTLEAWS) Remove(args []string) {
// remove cattle-aws cluster, not complete infra
// equivalent to cattle-aws remove --config rancher-cluster.yml
provisioner.NotImplemented()
}
func (p CATTLEAWS) Upgrade(args []string) {
cluster.Upgrade()
}
func (p CATTLEAWS) Destroy(args []string) {
// teardown complete infra
cluster.CattleDestroy()
}
func NewCattleAWS() provisioner.Provisioner {
cluster.SetClusterName()
provisioner := new(CATTLEAWS)
return provisioner
}