Skip to content

Commit

Permalink
Merge branch 'develop' into depandabot
Browse files Browse the repository at this point in the history
  • Loading branch information
prkhrkat authored Nov 14, 2024
2 parents 927b79b + 4a6540d commit 31dc299
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
17 changes: 0 additions & 17 deletions pkg/module/ModuleCacheService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}

Expand Down
24 changes: 17 additions & 7 deletions pkg/server/ServerCacheService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -63,33 +73,33 @@ 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
}

// 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
}
21 changes: 19 additions & 2 deletions pkg/server/ServerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,40 @@ 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,
serverDataStore: serverDataStore,
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,
Expand Down
37 changes: 19 additions & 18 deletions pkg/server/config/ServerEnvConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31dc299

Please sign in to comment.