|
1 | 1 | # -*- mode: Python -*-
|
2 | 2 |
|
3 |
| -def namespace_yaml(name): |
| 3 | +def namespace_yaml(name, annotations=[], labels=[]): |
4 | 4 | """Returns YAML for a namespace
|
5 | 5 |
|
6 | 6 | Args:
|
7 | 7 | name: The namespace name. Currently not validated.
|
| 8 | + annotations: Annotations applied to the namespace metadata |
| 9 | + labels: Labels applied to the namespace metadata |
8 | 10 |
|
9 | 11 | Returns:
|
10 | 12 | The namespace YAML as a blob
|
11 | 13 | """
|
| 14 | + annotations_str = '' |
| 15 | + labels_str = '' |
| 16 | + if (len(annotations) > 0): |
| 17 | + annotations_str = """ annotations: |
| 18 | +%s |
| 19 | +""" % '\n'.join([" %s" % s for s in annotations]) |
| 20 | + if (len(labels) > 0): |
| 21 | + labels_str = """ labels: |
| 22 | +%s |
| 23 | +""" % '\n'.join([" %s" % s for s in labels]) |
12 | 24 |
|
13 | 25 | return blob("""apiVersion: v1
|
14 | 26 | kind: Namespace
|
15 | 27 | metadata:
|
16 | 28 | name: %s
|
17 |
| -""" % name) |
| 29 | +%s%s""" % (name, annotations_str, labels_str)) |
18 | 30 |
|
19 |
| -def namespace_create(name, allow_duplicates=False): |
| 31 | +def namespace_create(name, allow_duplicates=False, annotations=[], labels=[]): |
20 | 32 | """Creates a namespace in the current Kubernetes cluster.
|
21 | 33 |
|
22 | 34 | Args:
|
23 | 35 | name: The namespace name. Currently not validated.
|
24 | 36 | allow_duplicates: Whether or not k8s should be allowed to have two
|
25 | 37 | instances of the same resource. Useful if you have more than one
|
26 | 38 | Tiltfile trying to create the same namespace.
|
| 39 | + annotations: Annotations applied to the namespace metadata |
| 40 | + labels: Labels applied to the namespace metadata |
27 | 41 | """
|
28 |
| - k8s_yaml(namespace_yaml(name), allow_duplicates=allow_duplicates) |
| 42 | + k8s_yaml( |
| 43 | + namespace_yaml(name, annotations=annotations, labels=labels), |
| 44 | + allow_duplicates=allow_duplicates |
| 45 | + ) |
29 | 46 |
|
30 | 47 | def namespace_inject(x, ns):
|
31 | 48 | """Takes K8s yaml, sets its namespace to `ns`, and returns it as a blob.
|
|
0 commit comments