-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathgenerate-cmo-config.py
executable file
·61 lines (51 loc) · 3.2 KB
/
generate-cmo-config.py
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
#!/usr/bin/env python
import copy
import oyaml as yaml
import os
input_file_path = os.path.join("resources", "cluster-monitoring-config", "config.yaml")
output_file_path_non_uwm = os.path.join("deploy", "cluster-monitoring-config-non-uwm", "50-GENERATED-cluster-monitoring-config.yaml")
output_file_path_non_uwm_4_5 = os.path.join("deploy", "cluster-monitoring-config-non-uwm", "clusters-v4.5", "50-GENERATED-cluster-monitoring-config.yaml")
output_file_path_non_uwm_pre_411 = os.path.join("deploy", "cluster-monitoring-config-non-uwm", "pre-4.11", "50-GENERATED-cluster-monitoring-config.yaml")
output_file_path_uwm = os.path.join("deploy", "cluster-monitoring-config", "50-GENERATED-cluster-monitoring-config.yaml")
output_file_path_uwm_pre_411 = os.path.join("deploy", "cluster-monitoring-config", "pre-4.11", "50-GENERATED-cluster-monitoring-config.yaml")
output_file_path_fr = os.path.join("deploy", "osd-fedramp-cluster-monitoring-config", "50-GENERATED-cluster-monitoring-config.yaml")
output_mc_file_path_non_uwm = os.path.join("deploy", "cluster-monitoring-config-non-uwm", "management-clusters", "50-GENERATED-cluster-monitoring-config.yaml")
output_mc_file_path_uwm = os.path.join("deploy", "cluster-monitoring-config", "management-clusters", "50-GENERATED-cluster-monitoring-config.yaml")
def str_presenter(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
yaml.add_representer(str, str_presenter)
def dump_configmap(input_path, configmap_path, enableUserWorkload,
disableremoteWrite, retentionTime = "11d",
enableGrafana = False):
with open(input_path,'r') as input_file:
config = yaml.safe_load(input_file)
config["enableUserWorkload"] = enableUserWorkload
config["prometheusK8s"]["retention"] = retentionTime
if disableremoteWrite:
del config['prometheusK8s']['remoteWrite']
if enableGrafana:
# Grafana config was removed in 4.11, pre-4.11, put it back
config["grafana"] = copy.deepcopy(config["prometheusOperator"])
cmo_config = {
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "cluster-monitoring-config" ,
"namespace": "openshift-monitoring"
},
"data": {
"config.yaml": yaml.dump(config)
}
}
with open(configmap_path, 'w') as outfile:
yaml.dump(cmo_config, outfile)
dump_configmap(input_file_path, output_file_path_uwm, True, False)
dump_configmap(input_file_path, output_file_path_uwm_pre_411, True, False, "7d", True)
dump_configmap(input_file_path, output_file_path_non_uwm, False, False)
dump_configmap(input_file_path, output_file_path_non_uwm_4_5, False, False, "11d", True)
dump_configmap(input_file_path, output_file_path_non_uwm_pre_411, False, False, "7d", True)
dump_configmap(input_file_path, output_file_path_fr, True, True)
dump_configmap(input_file_path, output_mc_file_path_uwm, True, False, "7d")
dump_configmap(input_file_path, output_mc_file_path_non_uwm, False, False, "7d")