forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
177 lines (143 loc) · 4.88 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
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
# -*- mode: Python -*-
def secret_yaml_generic(name, namespace="", from_file=None, secret_type=None, from_env_file=None):
"""Returns YAML for a generic secret
Args:
name: The secret name.
namespace: The namespace.
from_file: Use the from-file secret generator. May be a string or a list of strings.
Example: ["ssh--privatekey=path/to/id_rsa", "ssh-publickey=path/to/id_rsa.pub"]
from_env_file: Specify the path to a file to read lines of key=val pairs to create a secret
(i.e. a Docker .env file)
secret_type (optional): Specify the type of the secret
Example: 'kubernetes.io/dockerconfigjson'
Returns:
The secret YAML as a blob
"""
args = [
"kubectl",
"create",
"secret",
"generic",
name,
]
if namespace:
args.extend(["-n", namespace])
generator = False
if from_file:
if type(from_file) == "string":
args.extend(["--from-file", from_file])
generator = True
elif type(from_file) == "list":
for f in from_file:
args.extend(["--from-file", f])
generator = True
else:
fail("Bad from_file argument: %s" % from_file)
if from_env_file:
if type(from_env_file) != "string":
fail("from_env_file only accepts strings")
args.extend(["--from-env-file", from_env_file])
generator = True
if not generator:
fail("No secret generator specified")
if secret_type:
if type(secret_type) == "string":
args.extend(["--type", secret_type])
else:
fail("Bad secret_type argument: %s" % secret_type)
args.extend(["-o=yaml", "--dry-run=client"])
return local(args, quiet=True, echo_off=True)
def secret_from_dict(name, namespace="", inputs={}):
"""Returns YAML for a generic secret
Args:
name: The configmap name.
namespace: The namespace.
inputs: A dict of keys and values to use. Nesting is not supported
Returns:
The secret YAML as a blob
"""
args = [
"kubectl",
"create",
"secret",
"generic",
name,
]
if namespace:
args.extend(["-n", namespace])
if type(inputs) != "dict":
fail("Bad argument to secret_from_dict, inputs was not dict typed")
for k,v in inputs.items():
args.extend(["--from-literal", "%s=%s" % (k,v)])
args.extend(["-o=yaml", "--dry-run=client"])
return local(args, quiet=True, echo_off=True)
def secret_yaml_registry(name, namespace="", flags_dict={}):
"""Returns YAML for a docker-registry secret
Args:
name: The configmap name.
namespace: The namespace.
flags_dict (optional): the flags used by docker-registry secret command
Example: '{"docker-server": "host", "docker-username": "username", "docker-password": "password", "docker-email": "[email protected]"}'
Returns:
The secret YAML as a blob
"""
args = [
"kubectl",
"create",
"secret",
"docker-registry",
name,
]
if namespace:
args.extend(["-n", namespace])
if type(flags_dict) != "dict":
fail("Bad argument to secret_from_dict, inputs was not dict typed")
for k,v in flags_dict.items():
args.extend(["--%s=%s" % (k,v)])
args.extend(["-o=yaml", "--dry-run=client"])
return local(args, quiet=True, echo_off=True)
def secret_create_generic(name, namespace="", from_file=None, secret_type=None, from_env_file=None):
"""Creates a secret in the current Kubernetes cluster.
Args:
name: The secret name.
namespace: The namespace.
from_file: Use the from-file secret generator. May be a string or a list of strings.
Example: ["ssh--privatekey=path/to/id_rsa", "ssh-publickey=path/to/id_rsa.pub"]
from_env_file: Specify the path to a file to read lines of key=val pairs to create a secret
(i.e. a Docker .env file)
secret_type (optional): Specify the type of the secret
Example: 'kubernetes.io/dockerconfigjson'
"""
k8s_yaml(secret_yaml_generic(name, namespace, from_file, secret_type, from_env_file))
def secret_yaml_tls(name, cert, key, namespace=""):
"""Returns YAML for a TLS secret
Args:
name: The secret name.
cert: A path to the cert PEM file on disk.
key: A path to the key PEM file on disk.
namespace: The namespace.
Returns:
The secret YAML as a blob
"""
args = [
"kubectl",
"create",
"secret",
"tls",
name,
"--cert=%s" % cert,
"--key=%s" % key,
]
if namespace:
args.extend(["-n", namespace])
args.extend(["-o=yaml", "--dry-run=client"])
return local(args, quiet=True, echo_off=True)
def secret_create_tls(name, cert, key, namespace=""):
"""Creates a TLS secret in the current Kubernetes cluster.
Args:
name: The secret name.
cert: A path to the cert PEM file on disk.
key: A path to the key PEM file on disk.
namespace: The namespace.
"""
k8s_yaml(secret_yaml_tls(name, cert, key, namespace))