From: hoejoo lee Date: Fri, 19 May 2023 04:19:23 +0000 (+0000) Subject: Revert " helm packaging, add chart_builder" X-Git-Tag: 1.0.0~24^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=f315d341e822b9c2e23fb093d4569d74c916f207;p=aiml-fw%2Faihp%2Fips%2Fkserve-adapter.git Revert " helm packaging, add chart_builder" This reverts commit 59895a6bf5cc6c7af606d669dff3002436d56d01. Reason for revert: naming error Change-Id: Ie0a6792c940e488d599aac69abf37cc56ad4c18e Signed-off-by: hoejoo.lee --- diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 index a2d43a4..9c14461 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ # documentation .tox docs/_build/ -pkg/helm/data/sample-xapp-2.2.0/ -*.tgz -mock*.go diff --git a/config/kserve-adapter.yaml b/config/kserve-adapter.yaml deleted file mode 100755 index d5459ec..0000000 --- a/config/kserve-adapter.yaml +++ /dev/null @@ -1,17 +0,0 @@ -################################################################################ -# Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); # -# you may not use this file except in compliance with the License. # -# You may obtain a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -################################################################################ -"helm": - "retry": 1 diff --git a/main.go b/main.go index 689c324..75c3378 100755 --- a/main.go +++ b/main.go @@ -20,27 +20,18 @@ limitations under the License. package main import ( - "flag" "os" - "github.com/spf13/viper" "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api" "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger" ) -const KSERVE_ADAPTER_CONFIG_FILE = "./config/kserve-adapter.yaml" - var ( apiServerPort string ) func init() { apiServerPort = os.Getenv("API_SERVER_PORT") - - var fileName *string - fileName = flag.String("f", KSERVE_ADAPTER_CONFIG_FILE, "Specify the configuration file.") - flag.Parse() - viper.SetConfigFile(*fileName) } func main() { diff --git a/pkg/helm/chart_builder.go b/pkg/helm/chart_builder.go index 21484e7..3318eb0 100755 --- a/pkg/helm/chart_builder.go +++ b/pkg/helm/chart_builder.go @@ -29,8 +29,6 @@ import ( "github.com/xeipuuv/gojsonschema" "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger" - "github.sec.samsung.net/RANIS/aiml-fw-aihp-ips-kserve-adapter/pkg/util" - "gopkg.in/yaml.v1" ) const ( @@ -85,17 +83,10 @@ func NewChartBuilder(configFile string, schemaFile string) *ChartBuilder { _, err = os.Stat(chartBuilder.chartWorkspacePath) if err != nil { if !os.IsNotExist(err) { - logger.Logging(logger.ERROR, err.Error()) - return nil + os.RemoveAll(chartBuilder.chartWorkspacePath) } } - err = os.RemoveAll(chartBuilder.chartWorkspacePath) - if err != nil { - logger.Logging(logger.ERROR, err.Error()) - return nil - } - err = os.Mkdir(chartBuilder.chartWorkspacePath, os.FileMode(0744)) if err != nil { logger.Logging(logger.ERROR, err.Error()) @@ -205,29 +196,7 @@ func (c *ChartBuilder) copyDirectory(src string, dest string) (err error) { } func (c *ChartBuilder) PackageChart() (err error) { - err = c.appendConfigToValuesYaml() - if err != nil { - return - } - - err = c.changeChartNameVersion() - if err != nil { - return - } - - err = c.helmLint() - if err != nil { - return - } - - output, err := util.HelmExec(fmt.Sprintf("package %s/%s -d %s", c.chartWorkspacePath, c.chartName, c.chartWorkspacePath)) - if err != nil { - logger.Logging(logger.ERROR, "%s-%s helm lint failed (Caused by : %s)", c.chartName, c.chartVersion, err.Error()) - return - } - logger.Logging(logger.INFO, "result of helm lint : %s", string(output)) - - return + return errors.New("not yet implemented") } func (c *ChartBuilder) parseConfigFile(configFile string) (config Config, err error) { @@ -266,65 +235,15 @@ func (c *ChartBuilder) parseSchemaFile(schemaFile string) (schema Schema, err er } func (c *ChartBuilder) helmLint() (err error) { - - output, err := util.HelmExec(fmt.Sprintf("lint %s/%s", c.chartWorkspacePath, c.chartName)) - - if err != nil { - logger.Logging(logger.ERROR, err.Error()) - logger.Logging(logger.ERROR, fmt.Sprintf("%s-%s helm lint failed (Caused by : %s)", c.chartName, c.chartVersion, err)) - } - logger.Logging(logger.INFO, fmt.Sprintf("result of helm lint : %s", string(output))) - return + return errors.New("not yet implemented") } func (c *ChartBuilder) appendConfigToValuesYaml() (err error) { - valueYamlPath := os.Getenv(ENV_CHART_WORKSPACE_PATH) + "/" + c.chartName + "-" + c.chartVersion + "/" + c.chartName + "/" + VALUES_YAML - yamlFile, err := ioutil.ReadFile(valueYamlPath) - if err != nil { - return - } - - data := make(map[interface{}]interface{}) - err = yaml.Unmarshal(yamlFile, &data) - if err != nil { - return - } - - data["engine"] = c.config.InferenceService.Engine - data["storageUri"] = c.config.InferenceService.StorageURI - - //data["resources"] = c.config. - data["max_replicas"] = c.config.InferenceService.MaxReplicas - data["min_replicas"] = c.config.InferenceService.MinReplicas - data["name"] = c.config.XappName - data["fullname"] = c.config.XappName - data["ric_serviceaccount_name"] = c.config.SaName - - ret, err := yaml.Marshal(&data) - if err != nil { - return - } - - err = ioutil.WriteFile(valueYamlPath, ret, os.FileMode(0644)) - if err != nil { - return - } - return + return errors.New("not yet implemented") } func (c *ChartBuilder) changeChartNameVersion() (err error) { - chartYamlPath := os.Getenv(ENV_CHART_WORKSPACE_PATH) + "/" + c.chartName + "/" + CHART_YAML - yamlFile, err := ioutil.ReadFile(chartYamlPath) - - data := make(map[interface{}]interface{}) - err = yaml.Unmarshal(yamlFile, &data) - if err != nil { - return - } - - data["version"] = c.chartVersion - data["name"] = c.chartName - return + return errors.New("not yet implemented") } func (c *ChartBuilder) ValidateChartMaterials() (err error) { diff --git a/pkg/helm/chart_builder_test.go b/pkg/helm/chart_builder_test.go index eabe211..8f47ecd 100755 --- a/pkg/helm/chart_builder_test.go +++ b/pkg/helm/chart_builder_test.go @@ -19,12 +19,10 @@ package helm import ( - "flag" "io/ioutil" "os" "testing" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) @@ -45,17 +43,13 @@ func TestParseSchemaFile(t *testing.T) { } func TestHelmLint(t *testing.T) { - os.Setenv("CHART_WORKSPACE_PATH", "./data") chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json") - err := chartBuilder.appendConfigToValuesYaml() - assert.Nil(t, err) + err := chartBuilder.helmLint() - err = chartBuilder.helmLint() assert.Nil(t, err) } func TestAppendConfigToValuesYaml(t *testing.T) { - os.Setenv("CHART_WORKSPACE_PATH", "./data") chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json") err := chartBuilder.appendConfigToValuesYaml() @@ -64,7 +58,6 @@ func TestAppendConfigToValuesYaml(t *testing.T) { } func TestChangeChartNameVersion(t *testing.T) { - os.Setenv("CHART_WORKSPACE_PATH", "./data") chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json") err := chartBuilder.changeChartNameVersion() @@ -72,21 +65,10 @@ func TestChangeChartNameVersion(t *testing.T) { } func TestPackageChart(t *testing.T) { - - var fileName *string - fileName = flag.String("f", "../../config/kserve-adapter.yaml", "Specify the configuration file.") - flag.Parse() - - viper.SetConfigFile(*fileName) - - os.Setenv("CHART_WORKSPACE_PATH", "./data") chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json") err := chartBuilder.PackageChart() assert.Nil(t, err) - assert.FileExists(t, "./data/sample-xapp-2.2.0/inference-service-1.0.0.tgz") - - defer os.RemoveAll("./data/sample-xapp-2.2.0/inference-service-1.0.0.tgz") } func TestCopyFile(t *testing.T) { @@ -129,12 +111,3 @@ func TestCopyDirectory(t *testing.T) { } } } - -func TestValidateChartMaterials(t *testing.T) { - os.Setenv("CHART_WORKSPACE_PATH", ".") - chartBuilder := NewChartBuilder("data/sample_config.json", "data/sample_schema.json") - err := chartBuilder.ValidateChartMaterials() - defer os.RemoveAll(os.Getenv("CHART_WORKSPACE_PATH") + "/" + chartBuilder.chartName + "-" + chartBuilder.chartVersion) - - assert.Nil(t, err) -} diff --git a/pkg/helm/data/resources/std/Chart.yaml b/pkg/helm/data/resources/std/Chart.yaml index 333e39e..edd6bd7 100755 --- a/pkg/helm/data/resources/std/Chart.yaml +++ b/pkg/helm/data/resources/std/Chart.yaml @@ -1,20 +1,21 @@ -/* -================================================================================== - Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. +# ================================================================================== +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -================================================================================== -*/ apiVersion: v1 appVersion: "1.0" description: Standard Inference Service Helm Chart diff --git a/pkg/helm/data/sample_config.json b/pkg/helm/data/sample_config.json index 00c8579..b665a13 100755 --- a/pkg/helm/data/sample_config.json +++ b/pkg/helm/data/sample_config.json @@ -1,5 +1,5 @@ { - "xapp_name": "sample-xapp", + "xapp_name": "sample_xapp", "xapp_type": "inferenceservice", "version": "2.2.0", "sa_name": "default", diff --git a/pkg/util/util.go b/pkg/util/util.go deleted file mode 100755 index 3269357..0000000 --- a/pkg/util/util.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -================================================================================== - Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -================================================================================== -*/ - -package util - -import ( - "bytes" - "errors" - "fmt" - "os/exec" - "strings" - "time" - - "github.sec.samsung.net/RANIS/aiml-fw-aihp-ips-kserve-adapter/pkg/commons/logger" -) - -func Exec(args string) (out []byte, err error) { - cmd := exec.Command("/bin/sh", "-c", args) - - var stdout bytes.Buffer - var stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - logger.Logging(logger.INFO, fmt.Sprintf("Running command: %s", cmd.Args)) - for i := 0; i < 3; i++ { - if err = cmd.Run(); err != nil { - logger.Logging(logger.ERROR, fmt.Sprintf("Command failed : %v - %s, retrying", err.Error(), stderr.String())) - time.Sleep(time.Duration(2) * time.Second) - continue - } - break - } - - if err == nil { - logger.Logging(logger.INFO, fmt.Sprintf("command success: %s", stdout.String())) - return stdout.Bytes(), nil - } - - return stdout.Bytes(), errors.New(stderr.String()) -} - -var HelmExec = func(args string) (out []byte, err error) { - return Exec(strings.Join([]string{"helm", args}, " ")) -}