"fmt"
"io"
"os"
+ "strings"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
"helm.sh/helm/v3/pkg/action"
)
func NewDeploymentManager() IDeploy {
- return &DeploymentManager{}
+ return &DeploymentManager{
+ settings: cli.New(),
+ }
}
func (d *DeploymentManager) install(chartPath, appName, version, namesapce string) error {
}
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)
}
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
+}
}
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()
+}
}
+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
}