Skip to content
24 changes: 19 additions & 5 deletions api/restHandler/DockerRegRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
err = impl.TriggerChartSync(bean)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
return
}
Expand All @@ -268,19 +273,28 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri
return
}
// trigger a chart sync job
err = impl.TriggerChartSync(bean)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (impl DockerRegRestHandlerImpl) TriggerChartSync(bean types.DockerArtifactStoreBean) error {
if bean.IsOCICompliantRegistry && len(bean.RepositoryList) != 0 {
request := &chartProviderService.ChartProviderRequestDto{
Id: bean.Id,
IsOCIRegistry: bean.IsOCICompliantRegistry,
}
err = impl.chartProviderService.SyncChartProvider(request)
err := impl.chartProviderService.SyncChartProvider(request)
if err != nil {
impl.logger.Errorw("service err, SaveDockerRegistryConfig", "err", err, "userId", userId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
impl.logger.Errorw("service err, SaveDockerRegistryConfig", "err", err)
return err
}
}
common.WriteJsonResp(w, err, res, http.StatusOK)
return nil
}

func (impl DockerRegRestHandlerImpl) ValidateDockerRegistryConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (impl *AppStoreApplicationVersionRepositoryImpl) SearchAppStoreChartByName(
" inner join app_store aps on asv.app_store_id = aps.id" +
" left join chart_repo chr on aps.chart_repo_id = chr.id" +
" left join docker_artifact_store das on aps.docker_artifact_store_id = das.id" +
" where aps.name like '%" + chartName + "%' and asv.latest is TRUE order by aps.name asc;"
" where aps.name like '%" + chartName + "%' and asv.latest is TRUE and aps.active=true order by aps.name asc;"
_, err := impl.dbConnection.Query(&chartRepos, queryTemp)
if err != nil {
return nil, err
Expand Down
12 changes: 10 additions & 2 deletions pkg/chartRepo/ChartRepositoryService.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
util3 "github.com/devtron-labs/common-lib/utils/k8s"
"io"
"io/ioutil"
v1 "k8s.io/api/batch/v1"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -712,9 +713,16 @@ func (impl *ChartRepositoryServiceImpl) TriggerChartSyncManual(chartProviderConf

manualAppSyncJobByteArr := manualAppSyncJobByteArr(impl.serverEnvConfig.AppSyncImage, impl.serverEnvConfig.AppSyncJobResourcesObj, chartProviderConfig)

err = impl.K8sUtil.DeleteAndCreateJob(manualAppSyncJobByteArr, impl.aCDAuthConfig.ACDConfigMapNamespace, defaultClusterConfig)
var job v1.Job
err = yaml.Unmarshal(manualAppSyncJobByteArr, &job)
if err != nil {
impl.logger.Errorw("DeleteAndCreateJob err, TriggerChartSyncManual", "err", err)
impl.logger.Errorw("Unmarshal err, CreateJobSafely", "err", err)
return err
}

err = impl.K8sUtil.CreateJob(impl.aCDAuthConfig.ACDConfigMapNamespace, job.Name, defaultClusterConfig, &job)
if err != nil {
impl.logger.Errorw("CreateJob err, CreateJobSafely", "err", err)
return err
}

Expand Down
4 changes: 4 additions & 0 deletions scripts/sql/205_app_store_unique_constraint.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS app_store_unique_oci_repo;
DROP INDEX IF EXISTS app_store_unique_chart_repo;


8 changes: 8 additions & 0 deletions scripts/sql/205_app_store_unique_constraint.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE public.app_store
DROP CONSTRAINT IF EXISTS app_store_unique;
CREATE UNIQUE INDEX IF NOT EXISTS app_store_unique_oci_repo ON public.app_store
(name, docker_artifact_store_id) where active=true;
CREATE UNIQUE INDEX IF NOT EXISTS app_store_unique_chart_repo ON public.app_store
(name, chart_repo_id) where active=true;
CREATE UNIQUE INDEX IF NOT EXISTS app_store_version_unique ON public.app_store_application_version
(app_store_id,name, version) ;