Skip to content

Commit

Permalink
createDownwardAPIVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
prkhrkat committed Dec 20, 2024
1 parent edd184a commit a6821af
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 16 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect

replace (
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.10
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241216110450-9f2f2d5a0281
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241216110450-9f2f2d5a0281
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241220103339-f61a1734c0f4
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241220103339-f61a1734c0f4
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
k8s.io/api => k8s.io/api v0.29.7
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/devtron-labs/argo-workflows/v3 v3.5.10 h1:6rxQOesOzDz6SgQCMDQNHaehsKFW3C7U8CZeEek5kgQ=
github.com/devtron-labs/argo-workflows/v3 v3.5.10/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241216110450-9f2f2d5a0281 h1:UX4HklNLOH7nuTRJQGes3H2T3XgdA+mqoC0+ENfDPAI=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241216110450-9f2f2d5a0281/go.mod h1:vFJ3M7akwAWCtugDXRW+5Q9P+cp0RiH+K/D5FBbb/JA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241216110450-9f2f2d5a0281 h1:BuvKKBLDujIOtWFYjx0XvhWW0weIFZ6mVorA05EswpY=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241216110450-9f2f2d5a0281/go.mod h1:NJSMdv+zTUK3p7rML12RZSeAUKHeLaoY3sR/oK0xhwo=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241220103339-f61a1734c0f4 h1:rUpKHFiDOl8LHgWqFeFTHTcEUChwwbZTKVTZl7fyN0A=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241220103339-f61a1734c0f4/go.mod h1:vFJ3M7akwAWCtugDXRW+5Q9P+cp0RiH+K/D5FBbb/JA=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241220103339-f61a1734c0f4 h1:c4ubgwjt6+HfCwMX7O/JyDiOMMYTg/oAS7jC0zMmjmc=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241220103339-f61a1734c0f4/go.mod h1:NJSMdv+zTUK3p7rML12RZSeAUKHeLaoY3sR/oK0xhwo=
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/WorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W

workflowTemplate.ConfigMaps = workflowConfigMaps
workflowTemplate.Secrets = workflowSecrets
workflowTemplate.Volumes = executors.ExtractVolumesFromCmCs(workflowConfigMaps, workflowSecrets)
workflowTemplate.Volumes = executors.ExtractVolumes(workflowConfigMaps, workflowSecrets)

workflowRequest.AddNodeConstraintsFromConfig(&workflowTemplate, impl.ciCdConfig)
infraConfiguration := &bean4.InfraConfig{}
Expand Down
37 changes: 37 additions & 0 deletions pkg/pipeline/executors/WorkflowUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
v1alpha12 "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
"github.com/devtron-labs/common-lib/utils"
bean2 "github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/internal/sql/repository"
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
Expand All @@ -34,6 +35,17 @@ import (

var ArgoWorkflowOwnerRef = v1.OwnerReference{APIVersion: "argoproj.io/v1alpha1", Kind: "Workflow", Name: "{{workflow.name}}", UID: "{{workflow.uid}}", BlockOwnerDeletion: &[]bool{true}[0]}

func ExtractVolumes(configMaps []bean2.ConfigSecretMap, secrets []bean2.ConfigSecretMap) []v12.Volume {
var volumes []v12.Volume
configMapVolumes := ExtractVolumesFromCmCs(configMaps, secrets)
volumes = append(volumes, configMapVolumes...)

// Add downwardAPI volume
downwardAPIVolume := createDownwardAPIVolume()
volumes = append(volumes, downwardAPIVolume)
return volumes
}

func ExtractVolumesFromCmCs(configMaps []bean2.ConfigSecretMap, secrets []bean2.ConfigSecretMap) []v12.Volume {
var volumes []v12.Volume
configMapVolumes := extractVolumesFromConfigSecretMaps(true, configMaps)
Expand All @@ -45,9 +57,34 @@ func ExtractVolumesFromCmCs(configMaps []bean2.ConfigSecretMap, secrets []bean2.
for _, volume := range secretVolumes {
volumes = append(volumes, volume)
}

return volumes
}

func createDownwardAPIVolume() v12.Volume {
return v12.Volume{
Name: utils.DEVTRON_SELF_DOWNWARD_API_VOLUME,
VolumeSource: v12.VolumeSource{
DownwardAPI: &v12.DownwardAPIVolumeSource{
Items: []v12.DownwardAPIVolumeFile{
{
Path: "labels",
FieldRef: &v12.ObjectFieldSelector{
FieldPath: "metadata.labels",
},
},
{
Path: "annotations",
FieldRef: &v12.ObjectFieldSelector{
FieldPath: "metadata.annotations",
},
},
},
},
},
}
}

func extractVolumesFromConfigSecretMaps(isCm bool, configSecretMaps []bean2.ConfigSecretMap) []v12.Volume {
var volumes []v12.Volume
for _, configSecretMap := range configSecretMaps {
Expand Down
9 changes: 8 additions & 1 deletion pkg/pipeline/types/Workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ func (workflowRequest *WorkflowRequest) GetWorkflowMainContainer(config *CiCdCon
TerminationMessagePath: workFlow.GetTerminalLogFilePath(),
Resources: workflowRequest.GetLimitReqCpuMem(config, infraConfigurations),
}
// add volumeMount for downwardAPI volume
workflowMainContainer.VolumeMounts = append(workflowMainContainer.VolumeMounts,
v1.VolumeMount{
Name: utils.DEVTRON_SELF_DOWNWARD_API_VOLUME,
MountPath: utils.DEVTRON_SELF_DOWNWARD_API_VOLUME_PATH,
},
)
if workflowRequest.Type == bean.CI_WORKFLOW_PIPELINE_TYPE || workflowRequest.Type == bean.JOB_WORKFLOW_PIPELINE_TYPE {
workflowMainContainer.Ports = []v1.ContainerPort{{
// exposed for user specific data from ci container
Expand Down Expand Up @@ -547,7 +554,7 @@ func (workflowRequest *WorkflowRequest) updateVolumeMountsForCi(config *CiCdConf
return err
}
workflowTemplate.Volumes = append(workflowTemplate.Volumes, volume...)
workflowMainContainer.VolumeMounts = volumeMounts
workflowMainContainer.VolumeMounts = append(workflowMainContainer.VolumeMounts, volumeMounts...)
return nil
}

Expand Down

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

8 changes: 4 additions & 4 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ github.com/davecgh/go-spew/spew
# github.com/deckarep/golang-set v1.8.0
## explicit; go 1.17
github.com/deckarep/golang-set
# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241216110450-9f2f2d5a0281
# github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241220103339-f61a1734c0f4
## explicit; go 1.21
github.com/devtron-labs/authenticator/apiToken
github.com/devtron-labs/authenticator/client
github.com/devtron-labs/authenticator/jwt
github.com/devtron-labs/authenticator/middleware
github.com/devtron-labs/authenticator/oidc
github.com/devtron-labs/authenticator/password
# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241216110450-9f2f2d5a0281
# github.com/devtron-labs/common-lib v0.18.1-0.20241001061923-eda545dc839e => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241220103339-f61a1734c0f4
## explicit; go 1.21
github.com/devtron-labs/common-lib/async
github.com/devtron-labs/common-lib/blob-storage
Expand Down Expand Up @@ -2213,8 +2213,8 @@ xorm.io/xorm/log
xorm.io/xorm/names
xorm.io/xorm/schemas
xorm.io/xorm/tags
# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241216110450-9f2f2d5a0281
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241216110450-9f2f2d5a0281
# github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20241220103339-f61a1734c0f4
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241220103339-f61a1734c0f4
# github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
# github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
# k8s.io/api => k8s.io/api v0.29.7
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 a6821af

Please sign in to comment.