Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/module/Bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type ModuleStatus = string
type ModuleName = string

const BlobStorage = "blob-storage"
const INSTALLER_MODULES_HELM_KEY = "installer.modules"

const (
ModuleStatusNotInstalled ModuleStatus = "notInstalled"
Expand Down
25 changes: 15 additions & 10 deletions pkg/module/ModuleCronService.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,22 @@ func (impl *ModuleCronServiceImpl) HandleModuleStatus() {
// timeout case
impl.updateModuleStatus(module, ModuleStatusTimeout)
} else if !util.IsBaseStack() {
// check if helm release is healthy or not
appIdentifier := client.AppIdentifier{
ClusterId: 1,
Namespace: impl.serverEnvConfig.DevtronHelmReleaseNamespace,
ReleaseName: impl.serverEnvConfig.DevtronHelmReleaseName,
}
appDetail, err := impl.helmAppService.GetApplicationDetail(context.Background(), &appIdentifier)
if err != nil {
impl.logger.Errorw("Error occurred while fetching helm application detail to check if module is installed", "moduleName", module.Name, "err", err)
} else if appDetail.ApplicationStatus == serverBean.AppHealthStatusHealthy {
// if module is cicd then insert as installed
if module.Name == ModuleNameCicd {
impl.updateModuleStatus(module, ModuleStatusInstalled)
} else {
// check if helm release is healthy or not for non cicd apps
appIdentifier := client.AppIdentifier{
ClusterId: 1,
Namespace: impl.serverEnvConfig.DevtronHelmReleaseNamespace,
ReleaseName: impl.serverEnvConfig.DevtronHelmReleaseName,
}
appDetail, err := impl.helmAppService.GetApplicationDetail(context.Background(), &appIdentifier)
if err != nil {
impl.logger.Errorw("Error occurred while fetching helm application detail to check if module is installed", "moduleName", module.Name, "err", err)
} else if appDetail.ApplicationStatus == serverBean.AppHealthStatusHealthy {
impl.updateModuleStatus(module, ModuleStatusInstalled)
}
}
}
}
Expand Down
41 changes: 34 additions & 7 deletions pkg/module/ModuleService.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/go-pg/pg"
"github.com/tidwall/gjson"
"go.uber.org/zap"
"reflect"
"time"
)

Expand Down Expand Up @@ -140,9 +141,31 @@ func (impl ModuleServiceImpl) handleModuleNotFoundStatus(moduleName string) (Mod
impl.logger.Errorw("Error in getting values yaml for devtron operator helm release", "moduleName", moduleName, "err", err)
return ModuleStatusNotInstalled, err
}
isEnabled := gjson.Get(releaseInfo.MergedValues, moduleUtil.BuildModuleEnableKey(moduleName)).Bool()
if isEnabled {
return impl.saveModuleAsInstalled(moduleName)
releaseValues := releaseInfo.MergedValues

// if check non-cicd module status
if moduleName != ModuleNameCicd {
isEnabled := gjson.Get(releaseValues, moduleUtil.BuildModuleEnableKey(moduleName)).Bool()
if isEnabled {
return impl.saveModuleAsInstalled(moduleName)
}
} else if util2.IsBaseStack() {
// check if cicd is in installing state
// if devtron is installed with cicd module, then cicd module should be shown as installing
installerModulesIface := gjson.Get(releaseValues, INSTALLER_MODULES_HELM_KEY).Value()
if installerModulesIface != nil {
installerModulesIfaceKind := reflect.TypeOf(installerModulesIface).Kind()
if installerModulesIfaceKind == reflect.Slice {
installerModules := installerModulesIface.([]interface{})
for _, installerModule := range installerModules {
if installerModule == moduleName {
return impl.saveModule(moduleName, ModuleStatusInstalling)
}
}
} else {
impl.logger.Warnw("Invalid installerModulesIfaceKind expected slice", "installerModulesIfaceKind", installerModulesIfaceKind, "val", installerModulesIface)
}
}
}

// if module not enabled in helm for non enterprise-user
Expand Down Expand Up @@ -247,7 +270,7 @@ func (impl ModuleServiceImpl) HandleModuleAction(userId int32, moduleName string

extraValues := make(map[string]interface{})
extraValues["installer.release"] = moduleActionRequest.Version
extraValues["installer.modules"] = []interface{}{moduleName}
extraValues[INSTALLER_MODULES_HELM_KEY] = []interface{}{moduleName}
alreadyInstalledModuleNames, err := impl.moduleRepository.GetInstalledModuleNames()
if err != nil {
impl.logger.Errorw("error in getting modules with installed status ", "err", err)
Expand Down Expand Up @@ -291,16 +314,20 @@ func (impl ModuleServiceImpl) buildModuleMetaDataUrl(moduleName string) string {
}

func (impl ModuleServiceImpl) saveModuleAsInstalled(moduleName string) (ModuleStatus, error) {
return impl.saveModule(moduleName, ModuleStatusInstalled)
}

func (impl ModuleServiceImpl) saveModule(moduleName string, moduleStatus ModuleStatus) (ModuleStatus, error) {
module := &moduleRepo.Module{
Name: moduleName,
Version: impl.serverDataStore.CurrentVersion,
Status: ModuleStatusInstalled,
Status: moduleStatus,
UpdatedOn: time.Now(),
}
err := impl.moduleRepository.Save(module)
if err != nil {
impl.logger.Errorw("error in saving module with installed status ", "moduleName", moduleName, "err", err)
impl.logger.Errorw("error in saving module status ", "moduleName", moduleName, "moduleStatus", moduleStatus, "err", err)
return ModuleStatusNotInstalled, err
}
return ModuleStatusInstalled, nil
return moduleStatus, nil
}