Skip to content

Commit da8b5d4

Browse files
prakash100198pghildiyalkripanshdevtron
authored
fix: pvc mounted on pods for cache handling (#2912)
* first cut pvc for ci * isPvcMounted flag introduced * cache invalidate and global invalidate handling * cache path made configurable * pvc mounted false * PVC mounted at two new paths for storing build and buildx cache * mnor fix * removed redundant objects from struct * chenged names of env variables for paths * buildx cache path restored after doing POC --------- Co-authored-by: Prashant Ghildiyal <[email protected]> Co-authored-by: Kripansh <[email protected]>
1 parent 81e77eb commit da8b5d4

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

pkg/pipeline/CiConfig.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type CiConfig struct {
7979
CiRunnerDockerMTUValue int `env:"CI_RUNNER_DOCKER_MTU_VALUE" envDefault:"-1"`
8080
IgnoreDockerCacheForCI bool `env:"CI_IGNORE_DOCKER_CACHE"`
8181
VolumeMountsForCiJson string `env:"CI_VOLUME_MOUNTS_JSON"`
82+
BuildPvcCachePath string `env:"PRE_CI_CACHE_PATH" envDefault:"/devtroncd-cache"`
83+
DefaultPvcCachePath string `env:"DOCKER_BUILD_CACHE_PATH" envDefault:"/var/lib/docker"`
84+
BuildxPvcCachePath string `env:"BUILDX_CACHE_PATH" envDefault:"/var/lib/devtron/buildx"`
8285
ClusterConfig *rest.Config
8386
NodeLabel map[string]string
8487
}

pkg/pipeline/CiService.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
480480
CiBuildConfig: ciBuildConfigBean,
481481
CiBuildDockerMtuValue: impl.ciConfig.CiRunnerDockerMTUValue,
482482
IgnoreDockerCachePush: impl.ciConfig.IgnoreDockerCacheForCI,
483-
IgnoreDockerCachePull: impl.ciConfig.IgnoreDockerCacheForCI || trigger.InvalidateCache,
483+
IgnoreDockerCachePull: impl.ciConfig.IgnoreDockerCacheForCI,
484+
CacheInvalidate: trigger.InvalidateCache,
484485
}
485486

486487
if ciWorkflowConfig.LogsBucket == "" {

pkg/pipeline/WorkflowService.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package pipeline
2020
import (
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

4244
type 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

117121
const (
@@ -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

127133
type 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

Comments
 (0)