Skip to content

Commit 4174f9c

Browse files
committed
fix
1 parent c8b3943 commit 4174f9c

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

pkg/pipeline/WorkflowService.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ func (impl *WorkflowServiceImpl) createWorkflowTemplate(workflowRequest *types.W
165165
impl.Logger.Errorw("error occurred while getting workflow main container", "err", err)
166166
return bean3.WorkflowTemplate{}, err
167167
}
168-
// if anyone wants to add extra labels in workflow template then leverage below func.
169-
workflowRequest.AddExtraLabelsInWorkflowTemplate()
170168
workflowTemplate.Containers = []v12.Container{workflowMainContainer}
171169
impl.updateBlobStorageConfig(workflowRequest, &workflowTemplate)
172170
if workflowRequest.Type == bean3.CI_WORKFLOW_PIPELINE_TYPE || workflowRequest.Type == bean3.JOB_WORKFLOW_PIPELINE_TYPE {

pkg/pipeline/bean/WorkflowTemplate.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ type WorkflowTemplate struct {
5050
}
5151

5252
const (
53-
CI_WORKFLOW_NAME = "ci"
54-
CI_WORKFLOW_WITH_STAGES = "ci-stages-with-env"
55-
CiStage = "CI"
56-
JobStage = "JOB"
57-
CdStage = "CD"
58-
CD_WORKFLOW_NAME = "cd"
59-
CD_WORKFLOW_WITH_STAGES = "cd-stages-with-env"
53+
CI_WORKFLOW_NAME = "ci"
54+
CI_WORKFLOW_WITH_STAGES = "ci-stages-with-env"
55+
CiStage = "CI"
56+
JobStage = "JOB"
57+
CdStage = "CD"
58+
CD_WORKFLOW_NAME = "cd"
59+
CD_WORKFLOW_WITH_STAGES = "cd-stages-with-env"
60+
WorkflowGenerateNamePrefix = "devtron.ai/generate-name-prefix"
6061
)
6162

6263
func (workflowTemplate *WorkflowTemplate) GetEntrypoint() string {
@@ -72,17 +73,20 @@ func (workflowTemplate *WorkflowTemplate) GetEntrypoint() string {
7273

7374
func (workflowTemplate *WorkflowTemplate) CreateObjectMetadata() *v12.ObjectMeta {
7475

76+
workflowLabels := map[string]string{WorkflowGenerateNamePrefix: workflowTemplate.WorkflowNamePrefix}
7577
switch workflowTemplate.WorkflowType {
7678
case CI_WORKFLOW_NAME:
79+
workflowLabels["devtron.ai/workflow-purpose"] = "ci"
7780
return &v12.ObjectMeta{
7881
GenerateName: workflowTemplate.WorkflowNamePrefix + "-",
79-
Labels: map[string]string{"devtron.ai/workflow-purpose": "ci"},
82+
Labels: workflowLabels,
8083
}
8184
case CD_WORKFLOW_NAME:
85+
workflowLabels["devtron.ai/workflow-purpose"] = "cd"
8286
return &v12.ObjectMeta{
8387
GenerateName: workflowTemplate.WorkflowNamePrefix + "-",
8488
Annotations: map[string]string{"workflows.argoproj.io/controller-instanceid": workflowTemplate.WfControllerInstanceID},
85-
Labels: map[string]string{"devtron.ai/workflow-purpose": "cd"},
89+
Labels: workflowLabels,
8690
}
8791
default:
8892
return nil

pkg/pipeline/executors/ArgoWorkflowExecutor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (impl *ArgoWorkflowExecutorImpl) TerminateDanglingWorkflow(workflowGenerate
9797
impl.logger.Errorw("cannot build wf client", "workflowGenerateName", workflowGenerateName, "err", err)
9898
return err
9999
}
100-
jobSelectorLabel := fmt.Sprintf("%s=%s", types.WorkflowGenerateNamePrefix, workflowGenerateName)
100+
jobSelectorLabel := fmt.Sprintf("%s=%s", bean.WorkflowGenerateNamePrefix, workflowGenerateName)
101101
wfList, err := wfClient.List(context.Background(), v1.ListOptions{LabelSelector: jobSelectorLabel})
102102
if err != nil {
103103
impl.logger.Errorw("error in fetching list of workflows", "namespace", namespace, "err", err)

pkg/pipeline/executors/SystemWorkflowExecutor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (impl *SystemWorkflowExecutorImpl) TerminateDanglingWorkflow(workflowGenera
120120
impl.logger.Errorw("error occurred while creating k8s client", "workflowGenerateName", workflowGenerateName, "namespace", namespace, "err", err)
121121
return err
122122
}
123-
jobSelectorLabel := fmt.Sprintf("%s=%s", types2.WorkflowGenerateNamePrefix, workflowGenerateName)
123+
jobSelectorLabel := fmt.Sprintf("%s=%s", bean.WorkflowGenerateNamePrefix, workflowGenerateName)
124124
jobList, err := clientset.BatchV1().Jobs(namespace).List(context.Background(), v12.ListOptions{LabelSelector: jobSelectorLabel})
125125
if err != nil {
126126
impl.logger.Errorw("error occurred while fetching jobs list for terminating dangling workflows", "namespace", namespace, "err", err)
@@ -185,8 +185,7 @@ func (impl *SystemWorkflowExecutorImpl) GetWorkflowStatus(workflowName string, n
185185
}
186186

187187
func (impl *SystemWorkflowExecutorImpl) getJobTemplate(workflowTemplate bean.WorkflowTemplate) *v1.Job {
188-
189-
workflowLabels := map[string]string{DEVTRON_WORKFLOW_LABEL_KEY: DEVTRON_WORKFLOW_LABEL_VALUE, "devtron.ai/purpose": "workflow", "workflowType": workflowTemplate.WorkflowType}
188+
workflowLabels := GetWorkflowLabelsForSystemExecutor(workflowTemplate)
190189

191190
//setting TerminationGracePeriodSeconds in PodSpec
192191
//which ensures Pod has enough time to execute cleanup on SIGTERM event

pkg/pipeline/executors/WorkflowUtils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,12 @@ func CheckIfReTriggerRequired(status, message, workflowRunnerStatus string) bool
256256

257257
const WorkflowCancel = "CANCELLED"
258258
const POD_DELETED_MESSAGE = "pod deleted"
259+
260+
func GetWorkflowLabelsForSystemExecutor(workflowTemplate bean.WorkflowTemplate) map[string]string {
261+
return map[string]string{
262+
DEVTRON_WORKFLOW_LABEL_KEY: DEVTRON_WORKFLOW_LABEL_VALUE,
263+
"devtron.ai/purpose": "workflow",
264+
"workflowType": workflowTemplate.WorkflowType,
265+
bean.WorkflowGenerateNamePrefix: workflowTemplate.WorkflowNamePrefix,
266+
}
267+
}

pkg/pipeline/types/Workflow.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ type WorkflowRequest struct {
151151
HostUrl string `json:"hostUrl"`
152152
}
153153

154-
func (workflowRequest *WorkflowRequest) AddExtraLabelsInWorkflowTemplate() {
155-
workflowRequest.AppLabels[WorkflowGenerateNamePrefix] = workflowRequest.WorkflowNamePrefix
156-
}
157-
158154
func (workflowRequest *WorkflowRequest) updateExternalRunMetadata() {
159155
pipeline := workflowRequest.Pipeline
160156
env := workflowRequest.Env
@@ -598,7 +594,6 @@ const (
598594
POST = "POST"
599595
CI_NODE_PVC_ALL_ENV = "devtron.ai/ci-pvc-all"
600596
CI_NODE_PVC_PIPELINE_PREFIX = "devtron.ai/ci-pvc"
601-
WorkflowGenerateNamePrefix = "devtron.ai/generate-name-prefix"
602597
)
603598

604599
type CiArtifactDTO struct {

0 commit comments

Comments
 (0)