forked from sieve-project/sieve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_env.py
218 lines (187 loc) · 6.8 KB
/
check_env.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import os
import subprocess
from sieve_common.common import fail, ok, warn
def check_go_env():
if os.system("go version > /dev/null 2>&1") != 0:
fail(
"golang environment not detected, please install it according to https://golang.org/doc/install"
)
return
else:
ok("golang environment detected")
goenv = {
x.split("=")[0]: x.split("=")[1].strip('"')
for x in subprocess.check_output("go env", shell=True, encoding="UTF-8")
.strip()
.split("\n")
}
if "GOVERSION" in goenv:
version = goenv["GOVERSION"][2:]
else:
version = os.popen("go version").read().split()[2][2:]
version_breakdown = version.split(".")
major = int(version_breakdown[0])
minor = int(version_breakdown[1])
if major > 1 or (major == 1 and minor >= 13):
ok("go version {} satisfies the requirement".format(version))
else:
warn(
"go version {} not satisfies the requirement, the minimum go version should be above 1.13.0".format(
version
)
)
if "GOPATH" in os.environ:
ok("environment variable $GOPATH detected")
else:
fail(
"environment variable $GOPATH not detected, try to set it according to https://golang.org/doc/gopath_code#GOPATH"
)
return
def check_kubectl_env():
if os.system("kubectl --help > /dev/null 2>&1") != 0:
fail(
"kubectl not detected, please install it according to https://kubernetes.io/docs/tasks/tools/"
)
return
else:
ok("kubectl detected")
def check_helm_env():
warn(
"helm is only required for certain controllers, please ignore the following failure if your controller does not need helm"
)
if os.system("helm version > /dev/null 2>&1") != 0:
fail(
"helm not detected, please install it according to https://helm.sh/docs/intro/install/"
)
return
else:
ok("helm detected")
def check_mage_env():
warn(
"mage is only required for certain controllers, please ignore the following failure if your controller does not need mage"
)
if os.system("mage --version > /dev/null 2>&1") != 0:
fail("mage not detected, please install it according to https://magefile.org/")
return
else:
ok("mage detected")
def check_kind_env():
if os.system("kind version > /dev/null 2>&1") != 0:
fail(
"kind not detected, please install it according to https://kind.sigs.k8s.io/docs/user/quick-start/#installation"
)
return
else:
ok("kind detected")
# version = subprocess.check_output(
# "kind version", shell=True, encoding='UTF-8').strip().split()[1]
version = os.popen("kind version").read().split()[1].split("-")[0]
parsed = [int(x) for x in (version[1:].split("."))]
major = parsed[0]
minor = parsed[1]
if major > 0 or (major == 0 and minor >= 10):
ok("kind version {} satisfies the requirement".format(version))
else:
warn(
"kind version {} not satisfies the requirement, the minimum kind version should be above 0.10.0".format(
version
)
)
if "KUBECONFIG" in os.environ:
ok("environment variable $KUBECONFIG detected")
else:
fail(
"environment variable $KUBECONFIG not detected, try to set it according to https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig"
)
return
def check_sqlite_env():
warn(
"sqlite3 version 3.32 and pysqlite3 are only required for learning mode, please ignore any failures below if you only want to reproduce the bugs"
)
if os.system("sqlite3 -version > /dev/null 2>&1") != 0:
fail(
"sqlite3 not detected, please install it with version above 3.32 according to https://help.dreamhost.com/hc/en-us/articles/360028047592-Installing-a-custom-version-of-SQLite3"
)
return
else:
ok("sqlite3 detected")
version = (
subprocess.check_output("sqlite3 -version", shell=True, encoding="UTF-8")
.strip()
.split()[0]
)
major = int(version.split(".")[0])
minor = int(version.split(".")[1])
if major > 3 or (major == 3 and minor >= 32):
ok("sqlite3 version {} satisfies the requirement".format(version))
else:
fail(
"sqlite3 version {} not satisfies the requirement, the minimum sqlite3 version should be above 3.32, please update according to https://help.dreamhost.com/hc/en-us/articles/360028047592-Installing-a-custom-version-of-SQLite3".format(
version
)
)
try:
import sqlite3
ok("python module pysqlite3 detected")
except Exception as err:
fail(
"python module pysqlite3 not detected, try to install it by `pip3 install pysqlite3`"
)
def check_python_env():
try:
import kubernetes
ok("python module kubernetes detected")
except Exception as err:
fail(
"python module pysqlite3 not detected, try to install it by `pip3 install kubernetes`"
)
try:
import docker
ok("python module docker detected")
except Exception as err:
fail(
"python module docker not detected, try to install it by `pip3 install docker`"
)
try:
import yaml
ok("python module pyyaml detected")
except Exception as err:
fail(
"python module pyyaml not detected, try to install it by `pip3 install pyyaml`"
)
try:
import deepdiff
ok("python module deepdiff detected")
except Exception as err:
fail(
"python module deepdiff not detected, try to install it by `pip3 install deepdiff`"
)
if __name__ == "__main__":
try:
check_go_env()
except Exception as e:
warn("unable to check go env due to exception {}".format(str(e)))
try:
check_kubectl_env()
except Exception as e:
warn("unable to check kubectl env due to exception {}".format(str(e)))
try:
check_kind_env()
except Exception as e:
warn("unable to check kind env due to exception {}".format(str(e)))
try:
check_python_env()
except Exception as e:
warn("unable to check python env due to exception {}".format(str(e)))
try:
check_helm_env()
except Exception as e:
warn("unable to check helm env due to exception {}".format(str(e)))
try:
check_mage_env()
except Exception as e:
warn("unable to check mage env due to exception {}".format(str(e)))
# try:
# check_sqlite_env()
# except Exception as e:
# warn("unable to check sqlite env due to exception {}".format(str(e)))