Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 18 additions & 2 deletions pkg/appStore/chartGroup/ChartGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type ChartGroupServiceImpl struct {
chartGroupDeploymentRepository repository2.ChartGroupDeploymentRepository
installedAppRepository repository.InstalledAppRepository
appStoreVersionValuesRepository appStoreValuesRepository.AppStoreVersionValuesRepository
appStoreRepository appStoreDiscoverRepository.AppStoreRepository
userAuthService user.UserAuthService
appStoreApplicationVersionRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository
environmentService cluster2.EnvironmentService
Expand All @@ -86,6 +87,7 @@ func NewChartGroupServiceImpl(logger *zap.SugaredLogger,
chartGroupDeploymentRepository repository2.ChartGroupDeploymentRepository,
installedAppRepository repository.InstalledAppRepository,
appStoreVersionValuesRepository appStoreValuesRepository.AppStoreVersionValuesRepository,
appStoreRepository appStoreDiscoverRepository.AppStoreRepository,
userAuthService user.UserAuthService,
appStoreApplicationVersionRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository,
environmentService cluster2.EnvironmentService,
Expand Down Expand Up @@ -773,11 +775,25 @@ func (impl *ChartGroupServiceImpl) DeployDefaultChartOnCluster(bean *cluster2.Cl
chartGroupInstallRequest.UserId = userId
var chartGroupInstallChartRequests []*ChartGroupInstallChartRequest
for _, item := range charts.ChartComponent {
appStoreApplicationVersionId, err := impl.appStoreApplicationVersionRepository.FindLatestAppStoreVersionIdByAppStoreName(item.Name)
appStore, err := impl.appStoreRepository.FindAppStoreByName(item.Name)
if err != nil {
impl.logger.Errorw("DeployDefaultChartOnCluster, error in getting app store", "data", t, "err", err)
impl.logger.Errorw("error in getting app store by name", "appStoreName", item.Name, "err", err)
return false, err
}
var appStoreApplicationVersionId int
if len(appStore.DockerArtifactStoreId) > 0 {
appStoreApplicationVersionId, err = impl.appStoreApplicationVersionRepository.FindLatestVersionByAppStoreIdForOCIRepo(appStore.Id)
if err != nil {
impl.logger.Errorw("DeployDefaultChartOnCluster, error in getting app store", "data", t, "err", err)
return false, err
}
} else {
appStoreApplicationVersionId, err = impl.appStoreApplicationVersionRepository.FindLatestVersionByAppStoreIdForChartRepo(appStore.Id)
if err != nil {
impl.logger.Errorw("DeployDefaultChartOnCluster, error in getting app store", "data", t, "err", err)
return false, err
}
}
chartGroupInstallChartRequest := &ChartGroupInstallChartRequest{
AppName: fmt.Sprintf("%d-%d-%s", bean.Id, env.Id, item.Name),
EnvironmentId: env.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type AppStoreApplicationVersionRepository interface {
FindChartVersionByAppStoreId(id int) ([]*AppStoreApplicationVersion, error)
FindByIds(ids []int) ([]*AppStoreApplicationVersion, error)
GetChartInfoById(id int) (*AppStoreApplicationVersion, error)
FindLatestAppStoreVersionIdByAppStoreName(name string) (int, error)
FindLatestVersionByAppStoreIdForChartRepo(id int) (int, error)
FindLatestVersionByAppStoreIdForOCIRepo(id int) (int, error)
SearchAppStoreChartByName(chartName string) ([]*appStoreBean.ChartRepoSearch, error)
}

Expand Down Expand Up @@ -99,32 +100,39 @@ func updateFindWithFilterQuery(filter *appStoreBean.AppStoreFilter, updateAction
}
}

latestAppStoreVersionQuery := " SELECT MAX(asv.id) as id " +
latestAppStoreVersionQueryForChartRepo := " SELECT MAX(created) as created " +
" FROM app_store_application_version asv " +
" INNER JOIN app_store aps ON (asv.app_store_id = aps.id and aps.active = true) " +
" INNER JOIN app_store aps ON (asv.app_store_id = aps.id and aps.active = true and aps.chart_repo_id is NOT NULL) " +
" GROUP BY asv.app_store_id "

latestAppStoreVersionQueryForOCIRepo := " SELECT MAX(asv.id) as id " +
" FROM app_store_application_version asv " +
" INNER JOIN app_store aps ON (asv.app_store_id = aps.id and aps.active = true and aps.docker_artifact_store_id is NOT NULL) " +
" GROUP BY asv.app_store_id "

combinedWhereClause := fmt.Sprintf("( (asv.created IN (%s) and aps.chart_repo_id is not null ) or (asv.id IN (%s) and aps.docker_artifact_store_id is not null) )", latestAppStoreVersionQueryForChartRepo, latestAppStoreVersionQueryForOCIRepo)

if updateAction == QUERY_JOIN_UPDTAE {
if len(filter.ChartRepoId) > 0 && len(filter.RegistryId) > 0 {
query = " LEFT JOIN chart_repo ch ON (aps.chart_repo_id = ch.id and ch.deleted IS FALSE)" +
" LEFT JOIN docker_artifact_store das ON aps.docker_artifact_store_id = das.id" +
" LEFT JOIN oci_registry_config oci ON oci.docker_artifact_store_id = das.id" +
fmt.Sprintf(" WHERE (asv.id IN (%s) AND (ch.active IS TRUE OR (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)))", latestAppStoreVersionQuery) +
fmt.Sprintf(" WHERE ( (%s) AND (ch.active IS TRUE OR (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)))", combinedWhereClause) +
" AND (ch.id IN (?) OR das.id IN (?))"
} else if len(filter.RegistryId) > 0 {
query = " LEFT JOIN docker_artifact_store das ON aps.docker_artifact_store_id = das.id" +
" LEFT JOIN oci_registry_config oci ON oci.docker_artifact_store_id = das.id" +
fmt.Sprintf(" WHERE asv.id IN (%s) AND (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)", latestAppStoreVersionQuery) +
fmt.Sprintf(" WHERE asv.id IN (%s) AND (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)", latestAppStoreVersionQueryForOCIRepo) +
" AND das.id IN (?)"
} else if len(filter.ChartRepoId) > 0 {
query = " LEFT JOIN chart_repo ch ON (aps.chart_repo_id = ch.id and ch.deleted IS FALSE)" +
fmt.Sprintf(" WHERE asv.id IN (%s) AND ch.active IS TRUE", latestAppStoreVersionQuery) +
fmt.Sprintf(" WHERE asv.created IN (%s) AND ch.active IS TRUE", latestAppStoreVersionQueryForChartRepo) +
" AND ch.id IN (?)"
} else {
query = " LEFT JOIN chart_repo ch ON (aps.chart_repo_id = ch.id and ch.deleted IS FALSE)" +
" LEFT JOIN docker_artifact_store das ON aps.docker_artifact_store_id = das.id" +
" LEFT JOIN oci_registry_config oci ON oci.docker_artifact_store_id = das.id" +
fmt.Sprintf(" WHERE (asv.id IN (%s) AND (ch.active IS TRUE OR (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)))", latestAppStoreVersionQuery)
fmt.Sprintf(" WHERE (%s AND (ch.active IS TRUE OR (das.active IS TRUE AND oci.deleted IS FALSE AND oci.is_chart_pull_active IS TRUE)))", combinedWhereClause)
}
}
return query
Expand Down Expand Up @@ -227,10 +235,17 @@ func (impl AppStoreApplicationVersionRepositoryImpl) FindVersionsByAppStoreId(id
return appStoreApplicationVersions, err
}

func (impl *AppStoreApplicationVersionRepositoryImpl) FindLatestAppStoreVersionIdByAppStoreName(name string) (int, error) {
func (impl *AppStoreApplicationVersionRepositoryImpl) FindLatestVersionByAppStoreIdForChartRepo(id int) (int, error) {
var appStoreApplicationVersionId int
queryTemp := "SELECT asv.id AS app_store_application_version_id FROM app_store_application_version AS asv JOIN app_store AS ap ON asv.app_store_id = ap.id WHERE ap.id = ? order by created desc limit 1;"
_, err := impl.dbConnection.Query(&appStoreApplicationVersionId, queryTemp, id)
return appStoreApplicationVersionId, err
}

func (impl *AppStoreApplicationVersionRepositoryImpl) FindLatestVersionByAppStoreIdForOCIRepo(id int) (int, error) {
var appStoreApplicationVersionId int
queryTemp := "SELECT MAX(asv.id) AS app_store_application_version_id FROM app_store_application_version AS asv JOIN app_store AS ap ON asv.app_store_id = ap.id WHERE ap.name = ?;"
_, err := impl.dbConnection.Query(&appStoreApplicationVersionId, queryTemp, name)
queryTemp := "SELECT MAX(asv.id) AS app_store_application_version_id FROM app_store_application_version AS asv JOIN app_store AS ap ON asv.app_store_id = ap.id WHERE ap.id = ?;"
_, err := impl.dbConnection.Query(&appStoreApplicationVersionId, queryTemp, id)
return appStoreApplicationVersionId, err
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/appStore/discover/repository/AppStoreRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"time"
)

type AppStoreRepository interface{}
type AppStoreRepository interface {
FindAppStoreByName(name string) (*AppStore, error)
}

type AppStoreRepositoryImpl struct {
dbConnection *pg.DB
Expand All @@ -48,3 +50,9 @@ type AppStore struct {
ChartRepo *chartRepoRepository.ChartRepo
DockerArtifactStore *dockerArtifactStoreRegistry.DockerArtifactStore
}

func (impl *AppStoreRepositoryImpl) FindAppStoreByName(name string) (*AppStore, error) {
var AppStore AppStore
err := impl.dbConnection.Model(&AppStore).Where("name = ? ", name).Limit(1).Select()
return &AppStore, err
}
5 changes: 3 additions & 2 deletions wire_gen.go

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