"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 {
conf := action.Configuration{}
- err := conf.Init(d.settings.RESTClientGetter(), "namespace", os.Getenv(HELM_DRIVER), ricdms.Logger.Debug)
+ err := conf.Init(d.settings.RESTClientGetter(), namesapce, os.Getenv(HELM_DRIVER), ricdms.Logger.Debug)
if err != nil {
ricdms.Logger.Error("not able to prepare install configuration: %v", err)
}
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
+}