forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
89 lines (76 loc) · 3.77 KB
/
Tiltfile
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
def min_k8s_version(min_version):
version_str = _get_server_version()
cur_ver = _version_tuple(version_str)
min_ver = _version_tuple(min_version)
if cur_ver < min_ver:
print(" ---------------------------------------------------------- ")
print("| |")
print("| Minimum Kubernetes Version Not Met! |")
print("| Current Version : v{} |".format(version_str))
print("| Minimum Required Version : v{} |".format(min_version))
print("| Current Kubernetes Cluster : {} |".format( k8s_context()))
print("| |")
print(" ---------------------------------------------------------- ")
fail('Minimum Kubernetes Version Not Met! Current Version is %s' % version_str)
def max_k8s_version(max_version):
version_str = _get_server_version()
cur_ver = _version_tuple(version_str)
max_ver = _version_tuple(max_version)
if cur_ver > max_ver:
print(" ---------------------------------------------------------- ")
print("| |")
print("| Maximum Kubernetes Version Not Met! |")
print("| Current Version : v{} |".format(version_str))
print("| Maximum Required Version : v{} |".format(max_version))
print("| Current Kubernetes Cluster : {} |".format( k8s_context()))
print("| |")
print(" ---------------------------------------------------------- ")
fail('Maximum Kubernetes Version Not Met! Current Version is %s' % version_str)
def _get_server_version():
# This relies on the fact that the shell command returning something in the
# form 'Server Version: vX.X.X'.
#
# The previous version used 'grep' to filter out the server version. Use a
# native way to support systems without 'grep'.
kubectl_version_output = str(local('kubectl version', quiet=True))
for line in kubectl_version_output.split('\n'):
if line.startswith('Server Version'):
version_string = line.split(':')[1].strip()
if version_string.startswith('version.Info'):
# we are pre 1.28 kubectl, let's use the old method
return _get_server_version_pre_1_28_kubectl()
else:
return version_string.replace('v', '')
return ""
def _get_server_version_pre_1_28_kubectl():
kubectl_version_output = str(local('kubectl version --short', quiet=True))
version_str = ''
for line in kubectl_version_output.split('\n'):
if line.startswith('Server Version'):
version_str = line
break
# Get the string, separate it at the colon, remove the 'v' and any spaces.
return version_str.split(':')[1].replace('v','').strip()
def _version_tuple(v):
# splits a string into a list of contiguous numeric and non-numeric parts, and makes the numeric parts ints, e.g.:
# _version_tuple("1.2020.3-beta.2") == [1, ".", 2020, ".", 3, "-beta.", 2]
# this allows version comparison such that "1.10" > "1.9"
ret = []
if len(v) == 0:
return ret
cur_part_is_number = v[0].isdigit()
cur_part = ''
for c in v.elems():
if c.isdigit() != cur_part_is_number:
if cur_part.isdigit():
ret.append(int(cur_part))
else:
ret.append(cur_part)
cur_part = ''
cur_part_is_number = c.isdigit()
cur_part += c
if cur_part.isdigit():
ret.append(int(cur_part))
else:
ret.append(cur_part)
return ret