Add xApp pod annotation suport 03/3803/1
authorZhe <zhehuang@research.att.com>
Sat, 23 May 2020 03:45:00 +0000 (23:45 -0400)
committerZhe <zhehuang@research.att.com>
Sat, 23 May 2020 03:45:00 +0000 (23:45 -0400)
Signed-off-by: Zhe <zhehuang@research.att.com>
Change-Id: Icbcaf627b569aae841964d50bc088e21d51eb5e9

xapp_onboarder/tests/constants.py
xapp_onboarder/xapp_onboarder/helm_controller/xApp_builder.py
xapp_onboarder/xapp_onboarder/helm_controller/xapp_schema.py
xapp_onboarder/xapp_onboarder/resources/xapp-std/templates/deployment.yaml

index 9c961bf..a5c3249 100644 (file)
@@ -38,6 +38,11 @@ controls_schema_file = {
 config_file = {
     "xapp_name": "test_xapp",
     "version": "1.0.0",
+       "annotations": {
+         "prometheus.io/path": "/ric/v1/metrics",
+      "prometheus.io/port": "8080",
+      "prometheus.io/scrape": "true"
+       },
     "containers": [
         {
             "name": "mcxapp",
index 1eee2a5..ab314ad 100644 (file)
@@ -122,14 +122,13 @@ class xApp():
 
         for item in current_node.keys():
             if type(current_node.get(item)) is not dict:
-                current_node[item] = '{{ '+ helm_value_path +'.'+ item + ' | toJson }}'
+                current_node[item] = '{{ index '+ helm_value_path +' "'+ item + '" | toJson }}'
             else:
                 new_node_list = node_list.copy()
                 new_node_list.append(item)
                 self.recursive_convert_config_file(new_node_list)
 
 
-
     def append_config_to_config_map(self):
         with open(self.chart_workspace_path + '/' + self.chart_name + '/templates/appconfig.yaml', 'a') as outputfile:
             self.recursive_convert_config_file()
@@ -137,6 +136,7 @@ class xApp():
             indented_config_text = indent(config_file_json_text, 4)
             indented_config_text = re.sub(r"\"{{", '{{', indented_config_text)
             indented_config_text = re.sub(r"}}\"", '}}', indented_config_text)
+            indented_config_text = re.sub(r"\\", '', indented_config_text)
             outputfile.write("  config-file.json: |\n")
             outputfile.write(indented_config_text)
             outputfile.write("\n  schema.json: |\n")
@@ -162,7 +162,10 @@ class xApp():
             for probes in ['readinessProbe', 'livenessProbe']:
                 if self.configmap_config_json_file.get(probes):
                     probe_definition = self.configmap_config_json_file.get(probes)
-                    probe_definition_yaml = yaml.dump(probe_definition)
+                    probe_definition_yaml = yaml.dump(probe_definition, width=1000)
+
+                    print(probe_definition_yaml)
+
                     indented_probe_definition_yaml = indent(probe_definition_yaml, 12)
                     indented_probe_definition_yaml = re.sub(r" \| toJson", '', indented_probe_definition_yaml)
                     indented_probe_definition_yaml = re.sub(r"'", '', indented_probe_definition_yaml)
index 0588dfc..435e283 100644 (file)
@@ -44,6 +44,22 @@ schema = {
             ],
             "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
         },
+        "annotations": {
+            "$id": "#/properties/annotation",
+            "type": "object",
+            "title": "The k8s pod annotation",
+            "additionalProperties": {
+                "anyOf": [
+                    { "type": "string" },
+                    {
+                        "type": "array",
+                        "items": {
+                            "type": "object"
+                        }
+                    }
+                ]
+            }
+        },
         "containers": {
             "$id": "#/properties/containers",
             "type": "array",
index 9d4de1e..2bdacb2 100644 (file)
@@ -30,6 +30,17 @@ spec:
       release: {{ .Release.Name }}
   template:
     metadata:
+      {{- if .Values.annotations }}
+      annotations:
+        {{- range $key, $value := .Values.annotations }}
+          {{- if kindIs "string" $value }}
+        {{ $key }}: {{ $value | toPrettyJson }}
+          {{- else }}
+        {{ $key }}: |
+{{- $value | toPrettyJson | nindent 10 }}
+          {{- end }}
+        {{- end -}}
+      {{ end }}
       labels:
         app: {{ include "ricxapp.namespace" . }}-{{ include "ricxapp.name" . }}
         release: {{ .Release.Name }}