Skip to content

Commit 31b7637

Browse files
authored
Merge pull request #6666 from devtron-labs/feat-ext-flux-linking
feat: ext flux linking
2 parents c74391c + 02d847e commit 31b7637

File tree

21 files changed

+520
-98
lines changed

21 files changed

+520
-98
lines changed

api/fluxApplication/FluxApplicationRestHandler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.Respo
4545
var clusterIds []int
4646
var err error
4747

48+
noStream := v.Get("noStream") == "true"
49+
4850
//handling when the clusterIds string is empty ,it will not support the
4951
if len(clusterIdString) == 0 {
5052
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds)
@@ -57,7 +59,7 @@ func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.Respo
5759
return
5860
}
5961
handler.logger.Debugw("extracted ClusterIds successfully ", "clusterIds", clusterIds)
60-
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, w)
62+
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, noStream, w)
6163
}
6264

6365
func (handler *FluxApplicationRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) {

api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,11 @@ func (handler *PipelineConfigRestHandlerImpl) ValidateExternalAppLinkRequest(w h
24722472
common.WriteJsonResp(w, err, response, http.StatusOK)
24732473
return
24742474
// handle helm deployment types
2475+
} else if request.DeploymentAppType == util.PIPELINE_DEPLOYMENT_TYPE_FLUX {
2476+
response := handler.pipelineBuilder.ValidateLinkFluxAppRequest(ctx, &request)
2477+
common.WriteJsonResp(w, err, response, http.StatusOK)
2478+
return
2479+
// handle helm deployment types
24752480
}
24762481
common.WriteJsonResp(w, errors.New("invalid deployment app type in request"), nil, http.StatusBadRequest)
24772482
return

client/fluxcd/fluxDeploymentService.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ func (impl *DeploymentServiceImpl) upsertGitRepoSecret(ctx context.Context, flux
135135
"providerId": gitOpsConfig.Provider,
136136
}
137137

138-
namespace := fluxCdSpec.Namespace
138+
namespace := fluxCdSpec.GitRepositoryNamespace
139139
secret := &v1.Secret{
140140
ObjectMeta: metav1.ObjectMeta{
141141
Name: fluxCdSpec.GitOpsSecretName,
142-
Namespace: fluxCdSpec.Namespace,
142+
Namespace: fluxCdSpec.GitRepositoryNamespace,
143143
Labels: labels,
144144
},
145145
Type: v1.SecretTypeBasicAuth,
@@ -223,7 +223,7 @@ func (impl *DeploymentServiceImpl) updateFluxCdApp(ctx context.Context, fluxCdSp
223223
}
224224

225225
func (impl *DeploymentServiceImpl) CreateGitRepository(ctx context.Context, fluxCdSpec bean.FluxCDSpec, secretName string, apiClient client.Client) (*sourcev1.GitRepository, error) {
226-
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.Namespace
226+
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.GitRepositoryNamespace
227227
gitRepo := &sourcev1.GitRepository{
228228
ObjectMeta: metav1.ObjectMeta{
229229
Name: name,
@@ -250,7 +250,7 @@ func (impl *DeploymentServiceImpl) CreateGitRepository(ctx context.Context, flux
250250

251251
func (impl *DeploymentServiceImpl) UpdateGitRepository(ctx context.Context, fluxCdSpec bean.FluxCDSpec,
252252
secretName string, apiClient client.Client) (*sourcev1.GitRepository, error) {
253-
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.Namespace
253+
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.GitRepositoryNamespace
254254
key := types.NamespacedName{Name: name, Namespace: namespace}
255255
existing := &sourcev1.GitRepository{}
256256

@@ -274,7 +274,7 @@ func (impl *DeploymentServiceImpl) UpdateGitRepository(ctx context.Context, flux
274274

275275
func (impl *DeploymentServiceImpl) CreateHelmRelease(ctx context.Context, fluxCdSpec bean.FluxCDSpec,
276276
apiClient client.Client) (*helmv2.HelmRelease, error) {
277-
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.Namespace
277+
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.HelmReleaseNamespace
278278
helmRelease := &helmv2.HelmRelease{
279279
ObjectMeta: metav1.ObjectMeta{
280280
Name: name,
@@ -313,7 +313,7 @@ func (impl *DeploymentServiceImpl) CreateHelmRelease(ctx context.Context, fluxCd
313313

314314
func (impl *DeploymentServiceImpl) UpdateHelmRelease(ctx context.Context, fluxCdSpec bean.FluxCDSpec,
315315
apiClient client.Client) (*helmv2.HelmRelease, error) {
316-
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.Namespace
316+
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.HelmReleaseNamespace
317317
key := types.NamespacedName{Name: name, Namespace: namespace}
318318
existing := &helmv2.HelmRelease{}
319319

@@ -350,7 +350,6 @@ func (impl *DeploymentServiceImpl) UpdateHelmRelease(ctx context.Context, fluxCd
350350
func (impl *DeploymentServiceImpl) DeleteFluxDeploymentApp(ctx context.Context, request *DeploymentAppDeleteRequest) error {
351351
fluxCdSpec := request.DeploymentConfig.ReleaseConfiguration.FluxCDSpec
352352
clusterId := fluxCdSpec.ClusterId
353-
namespace := fluxCdSpec.Namespace
354353
restConfig, err := impl.K8sUtil.GetRestConfigByCluster(request.ClusterConfig)
355354
if err != nil {
356355
impl.logger.Errorw("error in getting rest config", "clusterId", clusterId, "err", err)
@@ -361,7 +360,7 @@ func (impl *DeploymentServiceImpl) DeleteFluxDeploymentApp(ctx context.Context,
361360
impl.logger.Errorw("error in creating k8s client", "clusterId", clusterId, "err", err)
362361
return err
363362
}
364-
name, namespace := fluxCdSpec.GitRepositoryName, fluxCdSpec.Namespace
363+
name, namespace := fluxCdSpec.HelmReleaseName, fluxCdSpec.HelmReleaseNamespace
365364
key := types.NamespacedName{Name: name, Namespace: namespace}
366365

367366
existingHelmRelease := &helmv2.HelmRelease{}
@@ -376,6 +375,7 @@ func (impl *DeploymentServiceImpl) DeleteFluxDeploymentApp(ctx context.Context,
376375
return err
377376
}
378377

378+
key = types.NamespacedName{Name: fluxCdSpec.GitRepositoryName, Namespace: fluxCdSpec.GitRepositoryNamespace}
379379
existingGitRepository := &sourcev1.GitRepository{}
380380
err = apiClient.Get(ctx, key, existingGitRepository)
381381
if err != nil {

cmd/external-app/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

env_gen.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| DEVTRON_CHART_INSTALL_REQUEST_TIMEOUT | int |6 | Context timeout for no gitops concurrent async deployments | | false |
1414
| EXPOSE_CD_METRICS | bool |false | | | false |
1515
| FEATURE_MIGRATE_ARGOCD_APPLICATION_ENABLE | bool |false | enable migration of external argocd application to devtron pipeline | | false |
16+
| FEATURE_MIGRATE_FLUX_APPLICATION_ENABLE | bool |false | enable flux application services | | false |
1617
| FLUX_CD_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME | string |120 | eligible time for checking flux app status periodically and update in db, value is in seconds., default is 120, if wfr is updated within configured time i.e. FLUX_CD_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME then do not include for this cron cycle. | | false |
1718
| HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME | string |120 | eligible time for checking helm app status periodically and update in db, value is in seconds., default is 120, if wfr is updated within configured time i.e. HELM_PIPELINE_STATUS_CHECK_ELIGIBLE_TIME then do not include for this cron cycle. | | false |
1819
| IS_INTERNAL_USE | bool |true | If enabled then cd pipeline and helm apps will not need the deployment app type mandatorily. Couple this flag with HIDE_GITOPS_OR_HELM_OPTION (in Dashborad) and if gitops is configured and allowed for the env, pipeline/ helm app will gitops else no-gitops. | | false |
@@ -25,6 +26,7 @@
2526
| RUN_HELM_INSTALL_IN_ASYNC_MODE_HELM_APPS | bool |false | | | false |
2627
| SHOULD_CHECK_NAMESPACE_ON_CLONE | bool |false | should we check if namespace exists or not while cloning app | | false |
2728
| USE_DEPLOYMENT_CONFIG_DATA | bool |false | use deployment config data from deployment_config table | | true |
29+
| VALIDATE_EXT_APP_CHART_TYPE | bool |false | validate external flux app chart | | false |
2830

2931

3032
## CI_RUNNER Related Environment Variables

pkg/appStore/bean/bean.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ func (chart *InstallAppVersionDTO) GetFluxDeploymentConfig() *bean2.DeploymentCo
283283
Version: bean2.Version,
284284
FluxCDSpec: bean2.FluxCDSpec{
285285
ClusterId: chart.ClusterId,
286-
Namespace: chart.Namespace,
286+
HelmReleaseNamespace: chart.Namespace,
287+
GitRepositoryNamespace: chart.Namespace,
287288
GitRepositoryName: util.BuildDeployedAppName(chart.AppName, chart.EnvironmentName),
288289
HelmReleaseName: util.BuildDeployedAppName(chart.AppName, chart.EnvironmentName),
289290
GitOpsSecretName: fmt.Sprintf("devtron-flux-secret-%d", chart.GitOpsId),

pkg/appStore/installedApp/service/FullMode/InstalledAppDBExtendedService.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
type InstalledAppDBExtendedService interface {
2929
EAMode.InstalledAppDBService
3030
UpdateInstalledAppVersionStatus(application *v1alpha1.Application) (bool, error)
31-
IsGitOpsRepoAlreadyRegistered(repoUrl string) (bool, error)
31+
IsGitOpsRepoAlreadyRegistered(repoUrl string, appId int) (bool, error)
3232
}
3333

3434
type InstalledAppDBExtendedServiceImpl struct {
@@ -91,9 +91,9 @@ func (impl *InstalledAppDBExtendedServiceImpl) UpdateInstalledAppVersionStatus(a
9191
return true, nil
9292
}
9393

94-
func (impl *InstalledAppDBExtendedServiceImpl) IsGitOpsRepoAlreadyRegistered(repoUrl string) (bool, error) {
94+
func (impl *InstalledAppDBExtendedServiceImpl) IsGitOpsRepoAlreadyRegistered(repoUrl string, appId int) (bool, error) {
9595

96-
urlPresent, err := impl.InstalledAppDBServiceImpl.DeploymentConfigService.CheckIfURLAlreadyPresent(repoUrl)
96+
urlPresent, err := impl.InstalledAppDBServiceImpl.DeploymentConfigService.CheckIfURLAlreadyPresent(repoUrl, appId)
9797
if err != nil && !util.IsErrNoRows(err) {
9898
impl.Logger.Errorw("error in checking url in deployment configs", "repoUrl", repoUrl, "err", err)
9999
return false, err
@@ -111,6 +111,9 @@ func (impl *InstalledAppDBExtendedServiceImpl) IsGitOpsRepoAlreadyRegistered(rep
111111
if util.IsErrNoRows(err) {
112112
return false, nil
113113
}
114+
if installedAppModel != nil && installedAppModel.AppId == appId {
115+
return false, nil
116+
}
114117
impl.Logger.Warnw("repository is already in use for helm app", "repoUrl", repoUrl, "appId", installedAppModel.AppId)
115118
return true, nil
116119
}

pkg/chart/ChartService.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type ChartService interface {
7272
ConfigureGitOpsRepoUrlForApp(appId int, repoUrl, chartLocation string, isCustomRepo bool, userId int32) (*bean2.DeploymentConfig, error)
7373

7474
IsGitOpsRepoConfiguredForDevtronApp(appId int) (bool, error)
75-
IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string) (bool, error)
75+
IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string, appId int) (bool, error)
7676

7777
GetDeploymentTemplateDataByAppIdAndCharRefId(appId, chartRefId int) (map[string]interface{}, error)
7878

@@ -1047,9 +1047,9 @@ func (impl *ChartServiceImpl) ConfigureGitOpsRepoUrlForApp(appId int, repoUrl, c
10471047
// return nil
10481048
//}
10491049

1050-
func (impl *ChartServiceImpl) IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string) (bool, error) {
1050+
func (impl *ChartServiceImpl) IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string, appId int) (bool, error) {
10511051

1052-
isURLPresent, err := impl.deploymentConfigService.CheckIfURLAlreadyPresent(gitOpsRepoUrl)
1052+
isURLPresent, err := impl.deploymentConfigService.CheckIfURLAlreadyPresent(gitOpsRepoUrl, appId)
10531053
if err != nil {
10541054
impl.logger.Errorw("error in checking if gitOps repo url is already present", "error", err)
10551055
return false, err
@@ -1065,6 +1065,9 @@ func (impl *ChartServiceImpl) IsGitOpsRepoAlreadyRegistered(gitOpsRepoUrl string
10651065
} else if util.IsErrNoRows(err) {
10661066
return false, nil
10671067
}
1068+
if chartModel != nil && chartModel.AppId == appId {
1069+
return false, nil
1070+
}
10681071
impl.logger.Errorw("repository is already in use for devtron app", "repoUrl", gitOpsRepoUrl, "appId", chartModel.AppId)
10691072
return true, nil
10701073
}

pkg/commonService/CommonBaseService.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (impl *CommonBaseServiceImpl) isGitOpsEnable() (*FeatureGitOpsVariables, er
4646
featureGitOpsFlags := &FeatureGitOpsVariables{
4747
IsFeatureArgoCdMigrationEnabled: impl.globalEnvVariables.DeploymentServiceTypeConfig.IsFeatureMigrateArgoCdApplicationEnable(),
4848
}
49+
if impl.globalEnvVariables.DeploymentServiceTypeConfig.FeatureMigrateFluxApplicationEnable {
50+
featureGitOpsFlags.IsFeatureGitOpsEnabled = true
51+
featureGitOpsFlags.IsFeatureUserDefinedGitOpsEnabled = true
52+
}
4953
argoModule, err := impl.moduleReadService.GetModuleInfoByName(bean.ModuleNameArgoCd)
5054
if err != nil && !errors.Is(err, moduleErr.ModuleNotFoundError) {
5155
impl.logger.Errorw("error in getting argo module", "error", err)

0 commit comments

Comments
 (0)