Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/pipeline/CiConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type CiConfig struct {
CiRunnerDockerMTUValue int `env:"CI_RUNNER_DOCKER_MTU_VALUE" envDefault:"-1"`
IgnoreDockerCacheForCI bool `env:"CI_IGNORE_DOCKER_CACHE"`
VolumeMountsForCiJson string `env:"CI_VOLUME_MOUNTS_JSON"`
BuildPvcCachePath string `env:"BUILD_PVC_CACHE_PATH" envDefault:"/devtroncd-cache"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename these Params, BUILD_PVC_CACHE_PATH, DEFAULT_PVC_CACHE_PATH, something related to intent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

DefaultPvcCachePath string `env:"DEFAULT_PVC_CACHE_PATH" envDefault:"/var/lib/docker"`
BuildxPvcCachePath string `env:"BUILDX_PVC_CACHE_PATH" envDefault:"/var/lib/devtron/buildx"`
ClusterConfig *rest.Config
NodeLabel map[string]string
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
CiBuildConfig: ciBuildConfigBean,
CiBuildDockerMtuValue: impl.ciConfig.CiRunnerDockerMTUValue,
IgnoreDockerCachePush: impl.ciConfig.IgnoreDockerCacheForCI,
IgnoreDockerCachePull: impl.ciConfig.IgnoreDockerCacheForCI || trigger.InvalidateCache,
IgnoreDockerCachePull: impl.ciConfig.IgnoreDockerCacheForCI,
CacheInvalidate: trigger.InvalidateCache,
}

if ciWorkflowConfig.LogsBucket == "" {
Expand Down
51 changes: 50 additions & 1 deletion pkg/pipeline/WorkflowService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package pipeline
import (
"context"
"encoding/json"
"fmt"
"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"
Expand All @@ -37,6 +38,7 @@ import (
"k8s.io/client-go/rest"
"net/url"
"strconv"
"strings"
)

type WorkflowService interface {
Expand Down Expand Up @@ -112,6 +114,9 @@ type WorkflowRequest struct {
CiBuildDockerMtuValue int `json:"ciBuildDockerMtuValue"`
IgnoreDockerCachePush bool `json:"ignoreDockerCachePush"`
IgnoreDockerCachePull bool `json:"ignoreDockerCachePull"`
CacheInvalidate bool `json:"cacheInvalidate"`
IsPvcMounted bool `json:"IsPvcMounted"`
PvcCachePath string `json:"pvcCachePath"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this flag is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't introduce the flag, but it's not being used anywhere so removed it

}

const (
Expand All @@ -122,6 +127,8 @@ const (
CI_WORKFLOW_NAME = "ci"
CI_WORKFLOW_WITH_STAGES = "ci-stages-with-env"
CI_NODE_SELECTOR_APP_LABEL_KEY = "devtron.ai/node-selector"
CI_NODE_PVC_ALL_ENV = "devtron.ai/ci-pvc-all"
CI_NODE_PVC_PIPELINE_PREFIX = "devtron.ai/ci-pvc"
)

type ContainerResources struct {
Expand Down Expand Up @@ -194,7 +201,18 @@ func (impl *WorkflowServiceImpl) SubmitWorkflow(workflowRequest *WorkflowRequest
miniCred := []v12.EnvVar{{Name: "AWS_ACCESS_KEY_ID", Value: impl.ciConfig.BlobStorageS3AccessKey}, {Name: "AWS_SECRET_ACCESS_KEY", Value: impl.ciConfig.BlobStorageS3SecretKey}}
containerEnvVariables = append(containerEnvVariables, miniCred...)
}

pvc := appLabels[strings.ToLower(fmt.Sprintf("%s-%s", CI_NODE_PVC_PIPELINE_PREFIX, workflowRequest.PipelineName))]
if len(pvc) == 0 {
pvc = appLabels[CI_NODE_PVC_ALL_ENV]
}
if len(pvc) != 0 {
workflowRequest.IsPvcMounted = true
workflowRequest.IgnoreDockerCachePush = true
workflowRequest.IgnoreDockerCachePull = true
}
if impl.ciConfig.IgnoreDockerCacheForCI && workflowRequest.CacheInvalidate {
workflowRequest.IsPvcMounted = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong, whats the intent of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was just doing some checks, didn't need it so removed it

}
ciCdTriggerEvent := CiCdTriggerEvent{
Type: ciEvent,
CiRequest: workflowRequest,
Expand Down Expand Up @@ -543,6 +561,37 @@ func (impl *WorkflowServiceImpl) SubmitWorkflow(workflowRequest *WorkflowRequest
}
}

// pvc mounting starts
if len(pvc) != 0 {
buildPvcCachePath := impl.ciConfig.BuildPvcCachePath
buildxPvcCachePath := impl.ciConfig.BuildxPvcCachePath
defaultPvcCachePath := impl.ciConfig.DefaultPvcCachePath

workflowRequest.PvcCachePath = buildPvcCachePath
ciTemplate.Volumes = append(ciTemplate.Volumes, v12.Volume{
Name: "root-vol",
VolumeSource: v12.VolumeSource{
PersistentVolumeClaim: &v12.PersistentVolumeClaimVolumeSource{
ClaimName: pvc,
ReadOnly: false,
},
},
})
ciTemplate.Container.VolumeMounts = append(ciTemplate.Container.VolumeMounts,
v12.VolumeMount{
Name: "root-vol",
MountPath: buildPvcCachePath,
},
v12.VolumeMount{
Name: "root-vol",
MountPath: buildxPvcCachePath,
},
v12.VolumeMount{
Name: "root-vol",
MountPath: defaultPvcCachePath,
})
}

// node selector
if val, ok := appLabels[CI_NODE_SELECTOR_APP_LABEL_KEY]; ok {
var nodeSelectors map[string]string
Expand Down