-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto.py
More file actions
65 lines (51 loc) · 2.11 KB
/
Copy pathauto.py
File metadata and controls
65 lines (51 loc) · 2.11 KB
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
import argparse
import os
from enum import Enum
class Service():
def __init__(self, title, location):
self.title = title
self.location = location
def rebuild(self):
os.system("docker build -t {}:1.0.0-a0 -f {}/{}/Dockerfile .".format(self.title, self.location, self.location))
os.system("kubectl delete deployment {}".format(self.title))
os.system("kubectl delete service {}".format(self.title))
os.system("kubectl create -f {}/{}-deployment.yml".format(self.location, self.title))
CLICKUI = Service("clickui", "ClickUI")
APIGATEWAY = Service("apigateway", "APIGateway")
STARS = Service("stars", "Stars")
class Ingress():
def __init__(self, title, location):
self.title = title
self.location = location
def rebuild(self):
os.system("kubectl delete ingress.extensions {}".format(self.title))
os.system("kubectl create -f {}/{}-deployment.yml".format(self.location, self.title))
INGRESS = Ingress("ingress", "Ingress")
buildables = [
INGRESS, CLICKUI, STARS, APIGATEWAY
]
def argument_string_to_bool(v):
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise argparse.ArgumentTypeError("Expected value parseable to boolean, but got `{}`.".format(v))
def main():
parser = argparse.ArgumentParser(description='Automatically configure kubectl deployments.')
group = parser.add_mutually_exclusive_group()
all_arg = group.add_argument("-a", "--all", dest="all",
type=argument_string_to_bool,
default=False)
name_arg = group.add_argument("-n", "--name", type=str)
args = parser.parse_args()
if (args.all):
for buildable in buildables:
buildable.rebuild()
else:
if args.name is None:
raise argparse.ArgumentError(name, "Flag --all was set to false, but no name was specified.")
buildable = next(f for f in buildables if f.title == args.name)
buildable.rebuild()
if __name__ == "__main__":
main()