@@ -20,6 +20,7 @@ package pipeline
2020import (
2121 "context"
2222 "encoding/json"
23+ "fmt"
2324 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
2425 "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
2526 v1alpha12 "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
@@ -37,6 +38,7 @@ import (
3738 "k8s.io/client-go/rest"
3839 "net/url"
3940 "strconv"
41+ "strings"
4042)
4143
4244type WorkflowService interface {
@@ -112,6 +114,8 @@ type WorkflowRequest struct {
112114 CiBuildDockerMtuValue int `json:"ciBuildDockerMtuValue"`
113115 IgnoreDockerCachePush bool `json:"ignoreDockerCachePush"`
114116 IgnoreDockerCachePull bool `json:"ignoreDockerCachePull"`
117+ CacheInvalidate bool `json:"cacheInvalidate"`
118+ IsPvcMounted bool `json:"IsPvcMounted"`
115119}
116120
117121const (
@@ -122,6 +126,8 @@ const (
122126 CI_WORKFLOW_NAME = "ci"
123127 CI_WORKFLOW_WITH_STAGES = "ci-stages-with-env"
124128 CI_NODE_SELECTOR_APP_LABEL_KEY = "devtron.ai/node-selector"
129+ CI_NODE_PVC_ALL_ENV = "devtron.ai/ci-pvc-all"
130+ CI_NODE_PVC_PIPELINE_PREFIX = "devtron.ai/ci-pvc"
125131)
126132
127133type ContainerResources struct {
@@ -194,7 +200,15 @@ func (impl *WorkflowServiceImpl) SubmitWorkflow(workflowRequest *WorkflowRequest
194200 miniCred := []v12.EnvVar {{Name : "AWS_ACCESS_KEY_ID" , Value : impl .ciConfig .BlobStorageS3AccessKey }, {Name : "AWS_SECRET_ACCESS_KEY" , Value : impl .ciConfig .BlobStorageS3SecretKey }}
195201 containerEnvVariables = append (containerEnvVariables , miniCred ... )
196202 }
197-
203+ pvc := appLabels [strings .ToLower (fmt .Sprintf ("%s-%s" , CI_NODE_PVC_PIPELINE_PREFIX , workflowRequest .PipelineName ))]
204+ if len (pvc ) == 0 {
205+ pvc = appLabels [CI_NODE_PVC_ALL_ENV ]
206+ }
207+ if len (pvc ) != 0 {
208+ workflowRequest .IsPvcMounted = true
209+ workflowRequest .IgnoreDockerCachePush = true
210+ workflowRequest .IgnoreDockerCachePull = true
211+ }
198212 ciCdTriggerEvent := CiCdTriggerEvent {
199213 Type : ciEvent ,
200214 CiRequest : workflowRequest ,
@@ -543,6 +557,36 @@ func (impl *WorkflowServiceImpl) SubmitWorkflow(workflowRequest *WorkflowRequest
543557 }
544558 }
545559
560+ // pvc mounting starts
561+ if len (pvc ) != 0 {
562+ buildPvcCachePath := impl .ciConfig .BuildPvcCachePath
563+ buildxPvcCachePath := impl .ciConfig .BuildxPvcCachePath
564+ defaultPvcCachePath := impl .ciConfig .DefaultPvcCachePath
565+
566+ ciTemplate .Volumes = append (ciTemplate .Volumes , v12.Volume {
567+ Name : "root-vol" ,
568+ VolumeSource : v12.VolumeSource {
569+ PersistentVolumeClaim : & v12.PersistentVolumeClaimVolumeSource {
570+ ClaimName : pvc ,
571+ ReadOnly : false ,
572+ },
573+ },
574+ })
575+ ciTemplate .Container .VolumeMounts = append (ciTemplate .Container .VolumeMounts ,
576+ v12.VolumeMount {
577+ Name : "root-vol" ,
578+ MountPath : buildPvcCachePath ,
579+ },
580+ v12.VolumeMount {
581+ Name : "root-vol" ,
582+ MountPath : buildxPvcCachePath ,
583+ },
584+ v12.VolumeMount {
585+ Name : "root-vol" ,
586+ MountPath : defaultPvcCachePath ,
587+ })
588+ }
589+
546590 // node selector
547591 if val , ok := appLabels [CI_NODE_SELECTOR_APP_LABEL_KEY ]; ok {
548592 var nodeSelectors map [string ]string
0 commit comments