add-namespace.py 982 Bytes
Newer Older
Kiran Veerapaneni's avatar
Kiran Veerapaneni committed
1
2
3
4
5
#!/usr/bin/env python

import yaml
import sys

6
7
8
9
10
def addNamespace(namespace, manifest):
    if 'metadata' in manifest and 'namespace' not in manifest['metadata'] and 'Namespace' not in manifest['kind']:
        manifest['metadata']['namespace'] = namespace
    if 'subjects' in manifest:
        manifest['subjects'][0]['namespace'] = namespace
11
12
def removeReplicasFromWorkerStatefulSet(manifest):
    if manifest['kind'] == 'StatefulSet' and manifest['metadata']['name'] == 'airflow-worker':
13
14
        if manifest['metadata']['labels']['autoscalingEnabled']:
            del manifest['spec']['replicas']
15

16

Kiran Veerapaneni's avatar
Kiran Veerapaneni committed
17
18
19
def addingNamespace(namespace):
    for manifest in yaml.load_all(sys.stdin, Loader=yaml.FullLoader):
        if manifest:
20
            addNamespace(namespace, manifest)
21
            removeReplicasFromWorkerStatefulSet(manifest)
Kiran Veerapaneni's avatar
Kiran Veerapaneni committed
22
23
24
25
26
            print ('---')
            print (yaml.dump(manifest, default_flow_style=False, sort_keys=False))

namespace="osdu"
addingNamespace(namespace)