-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.go
126 lines (98 loc) · 2.9 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package provisioner
import (
"fmt"
"log"
"os/exec"
"os/user"
"strings"
"github.com/blang/semver"
"github.com/kubernauts/tk8-provisioner-rke/internal/cluster"
"github.com/kubernauts/tk8/pkg/provisioner"
"path/filepath"
)
type RKE struct {
}
// var Name string
func (p RKE) Init(args []string) {
// Name = cluster.Name
// if len(Name) == 0 {
// Name = "TK8RKE"
// }
// cluster.KubesprayInit()
// cluster.Create()
}
func checkRKEProvisionerFile(name string) (bool, error) {
matches, err := filepath.Glob(name + "*")
if err != nil {
return false, err
}
return len(matches) > 0, nil
}
func (p RKE) 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))
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
rkeProvisionerPath := usr.HomeDir + "/.terraform.d/plugins/terraform-provider-rke"
exists, _ := checkRKEProvisionerFile(rkeProvisionerPath)
if !exists {
log.Fatalln("Terraform RKE provisioner plugin does not exists. Please check https://github.com/yamamoto-febc/terraform-provider-rke for installation instructions specific to your OS.")
} else {
log.Println("Terraform RKE provisioner exists. Good to go!")
}
//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")
}
// Check if rke is installed
if _, err := exec.LookPath("rke"); err != nil {
log.Fatalln("RKE binary not found. Please install it. While RKE binary is not required while setting up cluster, it is strongly recommended for further interactions with cluster")
}
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 RKE) Scale(args []string) {
provisioner.NotImplemented()
}
func (p RKE) Reset(args []string) {
cluster.RKEReset()
}
func (p RKE) Remove(args []string) {
// remove rke cluster, not complete infra
// equivalent to rke remove --config rancher-cluster.yml
cluster.RKERemove()
}
func (p RKE) Upgrade(args []string) {
cluster.Upgrade()
}
func (p RKE) Destroy(args []string) {
// teardown complete infra
cluster.RKEDestroy()
}
func NewRKE() provisioner.Provisioner {
cluster.SetClusterName()
provisioner := new(RKE)
return provisioner
}