Skip to content

Commit 7e0215f

Browse files
authored
Merge pull request #6546 from devtron-labs/feat-file-variable-cm-mount-main
feat: mount file type variable in ci-runner through cm
2 parents a796c8a + 428168c commit 7e0215f

22 files changed

+503
-281
lines changed

api/bean/ConfigMapAndSecret.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ type ConfigSecretMap struct {
5757
SubPath bool `json:"subPath"`
5858
ESOSubPath []string `json:"esoSubPath"`
5959
FilePermission string `json:"filePermission"`
60+
ConfigSecretMapEnt
6061
}
6162

62-
func (configSecret ConfigSecretMap) GetDataMap() (map[string]string, error) {
63-
var datamap map[string]string
64-
err := json.Unmarshal(configSecret.Data, &datamap)
65-
return datamap, err
63+
func (configSecret *ConfigSecretMap) GetDataMap() (map[string]string, error) {
64+
if len(configSecret.Data) == 0 {
65+
return make(map[string]string), nil
66+
}
67+
var dataMap map[string]string
68+
err := json.Unmarshal(configSecret.Data, &dataMap)
69+
return dataMap, err
6670
}
67-
func (configSecretJson ConfigSecretJson) GetDereferencedSecrets() []ConfigSecretMap {
71+
72+
func (configSecretJson *ConfigSecretJson) GetDereferencedSecrets() []ConfigSecretMap {
6873
return sliceUtil.GetDeReferencedSlice(configSecretJson.Secrets)
6974
}
7075

@@ -95,3 +100,14 @@ func GetTransformedDataForSecretRootJsonData(data string, mode util.SecretTransf
95100
}
96101
return string(marshal), nil
97102
}
103+
104+
type ConfigType string
105+
106+
func (c ConfigType) String() string {
107+
return string(c)
108+
}
109+
110+
const (
111+
ConfigMap ConfigType = "cm"
112+
Secret ConfigType = "cs"
113+
)

api/bean/ConfigMapAndSecret_ent.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bean
18+
19+
type ConfigSecretMapEnt struct {
20+
}
21+
22+
func (configSecret *ConfigSecretMap) AddDataToKey(keyName string, data []byte) (*ConfigSecretMap, error) {
23+
return configSecret, nil
24+
}
25+
26+
func (configSecret *ConfigSecretMap) GetBinaryDataMap() map[string][]byte {
27+
return nil
28+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ require (
307307

308308
replace (
309309
github.com/argoproj/argo-workflows/v3 v3.5.13 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
310-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250425083942-5092ec30954c
311-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250425083942-5092ec30954c
310+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250502103233-29d5c52295e4
311+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250502103233-29d5c52295e4
312312
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
313313
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
314314
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
829829
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
830830
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
831831
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
832-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250425083942-5092ec30954c h1:UZq25z5WE7MQZAXe6uvM/xNektllueo4mz4l4943raU=
833-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250425083942-5092ec30954c/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250425083942-5092ec30954c h1:lIIGAMWM4UwSwrd5Ljm1x4vtNRm1s0q2mTqdQWX8L6Q=
835-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250425083942-5092ec30954c/go.mod h1:zkNShlkcHxsmnL0gKNbs0uyRL8lZonGKr5Km63uTLI0=
832+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250502103233-29d5c52295e4 h1:FZ3z1sbg2qyconeuDSJKsku56gTKtKsEeodagDIpQq8=
833+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250502103233-29d5c52295e4/go.mod h1:FfaLDXN1ZXxyRpnskBqVIYkpkWDCzBmDgIO9xqLnxdQ=
834+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250502103233-29d5c52295e4 h1:Y66AO2dPjzFC+AbEkaHP3jGV15x9X4ALfDVZ1SNs/e4=
835+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250502103233-29d5c52295e4/go.mod h1:zkNShlkcHxsmnL0gKNbs0uyRL8lZonGKr5Km63uTLI0=
836836
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
837837
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
838838
github.com/devtron-labs/protos v0.0.3-0.20250323220609-ecf8a0f7305e h1:U6UdYbW8a7xn5IzFPd8cywjVVPfutGJCudjePAfL/Hs=

pkg/deployment/trigger/devtronApps/preStageHandlerCode.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
2424
blob_storage "github.com/devtron-labs/common-lib/blob-storage"
2525
commonBean "github.com/devtron-labs/common-lib/workflow"
26-
bean2 "github.com/devtron-labs/devtron/api/bean"
26+
apiBean "github.com/devtron-labs/devtron/api/bean"
2727
gitSensorClient "github.com/devtron-labs/devtron/client/gitSensor"
2828
constants2 "github.com/devtron-labs/devtron/internal/sql/constants"
2929
"github.com/devtron-labs/devtron/internal/sql/repository"
@@ -62,7 +62,7 @@ import (
6262
)
6363

6464
func (impl *HandlerServiceImpl) TriggerPreStage(request bean.TriggerRequest) (*bean6.ManifestPushTemplate, error) {
65-
request.WorkflowType = bean2.CD_WORKFLOW_TYPE_PRE
65+
request.WorkflowType = apiBean.CD_WORKFLOW_TYPE_PRE
6666
// setting triggeredAt variable to have consistent data for various audit log places in db for deployment time
6767
triggeredAt := time.Now()
6868
triggeredBy := request.TriggeredBy
@@ -219,7 +219,7 @@ func (impl *HandlerServiceImpl) TriggerAutoCDOnPreStageSuccess(triggerContext be
219219
func (impl *HandlerServiceImpl) checkDeploymentTriggeredAlready(wfId int) bool {
220220
deploymentTriggeredAlready := false
221221
// TODO : need to check this logic for status check in case of multiple deployments requirement for same workflow
222-
workflowRunner, err := impl.cdWorkflowRepository.FindByWorkflowIdAndRunnerType(context.Background(), wfId, bean2.CD_WORKFLOW_TYPE_DEPLOY)
222+
workflowRunner, err := impl.cdWorkflowRepository.FindByWorkflowIdAndRunnerType(context.Background(), wfId, apiBean.CD_WORKFLOW_TYPE_DEPLOY)
223223
if err != nil {
224224
impl.logger.Errorw("error occurred while fetching workflow runner", "wfId", wfId, "err", err)
225225
return deploymentTriggeredAlready
@@ -236,7 +236,7 @@ func (impl *HandlerServiceImpl) createStartingWfAndRunner(request bean.TriggerRe
236236
//in case of pre stage manual trigger auth is already applied and for auto triggers there is no need for auth check here
237237
cdWf := request.CdWf
238238
var err error
239-
if cdWf == nil && request.WorkflowType == bean2.CD_WORKFLOW_TYPE_PRE {
239+
if cdWf == nil && request.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
240240
cdWf = &pipelineConfig.CdWorkflow{
241241
CiArtifactId: artifact.Id,
242242
PipelineId: pipeline.Id,
@@ -279,9 +279,9 @@ func (impl *HandlerServiceImpl) getEnvAndNsIfRunStageInEnv(ctx context.Context,
279279
var err error
280280
namespace := impl.config.GetDefaultNamespace()
281281
runStageInEnv := false
282-
if workflowStage == bean2.CD_WORKFLOW_TYPE_PRE {
282+
if workflowStage == apiBean.CD_WORKFLOW_TYPE_PRE {
283283
runStageInEnv = pipeline.RunPreStageInEnv
284-
} else if workflowStage == bean2.CD_WORKFLOW_TYPE_POST {
284+
} else if workflowStage == apiBean.CD_WORKFLOW_TYPE_POST {
285285
runStageInEnv = pipeline.RunPostStageInEnv
286286
}
287287
_, span := otel.Tracer("orchestrator").Start(ctx, "envRepository.FindById")
@@ -588,7 +588,7 @@ func (impl *HandlerServiceImpl) buildWFRequest(runner *pipelineConfig.CdWorkflow
588588
}
589589
if pipelineStage != nil {
590590
var variableSnapshot map[string]string
591-
if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_PRE {
591+
if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
592592
// TODO: use const from pipeline.WorkflowService:95
593593
request := pipelineConfigBean.NewBuildPrePostStepDataReq(cdPipeline.Id, "preCD", scope)
594594
prePostAndRefPluginResponse, err := impl.pipelineStageService.BuildPrePostAndRefPluginStepsDataForWfRequest(request)
@@ -599,7 +599,7 @@ func (impl *HandlerServiceImpl) buildWFRequest(runner *pipelineConfig.CdWorkflow
599599
preDeploySteps = prePostAndRefPluginResponse.PreStageSteps
600600
refPluginsData = prePostAndRefPluginResponse.RefPluginData
601601
variableSnapshot = prePostAndRefPluginResponse.VariableSnapshot
602-
} else if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_POST {
602+
} else if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_POST {
603603
// TODO: use const from pipeline.WorkflowService:96
604604
request := pipelineConfigBean.NewBuildPrePostStepDataReq(cdPipeline.Id, "postCD", scope)
605605
prePostAndRefPluginResponse, err := impl.pipelineStageService.BuildPrePostAndRefPluginStepsDataForWfRequest(request)
@@ -630,9 +630,9 @@ func (impl *HandlerServiceImpl) buildWFRequest(runner *pipelineConfig.CdWorkflow
630630
}
631631
} else {
632632
//in this case no plugin script is not present for this cdPipeline hence going with attaching preStage or postStage config
633-
if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_PRE {
633+
if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
634634
stageYaml = cdPipeline.PreStageConfig
635-
} else if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_POST {
635+
} else if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_POST {
636636
stageYaml = cdPipeline.PostStageConfig
637637
deployStageWfr, deployStageTriggeredByUserEmail, pipelineReleaseCounter, err = impl.getDeployStageDetails(cdPipeline.Id)
638638
if err != nil {
@@ -813,11 +813,11 @@ func (impl *HandlerServiceImpl) buildWFRequest(runner *pipelineConfig.CdWorkflow
813813
// For Pre-CD / Post-CD workflow, cache is not uploaded; hence no need to set cache bucket
814814
cdWorkflowConfigCdCacheBucket := ""
815815

816-
if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_PRE {
816+
if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_PRE {
817817
// populate input variables of steps with extra env variables
818818
setExtraEnvVariableInDeployStep(preDeploySteps, runtimeParams.GetSystemVariables(), webhookAndCiData)
819819
cdStageWorkflowRequest.PrePostDeploySteps = preDeploySteps
820-
} else if runner.WorkflowType == bean2.CD_WORKFLOW_TYPE_POST {
820+
} else if runner.WorkflowType == apiBean.CD_WORKFLOW_TYPE_POST {
821821
// populate input variables of steps with extra env variables
822822
setExtraEnvVariableInDeployStep(postDeploySteps, runtimeParams.GetSystemVariables(), webhookAndCiData)
823823
cdStageWorkflowRequest.PrePostDeploySteps = postDeploySteps
@@ -1007,7 +1007,7 @@ func setExtraEnvVariableInDeployStep(deploySteps []*pipelineConfigBean.StepObjec
10071007
func (impl *HandlerServiceImpl) getDeployStageDetails(pipelineId int) (pipelineConfig.CdWorkflowRunner, string, int, error) {
10081008
deployStageWfr := pipelineConfig.CdWorkflowRunner{}
10091009
//getting deployment pipeline latest wfr by pipelineId
1010-
deployStageWfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, bean2.CD_WORKFLOW_TYPE_DEPLOY)
1010+
deployStageWfr, err := impl.cdWorkflowRepository.FindLatestByPipelineIdAndRunnerType(pipelineId, apiBean.CD_WORKFLOW_TYPE_DEPLOY)
10111011
if err != nil {
10121012
impl.logger.Errorw("error in getting latest status of deploy type wfr by pipelineId", "err", err, "pipelineId", pipelineId)
10131013
return deployStageWfr, "", 0, err
@@ -1046,14 +1046,14 @@ func ReplaceImageTagWithDigest(image, digest string) string {
10461046
}
10471047

10481048
func (impl *HandlerServiceImpl) sendPreStageNotification(ctx context.Context, cdWf *pipelineConfig.CdWorkflow, pipeline *pipelineConfig.Pipeline) error {
1049-
wfr, err := impl.cdWorkflowRepository.FindByWorkflowIdAndRunnerType(ctx, cdWf.Id, bean2.CD_WORKFLOW_TYPE_PRE)
1049+
wfr, err := impl.cdWorkflowRepository.FindByWorkflowIdAndRunnerType(ctx, cdWf.Id, apiBean.CD_WORKFLOW_TYPE_PRE)
10501050
if err != nil {
10511051
return err
10521052
}
10531053

10541054
event, _ := impl.eventFactory.Build(util2.Trigger, &pipeline.Id, pipeline.AppId, &pipeline.EnvironmentId, util2.CD)
10551055
impl.logger.Debugw("event PreStageTrigger", "event", event)
1056-
event = impl.eventFactory.BuildExtraCDData(event, &wfr, 0, bean2.CD_WORKFLOW_TYPE_PRE)
1056+
event = impl.eventFactory.BuildExtraCDData(event, &wfr, 0, apiBean.CD_WORKFLOW_TYPE_PRE)
10571057
_, span := otel.Tracer("orchestrator").Start(ctx, "eventClient.WriteNotificationEvent")
10581058
_, evtErr := impl.eventClient.WriteNotificationEvent(event)
10591059
span.End()

pkg/executor/WorkflowService.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"encoding/json"
2222
"errors"
23-
"fmt"
2423
v1alpha12 "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
2524
"github.com/argoproj/argo-workflows/v3/workflow/util"
2625
"github.com/devtron-labs/common-lib/utils"
@@ -324,23 +323,16 @@ func (impl *WorkflowServiceImpl) prepareCmCsForWorkflowTemplate(workflowRequest
324323
return nil, nil, err
325324
}
326325
allowAll := workflowRequest.IsDevtronJob() || workflowRequest.IsDevtronCI()
327-
namePrefix := workflowRequest.GetExistingCmCsNamePrefix()
328326
for _, cm := range workflowConfigMaps {
329327
// HERE we are allowing all existingSecrets in case of JOB/ BUILD Infra
330328
if _, ok := pipelineLevelConfigMaps[cm.Name]; ok || allowAll {
331-
if !cm.External {
332-
cm.Name = fmt.Sprintf("%s-cm-%s", cm.Name, namePrefix)
333-
}
334-
modifiedWorkflowConfigMaps = append(modifiedWorkflowConfigMaps, cm)
329+
modifiedWorkflowConfigMaps = append(modifiedWorkflowConfigMaps, workflowRequest.ModifyConfigSecretMap(cm, bean.ConfigMap))
335330
}
336331
}
337332
for _, secret := range workflowSecrets {
338333
// HERE we are allowing all existingSecrets in case of JOB/ BUILD Infra
339334
if _, ok := pipelineLevelSecrets[secret.Name]; ok || allowAll {
340-
if !secret.External {
341-
secret.Name = fmt.Sprintf("%s-cs-%s", secret.Name, namePrefix)
342-
}
343-
modifiedWorkflowSecrets = append(modifiedWorkflowSecrets, secret)
335+
modifiedWorkflowSecrets = append(modifiedWorkflowSecrets, workflowRequest.ModifyConfigSecretMap(secret, bean.Secret))
344336
}
345337
}
346338
return modifiedWorkflowConfigMaps, modifiedWorkflowSecrets, nil

pkg/pipeline/ArgoWorkflowExecutor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func TestExecuteWorkflow(t *testing.T) {
7575
secretKeySecret := s3Artifact.SecretKeySecret
7676
assert.NotNil(t, accessKeySecret)
7777
assert.NotNil(t, secretKeySecret)
78-
assert.True(t, reflect.DeepEqual(accessKeySecret, executors.ACCESS_KEY_SELECTOR))
79-
assert.True(t, reflect.DeepEqual(secretKeySecret, executors.SECRET_KEY_SELECTOR))
78+
assert.True(t, reflect.DeepEqual(accessKeySecret, executors.AccessKeySelector))
79+
assert.True(t, reflect.DeepEqual(secretKeySecret, executors.SecretKeySelector))
8080
})
8181

8282
t.Run("validate s3 blob storage with endpoint", func(t *testing.T) {
@@ -105,7 +105,7 @@ func TestExecuteWorkflow(t *testing.T) {
105105
assert.Equal(t, gcpBlobStorage.LogBucketName, gcsArtifact.Bucket)
106106
secretKeySecret := gcsArtifact.ServiceAccountKeySecret
107107
assert.NotNil(t, secretKeySecret)
108-
assert.True(t, reflect.DeepEqual(secretKeySecret, executors.SECRET_KEY_SELECTOR))
108+
assert.True(t, reflect.DeepEqual(secretKeySecret, executors.SecretKeySelector))
109109
})
110110
t.Run("validate env specific cm and secret", func(t *testing.T) {
111111
workflowTemplate := getBaseWorkflowTemplate(cdConfig)

pkg/pipeline/PipelineStageService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,14 +1985,14 @@ func (impl *PipelineStageServiceImpl) buildPipelineStepDataForWfRequest(step *re
19851985

19861986
func (impl *PipelineStageServiceImpl) buildVariableAndConditionDataForWfRequest(stepId int) (*bean.VariableAndConditionDataForStep, error) {
19871987
variableAndConditionData := bean.NewVariableAndConditionDataForStep()
1988-
//getting all variables in the step
1989-
variables, err := impl.pipelineStageRepository.GetVariablesByStepId(stepId)
1988+
// getting all variables in the step
1989+
stepVariables, err := impl.pipelineStageRepository.GetVariablesByStepId(stepId)
19901990
if err != nil && !util.IsErrNoRows(err) {
19911991
impl.logger.Errorw("error in getting variables by stepId", "err", err, "stepId", stepId)
19921992
return variableAndConditionData, err
19931993
}
19941994
variableNameIdMap := make(map[int]string)
1995-
for _, variable := range variables {
1995+
for _, variable := range stepVariables {
19961996
variableNameIdMap[variable.Id] = variable.Name
19971997
// getting format
19981998
// ignoring error as it is already validated in func validatePipelineStageStepVariableForTrigger

0 commit comments

Comments
 (0)