From: subhash kumar singh Date: Fri, 18 Nov 2022 12:05:59 +0000 (+0000) Subject: Implement uninstall of xApp X-Git-Tag: 2.0.0~5 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=c39ef838fcfa6fd30e0c70a6f4a2abcc4a25643d;p=ric-plt%2Fricdms.git Implement uninstall of xApp Implemtend delete api for xApp deployment. Signed-off-by: subhash kumar singh Change-Id: I9c8e64984a3924d39a617fa7dbe6c310646ebbda --- diff --git a/api/ric-dms-api-2.0.yaml b/api/ric-dms-api-2.0.yaml index 24cfc6e..f9e8434 100644 --- a/api/ric-dms-api-2.0.yaml +++ b/api/ric-dms-api-2.0.yaml @@ -194,7 +194,7 @@ paths: description: successful un-deploy xApp schema: type: object - '501': + '500': description: un-deployment failed schema: $ref: '#/definitions/error_message' diff --git a/pkg/deploy/deployment_manager.go b/pkg/deploy/deployment_manager.go index 8d55b9e..fdc2259 100644 --- a/pkg/deploy/deployment_manager.go +++ b/pkg/deploy/deployment_manager.go @@ -24,6 +24,7 @@ import ( "fmt" "io" "os" + "strings" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms" "helm.sh/helm/v3/pkg/action" @@ -42,7 +43,9 @@ const ( ) func NewDeploymentManager() IDeploy { - return &DeploymentManager{} + return &DeploymentManager{ + settings: cli.New(), + } } func (d *DeploymentManager) install(chartPath, appName, version, namesapce string) error { @@ -55,7 +58,7 @@ func (d *DeploymentManager) install(chartPath, appName, version, namesapce strin } install := action.NewInstall(&conf) - install.ReleaseName = fmt.Sprintf(RELESE_NAME_FORMAT, appName, version) + install.ReleaseName = fmt.Sprintf(RELESE_NAME_FORMAT, appName, strings.ReplaceAll(version, ".", "")) install.Namespace = namesapce cp, err := install.ChartPathOptions.LocateChart(chartPath, d.settings) @@ -111,3 +114,25 @@ func (d *DeploymentManager) Deploy(reader io.ReadCloser, appname, version, names } return nil } + +func (d *DeploymentManager) Uninstall(appname, version, namespace string) error { + conf := action.Configuration{} + + err := conf.Init(d.settings.RESTClientGetter(), namespace, os.Getenv(HELM_DRIVER), ricdms.Logger.Debug) + if err != nil { + ricdms.Logger.Error("Not able to prepare uninstall configuration: %v", err) + return err + } + + uninstall := action.NewUninstall(&conf) + uninstall.Wait = true + + resp, err := uninstall.Run(fmt.Sprintf(RELESE_NAME_FORMAT, appname, strings.ReplaceAll(version, ".", ""))) + if err != nil { + ricdms.Logger.Error("Error while uninstalling deployment: %v", err) + return err + } + + ricdms.Logger.Info("deployment uninstallation comlete : %", resp.Info) + return nil +} diff --git a/pkg/deploy/types.go b/pkg/deploy/types.go index 115caca..0078816 100644 --- a/pkg/deploy/types.go +++ b/pkg/deploy/types.go @@ -20,8 +20,11 @@ package deploy -import "io" +import ( + "io" +) type IDeploy interface { Deploy(reader io.ReadCloser, appname, version, namespace string) error + Uninstall(appname, version, namespace string) error } diff --git a/pkg/resthooks/resthooks.go b/pkg/resthooks/resthooks.go index 5940694..7cc8efe 100644 --- a/pkg/resthooks/resthooks.go +++ b/pkg/resthooks/resthooks.go @@ -117,3 +117,14 @@ func (rh *Resthook) DownloadAndInstallChart(appname, version, namespace string) } return dp.NewPostDeployCreated() } + +func (rh *Resthook) UninstallChart(appname, version, namespace string) middleware.Responder { + ricdms.Logger.Debug("Uninstall chart is invoked") + err := rh.DeployMgr.Uninstall(appname, version, namespace) + if err != nil { + ricdms.Logger.Error("Uninstall failed: %v", err) + return dp.NewDeleteDeployInternalServerError() + } + + return dp.NewDeleteDeployCreated() +} diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index 991fbec..7b65f15 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -213,6 +213,13 @@ func TestDownloadAndInstall(t *testing.T) { } +func TestUninstallxApp(t *testing.T) { + response := rh.UninstallChart("test", "test", "test") + if _, ok := response.(*d.DeleteDeployInternalServerError); !ok { + assert.Fail(t, "response type did not match actual: %T", response) + } +} + type HealthCheckerMock struct { mock.Mock }