add helm chart builder and service scheme file 98/11098/1
authorhoejoo.lee <hoejoo.lee@samsung.com>
Mon, 15 May 2023 07:52:40 +0000 (03:52 -0400)
committerhoejoo.lee <hoejoo.lee@samsung.com>
Mon, 15 May 2023 07:52:40 +0000 (03:52 -0400)
Change-Id: I725897a5d0a4ac5a06bb67bb9b1cf5a705f2da09
Signed-off-by: hoejoo.lee <hoejoo.lee@samsung.com>
go.mod
go.sum
pkg/helm/chart_builder.go
pkg/helm/data/sample_schema.json

diff --git a/go.mod b/go.mod
index 6d697f3..1ed9528 100755 (executable)
--- a/go.mod
+++ b/go.mod
@@ -22,6 +22,9 @@ require (
        github.com/modern-go/reflect2 v1.0.2 // indirect
        github.com/pelletier/go-toml/v2 v2.0.6 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
+       github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
+       github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
+       github.com/xeipuuv/gojsonschema v1.2.0 // indirect
        github.com/ugorji/go/codec v1.2.7 // indirect
        golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
        golang.org/x/net v0.4.0 // indirect
diff --git a/go.sum b/go.sum
index 726edeb..8e54db6 100755 (executable)
--- a/go.sum
+++ b/go.sum
@@ -58,6 +58,12 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
+github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
+github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
+github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
+github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
+github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
 github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
 github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
 github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
index 696964f..3318eb0 100755 (executable)
@@ -27,6 +27,7 @@ import (
        "os"
        "path/filepath"
 
+       "github.com/xeipuuv/gojsonschema"
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
 )
 
@@ -34,10 +35,12 @@ const (
        VALUES_YAML = "values.yaml"
        CHART_YAML  = "Chart.yaml"
 
+       ENV_CHART_WORKSPACE_PATH = "CHART_WORKSPACE_PATH"
+
        SERVING_VERSION_ALPHA = "serving.kubeflow.org/v1alpha2"
        SERVING_VERSION_BETA  = "serving.kubeflow.org/v1beta1"
-       RESOURCE_ALPHA        = "'resources/xapp-inf-alpha'"
-       RESOURCE_BETA         = "'resources/xapp-inf-beta'"
+       RESOURCE_ALPHA        = "resources/inf-alpha"
+       RESOURCE_BETA         = "resources/inf-beta"
 )
 
 type HelmChartBuilder interface {
@@ -75,16 +78,21 @@ func NewChartBuilder(configFile string, schemaFile string) *ChartBuilder {
 
        chartBuilder.chartName = chartBuilder.config.XappName
        chartBuilder.chartVersion = chartBuilder.config.Version
-       chartBuilder.chartWorkspacePath = os.Getenv("CHART_WORKSPACE_PATH") + "/" + chartBuilder.chartName + "-" + chartBuilder.chartVersion
+       chartBuilder.chartWorkspacePath = os.Getenv(ENV_CHART_WORKSPACE_PATH) + "/" + chartBuilder.chartName + "-" + chartBuilder.chartVersion
 
        _, err = os.Stat(chartBuilder.chartWorkspacePath)
        if err != nil {
                if !os.IsNotExist(err) {
                        os.RemoveAll(chartBuilder.chartWorkspacePath)
-                       os.Mkdir(chartBuilder.chartWorkspacePath, os.FileMode(644))
                }
        }
 
+       err = os.Mkdir(chartBuilder.chartWorkspacePath, os.FileMode(0744))
+       if err != nil {
+               logger.Logging(logger.ERROR, err.Error())
+               return nil
+       }
+
        resourceVersionMap := map[string]string{
                SERVING_VERSION_ALPHA: RESOURCE_ALPHA,
                SERVING_VERSION_BETA:  RESOURCE_BETA,
@@ -153,13 +161,11 @@ func (c *ChartBuilder) copyDirectory(src string, dest string) (err error) {
 
        _, err = os.Stat(dest)
        if err != nil && !os.IsNotExist(err) {
-               return
-       }
-       if err == nil {
                return fmt.Errorf("destination(%s) is already exists", dest)
        }
-       err = os.MkdirAll(dest, srcInfo.Mode())
-       if err != nil {
+
+       err = os.Mkdir(dest, os.FileMode(0744))
+       if err != nil && !os.IsExist(err) {
                return
        }
        entries, err := ioutil.ReadDir(src)
@@ -206,6 +212,7 @@ func (c *ChartBuilder) parseConfigFile(configFile string) (config Config, err er
                logger.Logging(logger.ERROR, err.Error())
                return
        }
+       config.configFile = configFile
        return
 }
 
@@ -222,6 +229,8 @@ func (c *ChartBuilder) parseSchemaFile(schemaFile string) (schema Schema, err er
                logger.Logging(logger.ERROR, err.Error())
                return
        }
+
+       schema.schemaFile = schemaFile
        return
 }
 
@@ -236,3 +245,23 @@ func (c *ChartBuilder) appendConfigToValuesYaml() (err error) {
 func (c *ChartBuilder) changeChartNameVersion() (err error) {
        return errors.New("not yet implemented")
 }
+
+func (c *ChartBuilder) ValidateChartMaterials() (err error) {
+
+       schemaLoader := gojsonschema.NewReferenceLoader("file://" + c.schema.schemaFile)
+       configLoader := gojsonschema.NewReferenceLoader("file://" + c.config.configFile)
+
+       result, err := gojsonschema.Validate(schemaLoader, configLoader)
+
+       if err != nil {
+               return
+       }
+
+       if !result.Valid() {
+               for _, desc := range result.Errors() {
+                       logger.Logging(logger.ERROR, fmt.Sprintf("[Invalid Config] - %s\n", desc))
+               }
+               return errors.New("Invalid Config")
+       }
+       return
+}
index 3d8f476..04f3ca9 100755 (executable)
 {
-  "definitions": {},
-  "$schema": "http://json-schema.org/draft-07/schema#",
-  "$id": "http://example.com/root.json",
-  "type": "object",
-  "title": "The Root Schema",
-  "required": [
-    "service_ports",
-    "rmr",
-    "envs"
-  ],
-  "properties": {
-    "service_ports": {
-      "$id": "#/properties/service_ports",
-      "type": "object",
-      "title": "The Service_ports Schema",
-      "required": [
-        "xapp_port",
-        "rmr_port"
-      ],
-      "properties": {
-        "xapp_port": {
-          "$id": "#/properties/service_ports/properties/xapp_port",
-          "type": "integer",
-          "title": "The Xapp_port Schema",
-          "default": 0,
-          "examples": [
-            4560
-          ]
-        },
-        "rmr_port": {
-          "$id": "#/properties/service_ports/properties/rmr_port",
-          "type": "integer",
-          "title": "The Rmr_port Schema",
-          "default": 0,
-          "examples": [
-            4561
-          ]
-        }
-      }
-    },
-    "rmr": {
-      "$id": "#/properties/rmr",
-      "type": "object",
-      "title": "The Rmr Schema",
-      "required": [
-        "protPort",
-        "maxSize",
-        "numWorkers",
-        "txMessages",
-        "rxMessages",
-        "file_path",
-        "contents"
-      ],
-      "properties": {
-        "protPort": {
-          "$id": "#/properties/rmr/properties/protPort",
-          "type": "string",
-          "title": "The Protport Schema",
-          "default": "",
-          "examples": [
-            "tcp:4560"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "maxSize": {
-          "$id": "#/properties/rmr/properties/maxSize",
-          "type": "integer",
-          "title": "The Maxsize Schema",
-          "default": 0,
-          "examples": [
-            2072
-          ]
-        },
-        "numWorkers": {
-          "$id": "#/properties/rmr/properties/numWorkers",
-          "type": "integer",
-          "title": "The Numworkers Schema",
-          "default": 0,
-          "examples": [
-            1
-          ]
-        },
-        "txMessages": {
-          "$id": "#/properties/rmr/properties/txMessages",
-          "type": "array",
-          "title": "The Txmessages Schema",
-          "items": {
-            "$id": "#/properties/rmr/properties/txMessages/items",
+    "definitions": {},
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "$id": "http://example.com/root.json",
+    "type": "object",
+    "title": "The Root Schema",
+    "required": [
+      "xapp_name",
+      "xapp_type",
+      "version",
+      "sa_name",
+      "inferenceservice"
+    ],
+    "properties": {
+      "inferenceservice": {
+        "$id": "#/properties/inferenceservice",
+        "type": "object",
+        "title": "The Inferenceservice Schema",
+        "required": [
+          "engine",
+          "storage_uri",
+          "api_version",
+          "min_replicas",
+          "max_replicas"
+        ],
+        "properties": {
+          "engine": {
+            "$id": "#/properties/inferenceservice/properties/engine",
             "type": "string",
-            "title": "The Items Schema",
+            "title": "The Engine Schema",
             "default": "",
             "examples": [
-              "RIC_SUB_REQ",
-              "RIC_SUB_DEL_REQ"
-            ],
-            "pattern": "^(.*)$"
-          }
-        },
-        "rxMessages": {
-          "$id": "#/properties/rmr/properties/rxMessages",
-          "type": "array",
-          "title": "The Rxmessages Schema",
-          "items": {
-            "$id": "#/properties/rmr/properties/rxMessages/items",
+              "tensorflow"
+            ]
+          },
+          "storage_uri": {
+            "$id": "#/properties/inferenceservice/properties/storage_uri",
+            "type": "string",
+            "title": "The Storage_uri Schema",
+            "default": "",
+            "examples": [
+                "s3://mlpipeline/artifacts/sample-rl-pipeline-bbzh4/sample-rl-pipeline-bbzh4-949264085/sample-training-saved-model.tgz"
+            ]
+          },
+          "api_version": {
+            "$id": "#/properties/inferenceservice/properties/api_version",
             "type": "string",
-            "title": "The Items Schema",
+            "title": "The Api_version Schema",
             "default": "",
             "examples": [
-              "RIC_SUB_RESP",
-              "RIC_SUB_FAILURE",
-              "RIC_SUB_DEL_RESP",
-              "RIC_SUB_DEL_FAILURE",
-              "RIC_INDICATION"
-            ],
-            "pattern": "^(.*)$"
+                "serving.kubeflow.org/v1alpha2",
+                "serving.kubeflow.org/v1beta1"
+            ]
+          },
+          "min_replicas": {
+            "$id": "#/properties/inferenceservice/properties/min_replicas",
+            "type": "integer",
+            "title": "The Min_replicas Schema",
+            "default": 0,
+            "examples": [
+              1
+            ]
+          },
+          "max_replicas": {
+            "$id": "#/properties/inferenceservice/properties/max_replicas",
+            "type": "integer",
+            "title": "The Max_replicas Schema",
+            "default": 0,
+            "examples": [
+              1
+            ]
           }
-        },
-        "file_path": {
-          "$id": "#/properties/rmr/properties/file_path",
-          "type": "string",
-          "title": "The File_path Schema",
-          "default": "",
-          "examples": [
-            "/tmp/routeinfo/routes.txt"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "contents": {
-          "$id": "#/properties/rmr/properties/contents",
-          "type": "string",
-          "title": "The Contents Schema",
-          "default": "",
-          "examples": [
-            "newrt|start\nrte|0|localhost:4560\nrte|2|localhost:4591\nrte|10002|localhost:4560\nrte|10005|localhost:4560\nrte|10003|localhost:4591\nrte|12010|localhost:4591\nrte|12020|localhost:4591\nrte|12011|localhost:4560\nrte|12012|localhost:4560\nrte|12021|localhost:4560\nrte|12022|localhost:4560\nrte|20000|localhost:4560\nrte|20001|localhost:4566\nnewrt|end "
-          ],
-          "pattern": "^(.*)$"
-        }
-      }
-    },
-    "envs": {
-      "$id": "#/properties/envs",
-      "type": "object",
-      "title": "The Envs Schema",
-      "required": [
-        "gNodeB",
-        "THREADS",
-        "A1_SCHEMA_FILE",
-        "VES_SCHEMA_FILE",
-        "SAMPLE_FILE",
-        "VES_COLLECTOR_URL",
-        "VES_MEAUSUREMENT_INTERVAL"
-      ],
-      "properties": {
-        "gNodeB": {
-          "$id": "#/properties/envs/properties/gNodeB",
-          "type": "string",
-          "title": "The Gnodeb Schema",
-          "default": "",
-          "examples": [
-            "NYC123"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "THREADS": {
-          "$id": "#/properties/envs/properties/THREADS",
-          "type": "string",
-          "title": "The Threads Schema",
-          "default": "",
-          "examples": [
-            "1"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "A1_SCHEMA_FILE": {
-          "$id": "#/properties/envs/properties/A1_SCHEMA_FILE",
-          "type": "string",
-          "title": "The A1_schema_file Schema",
-          "default": "",
-          "examples": [
-            "/etc/xapp/adm-ctrl-xapp-schema.json"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "VES_SCHEMA_FILE": {
-          "$id": "#/properties/envs/properties/VES_SCHEMA_FILE",
-          "type": "string",
-          "title": "The Ves_schema_file Schema",
-          "default": "",
-          "examples": [
-            "/etc/xapp/ves_schema.json"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "SAMPLE_FILE": {
-          "$id": "#/properties/envs/properties/SAMPLE_FILE",
-          "type": "string",
-          "title": "The Sample_file Schema",
-          "default": "",
-          "examples": [
-            "/etc/xapp/samples.json"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "VES_COLLECTOR_URL": {
-          "$id": "#/properties/envs/properties/VES_COLLECTOR_URL",
-          "type": "string",
-          "title": "The Ves_collector_url Schema",
-          "default": "",
-          "examples": [
-            "127.0.0.1:6350"
-          ],
-          "pattern": "^(.*)$"
-        },
-        "VES_MEAUSUREMENT_INTERVAL": {
-          "$id": "#/properties/envs/properties/VES_MEAUSUREMENT_INTERVAL",
-          "type": "string",
-          "title": "The Ves_meausurement_interval Schema",
-          "default": "",
-          "examples": [
-            "10"
-          ],
-          "pattern": "^(.*)$"
         }
       }
     }
   }
-}
-
+  
+  
\ No newline at end of file