diff --git a/pkg/module/ModuleCacheService.go b/pkg/module/ModuleCacheService.go index 76f3a58df55..57f45922d67 100644 --- a/pkg/module/ModuleCacheService.go +++ b/pkg/module/ModuleCacheService.go @@ -77,23 +77,6 @@ func NewModuleCacheServiceImpl(logger *zap.SugaredLogger, K8sUtil *k8s.K8sServic return nil, err } - // if old installation (i.e. project was created more than 1 hour ago then insert rest entries) - teamId := 1 - team, err := teamService.FetchOne(teamId) - if err != nil { - log.Println("Error while getting team.", "teamId", teamId, "err", err) - return nil, err - } - - // insert first release components if this was old release and user installed full mode at that time - if time.Now().After(team.CreatedOn.Add(1 * time.Hour)) { - for _, supportedModuleName := range SupportedModuleNamesListFirstReleaseExcludingCicd { - err = impl.updateModuleToInstalled(supportedModuleName) - if err != nil { - return nil, err - } - } - } } } diff --git a/pkg/server/ServerCacheService.go b/pkg/server/ServerCacheService.go index cfcd43bd6c2..b70d18a4b23 100644 --- a/pkg/server/ServerCacheService.go +++ b/pkg/server/ServerCacheService.go @@ -53,6 +53,16 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve return impl, nil } + err := impl.UpdateServerEnvAndDataStore() + if err != nil { + logger.Errorw("error encountered in updating UpdateServerEnvAndDataStore", "error", err) + return nil, err + } + + return impl, nil +} + +func (impl *ServerCacheServiceImpl) UpdateServerEnvAndDataStore() error { // devtron helm release identifier appIdentifier := bean.AppIdentifier{ ClusterId: 1, @@ -63,7 +73,8 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve // check if the release is installed or not isDevtronHelmReleaseInstalled, err := impl.helmAppService.IsReleaseInstalled(context.Background(), &appIdentifier) if err != nil { - logger.Errorw("not able to check if the devtron helm release exists or not.", "error", err) + impl.logger.Errorw("not able to check if the devtron helm release exists or not.", "error", err) + impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease = err // return nil, err // not returning the error as it will bring down orchestrator } @@ -71,25 +82,24 @@ func NewServerCacheServiceImpl(logger *zap.SugaredLogger, serverEnvConfig *serve // if not installed, treat it as OSS kubectl user // if installed, treat it as OSS helm user and fetch current version if isDevtronHelmReleaseInstalled { - serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssHelm + impl.serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssHelm // fetch current version from helm release releaseInfo, err := impl.helmAppService.GetValuesYaml(context.Background(), &appIdentifier) if err != nil { log.Println("got error in fetching devtron helm release values.", "error", err) - return nil, err + return err } currentVersion := gjson.Get(releaseInfo.GetMergedValues(), impl.serverEnvConfig.DevtronVersionIdentifierInHelmValues).String() if len(currentVersion) == 0 { log.Println("current devtron version found empty") - return nil, err + return err } // store current version in-memory impl.serverDataStore.CurrentVersion = currentVersion } else { - serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssKubectl + impl.serverEnvConfig.DevtronInstallationType = serverBean.DevtronInstallationTypeOssKubectl } - - return impl, nil + return nil } diff --git a/pkg/server/ServerService.go b/pkg/server/ServerService.go index ade41755566..12c278d7efc 100644 --- a/pkg/server/ServerService.go +++ b/pkg/server/ServerService.go @@ -44,10 +44,12 @@ type ServerServiceImpl struct { serverEnvConfig *serverEnvConfig.ServerEnvConfig helmAppService client.HelmAppService moduleRepository moduleRepo.ModuleRepository + serverCacheService *ServerCacheServiceImpl } func NewServerServiceImpl(logger *zap.SugaredLogger, serverActionAuditLogRepository ServerActionAuditLogRepository, - serverDataStore *serverDataStore.ServerDataStore, serverEnvConfig *serverEnvConfig.ServerEnvConfig, helmAppService client.HelmAppService, moduleRepository moduleRepo.ModuleRepository) *ServerServiceImpl { + serverDataStore *serverDataStore.ServerDataStore, serverEnvConfig *serverEnvConfig.ServerEnvConfig, helmAppService client.HelmAppService, moduleRepository moduleRepo.ModuleRepository, + serverCacheService *ServerCacheServiceImpl) *ServerServiceImpl { return &ServerServiceImpl{ logger: logger, serverActionAuditLogRepository: serverActionAuditLogRepository, @@ -55,12 +57,27 @@ func NewServerServiceImpl(logger *zap.SugaredLogger, serverActionAuditLogReposit serverEnvConfig: serverEnvConfig, helmAppService: helmAppService, moduleRepository: moduleRepository, + serverCacheService: serverCacheService, } } func (impl ServerServiceImpl) GetServerInfo(showServerStatus bool) (*serverBean.ServerInfoDto, error) { impl.logger.Debug("getting server info") - + if impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease != nil || impl.serverDataStore.CurrentVersion == "" { + // if on initialisation any error have occurred, have captured that error and retry mechanism is done here, possible scenario is migration did not complete but devtron pod came up so values set would not be correct. + impl.logger.Debug("error encountered on getting devtron helm release, now retrying", "err", impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease) + err := impl.serverCacheService.UpdateServerEnvAndDataStore() + if err != nil || impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease != nil { + var errToReturn error + if err != nil { + errToReturn = err + } else { + errToReturn = impl.serverEnvConfig.ErrorEncounteredOnGettingDevtronHelmRelease + } + impl.logger.Errorw("error encountered in GetServerInfo", "err", errToReturn) + return nil, errToReturn + } + } serverInfoDto := &serverBean.ServerInfoDto{ CurrentVersion: impl.serverDataStore.CurrentVersion, ReleaseName: impl.serverEnvConfig.DevtronHelmReleaseName, diff --git a/pkg/server/config/ServerEnvConfig.go b/pkg/server/config/ServerEnvConfig.go index f1339afacb7..4b4b9083654 100644 --- a/pkg/server/config/ServerEnvConfig.go +++ b/pkg/server/config/ServerEnvConfig.go @@ -22,24 +22,25 @@ import ( ) type ServerEnvConfig struct { - DevtronInstallationType string `env:"DEVTRON_INSTALLATION_TYPE"` - InstallerCrdObjectGroupName string `env:"INSTALLER_CRD_OBJECT_GROUP_NAME" envDefault:"installer.devtron.ai"` - InstallerCrdObjectVersion string `env:"INSTALLER_CRD_OBJECT_VERSION" envDefault:"v1alpha1"` - InstallerCrdObjectResource string `env:"INSTALLER_CRD_OBJECT_RESOURCE" envDefault:"installers"` - InstallerCrdNamespace string `env:"INSTALLER_CRD_NAMESPACE" envDefault:"devtroncd"` - DevtronHelmRepoName string `env:"DEVTRON_HELM_REPO_NAME" envDefault:"devtron"` - DevtronHelmRepoUrl string `env:"DEVTRON_HELM_REPO_URL" envDefault:"https://helm.devtron.ai"` - DevtronHelmReleaseName string `env:"DEVTRON_HELM_RELEASE_NAME" envDefault:"devtron"` - DevtronHelmReleaseNamespace string `env:"DEVTRON_HELM_RELEASE_NAMESPACE" envDefault:"devtroncd"` - DevtronHelmReleaseChartName string `env:"DEVTRON_HELM_RELEASE_CHART_NAME" envDefault:"devtron-operator"` - DevtronVersionIdentifierInHelmValues string `env:"DEVTRON_VERSION_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.release"` - DevtronModulesIdentifierInHelmValues string `env:"DEVTRON_MODULES_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.modules"` - DevtronBomUrl string `env:"DEVTRON_BOM_URL" envDefault:"https://raw.githubusercontent.com/devtron-labs/devtron/%s/charts/devtron/devtron-bom.yaml"` - AppSyncImage string `env:"APP_SYNC_IMAGE" envDefault:"quay.io/devtron/chart-sync:1227622d-132-3775"` - AppSyncServiceAccount string `env:"APP_SYNC_SERVICE_ACCOUNT" envDefault:"chart-sync"` - AppSyncJobResourcesObj string `env:"APP_SYNC_JOB_RESOURCES_OBJ"` - ModuleMetaDataApiUrl string `env:"MODULE_METADATA_API_URL" envDefault:"https://api.devtron.ai/module?name=%s"` - ParallelismLimitForTagProcessing int `env:"PARALLELISM_LIMIT_FOR_TAG_PROCESSING"` + DevtronInstallationType string `env:"DEVTRON_INSTALLATION_TYPE"` + InstallerCrdObjectGroupName string `env:"INSTALLER_CRD_OBJECT_GROUP_NAME" envDefault:"installer.devtron.ai"` + InstallerCrdObjectVersion string `env:"INSTALLER_CRD_OBJECT_VERSION" envDefault:"v1alpha1"` + InstallerCrdObjectResource string `env:"INSTALLER_CRD_OBJECT_RESOURCE" envDefault:"installers"` + InstallerCrdNamespace string `env:"INSTALLER_CRD_NAMESPACE" envDefault:"devtroncd"` + DevtronHelmRepoName string `env:"DEVTRON_HELM_REPO_NAME" envDefault:"devtron"` + DevtronHelmRepoUrl string `env:"DEVTRON_HELM_REPO_URL" envDefault:"https://helm.devtron.ai"` + DevtronHelmReleaseName string `env:"DEVTRON_HELM_RELEASE_NAME" envDefault:"devtron"` + DevtronHelmReleaseNamespace string `env:"DEVTRON_HELM_RELEASE_NAMESPACE" envDefault:"devtroncd"` + DevtronHelmReleaseChartName string `env:"DEVTRON_HELM_RELEASE_CHART_NAME" envDefault:"devtron-operator"` + DevtronVersionIdentifierInHelmValues string `env:"DEVTRON_VERSION_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.release"` + DevtronModulesIdentifierInHelmValues string `env:"DEVTRON_MODULES_IDENTIFIER_IN_HELM_VALUES" envDefault:"installer.modules"` + DevtronBomUrl string `env:"DEVTRON_BOM_URL" envDefault:"https://raw.githubusercontent.com/devtron-labs/devtron/%s/charts/devtron/devtron-bom.yaml"` + AppSyncImage string `env:"APP_SYNC_IMAGE" envDefault:"quay.io/devtron/chart-sync:1227622d-132-3775"` + AppSyncServiceAccount string `env:"APP_SYNC_SERVICE_ACCOUNT" envDefault:"chart-sync"` + AppSyncJobResourcesObj string `env:"APP_SYNC_JOB_RESOURCES_OBJ"` + ModuleMetaDataApiUrl string `env:"MODULE_METADATA_API_URL" envDefault:"https://api.devtron.ai/module?name=%s"` + ParallelismLimitForTagProcessing int `env:"PARALLELISM_LIMIT_FOR_TAG_PROCESSING"` + ErrorEncounteredOnGettingDevtronHelmRelease error } func ParseServerEnvConfig() (*ServerEnvConfig, error) { diff --git a/wire_gen.go b/wire_gen.go index 78a50dcd642..6108358eefc 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -901,7 +901,7 @@ func InitializeApp() (*App, error) { moduleRestHandlerImpl := module2.NewModuleRestHandlerImpl(sugaredLogger, moduleServiceImpl, userServiceImpl, enforcerImpl, validate) moduleRouterImpl := module2.NewModuleRouterImpl(moduleRestHandlerImpl) serverActionAuditLogRepositoryImpl := server.NewServerActionAuditLogRepositoryImpl(db) - serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl) + serverServiceImpl := server.NewServerServiceImpl(sugaredLogger, serverActionAuditLogRepositoryImpl, serverDataStoreServerDataStore, serverEnvConfigServerEnvConfig, helmAppServiceImpl, moduleRepositoryImpl,serverCacheServiceImpl) serverRestHandlerImpl := server2.NewServerRestHandlerImpl(sugaredLogger, serverServiceImpl, userServiceImpl, enforcerImpl, validate) serverRouterImpl := server2.NewServerRouterImpl(serverRestHandlerImpl) apiTokenSecretServiceImpl, err := apiToken.NewApiTokenSecretServiceImpl(sugaredLogger, attributesServiceImpl, apiTokenSecretStore)