Skip to content

feat:validation for pipeline Type #4670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e6eb341
Bug(linked ci) : validation added
adi6859 Feb 13, 2024
7f42b03
Bug(linked ci) : sql script added
adi6859 Feb 13, 2024
d3a2bef
Bug(linked ci) : condition check
adi6859 Feb 13, 2024
ad7e9eb
Bug(linked ci) : error handling added
adi6859 Feb 13, 2024
8c325e6
Bug(linked ci) : sql file name updated
adi6859 Feb 13, 2024
661742b
Bug(linked ci) : validation added
adi6859 Feb 14, 2024
fc93d7e
Bug(linked ci) : message changed
adi6859 Feb 14, 2024
7a24161
Merge branch 'main' into bug-linked-ci
adi6859 Feb 19, 2024
6c2ca8f
story (version up) : sql file updated
adi6859 Feb 19, 2024
84266dd
story (version up) : comment added in sql file
adi6859 Feb 19, 2024
e3de8fe
Bug(linked ci) : validation changed
adi6859 Feb 19, 2024
525401f
Bug(linked ci) : validation changed
adi6859 Feb 20, 2024
65792a6
Bug(same image scan detail) : Normal job flag added
adi6859 Feb 21, 2024
2572fd3
Merge branch 'main' into bug-linked-ci
adi6859 Feb 21, 2024
e0d9a37
main merge
adi6859 Apr 12, 2024
ad7b996
Bug(linked ci) : normal job check removed
adi6859 Apr 16, 2024
542a92a
Bug(linked ci) : assets updated
adi6859 Apr 16, 2024
332686f
Bug(linked ci) : normal job added
adi6859 Apr 16, 2024
bee7710
Bug(linked ci) : comment removed
adi6859 Apr 17, 2024
39e2eb4
Merge branch 'main' into bug-linked-ci
adi6859 Apr 19, 2024
109e004
Merge branch 'main' into bug-linked-ci
adi6859 Apr 22, 2024
3764708
Bug(linked ci) : sql file no. updated
adi6859 Apr 22, 2024
829e88a
Merge branch 'main' into bug-linked-ci
adi6859 May 6, 2024
86e0a3b
code commented
adi6859 May 6, 2024
b4c9962
bug(linked ci): sql file updated
adi6859 May 7, 2024
90548f5
bug(linked ci): validation added
adi6859 May 7, 2024
6bea8b9
all comments removed related to bug
adi6859 May 7, 2024
8b58dea
comment added
adi6859 May 7, 2024
48c35e1
logger updated
adi6859 May 7, 2024
e748dff
Merge branch 'main' into bug-linked-ci
adi6859 May 9, 2024
7109f73
code review comment resolved
adi6859 May 9, 2024
f1abd41
error message updated
adi6859 May 10, 2024
655dfc1
Merge branch 'main' into bug-linked-ci
adi6859 May 10, 2024
4515cf0
Merge branch 'main' into bug-linked-ci
adi6859 May 14, 2024
6826685
main merge
adi6859 May 14, 2024
aa33cdd
sql file name changed
adi6859 May 14, 2024
3fad085
Merge branch 'main' into bug-linked-ci
adi6859 May 14, 2024
3ed7b66
sql file no. updated
adi6859 May 14, 2024
0f76bf3
Merge branch 'main' into bug-linked-ci
adi6859 May 15, 2024
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
27 changes: 27 additions & 0 deletions internal/util/ErrorUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ type ApiError struct {
UserDetailMessage string `json:"userDetailMessage,omitempty"`
}

func NewApiError() *ApiError {
return &ApiError{}
}

func (e *ApiError) WithHttpStatusCode(httpStatusCode int) *ApiError {
e.HttpStatusCode = httpStatusCode
return e
}

func (e *ApiError) WithCode(code string) *ApiError {
e.Code = code
return e
}
func (e *ApiError) WithInternalMessage(InternalMessage string) *ApiError {
e.InternalMessage = InternalMessage
return e
}
func (e *ApiError) WithUserMessage(userMessage interface{}) *ApiError {
e.UserMessage = userMessage
return e
}

func (e *ApiError) WithUserDetailMessage(UserDetailMessage string) *ApiError {
e.UserDetailMessage = UserDetailMessage
return e
}

func (e *ApiError) Error() string {
return e.InternalMessage
}
Expand Down
1 change: 0 additions & 1 deletion pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ type ExternalCiConfigRole struct {

// -------------------
type PatchAction int
type PipelineType string

const (
CREATE PatchAction = iota
Expand Down
8 changes: 6 additions & 2 deletions pkg/pipeline/BuildPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ func (impl *CiPipelineConfigServiceImpl) patchCiPipelineUpdateSource(baseCiConfi
impl.logger.Errorw("error in fetching pipeline", "id", modifiedCiPipeline.Id, "err", err)
return nil, err
}

if !modifiedCiPipeline.PipelineType.IsValidPipelineType() {
impl.logger.Debugw(" Invalid PipelineType", "PipelineType", modifiedCiPipeline.PipelineType)
errorMessage := fmt.Sprintf(CiPipeline.PIPELINE_TYPE_IS_NOT_VALID, modifiedCiPipeline.Name)
return nil, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage(errorMessage).WithUserMessage(errorMessage)
}
cannotUpdate := false
for _, material := range pipeline.CiPipelineMaterials {
if material.ScmId != "" {
Expand Down Expand Up @@ -1455,7 +1459,7 @@ func (impl *CiPipelineConfigServiceImpl) GetCiPipelineMin(appId int, envIds []in
var ciPipelineResp []*bean.CiPipelineMin
for _, pipeline := range pipelines {
parentCiPipeline := pipelineConfig.CiPipeline{}
pipelineType := CiPipeline.NORMAL
pipelineType := CiPipeline.CI_BUILD

if pipelineParentCiMap[pipeline.Id] != nil {
parentCiPipeline = *pipelineParentCiMap[pipeline.Id]
Expand Down
10 changes: 8 additions & 2 deletions pkg/pipeline/CiCdPipelineOrchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"fmt"
attributesBean "github.com/devtron-labs/devtron/pkg/attributes/bean"
"golang.org/x/exp/slices"
"net/http"
"path"
"regexp"
"strconv"
Expand Down Expand Up @@ -816,7 +817,6 @@ func (impl CiCdPipelineOrchestratorImpl) CreateCiConf(createRequest *bean.CiConf
}
// Rollback tx on error.
defer tx.Rollback()

ciPipelineObject := &pipelineConfig.CiPipeline{
AppId: createRequest.AppId,
IsManual: ciPipeline.IsManual,
Expand Down Expand Up @@ -2087,7 +2087,13 @@ func (impl CiCdPipelineOrchestratorImpl) CreateEcrRepo(dockerRepository, AWSRegi
}

func (impl CiCdPipelineOrchestratorImpl) AddPipelineToTemplate(createRequest *bean.CiConfigRequest, isSwitchCiPipelineRequest bool) (resp *bean.CiConfigRequest, err error) {

for _, ciPipeline := range createRequest.CiPipelines {
if !ciPipeline.PipelineType.IsValidPipelineType() {
impl.logger.Debugw(" Invalid PipelineType", "ciPipeline.PipelineType", ciPipeline.PipelineType)
errorMessage := fmt.Sprintf(CiPipeline.PIPELINE_TYPE_IS_NOT_VALID, ciPipeline.PipelineType)
return nil, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage(errorMessage).WithUserMessage(errorMessage)
}
}
if createRequest.AppWorkflowId == 0 {
// create workflow
wf := &appWorkflow.AppWorkflow{
Expand Down
4 changes: 1 addition & 3 deletions pkg/pipeline/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ func IsLinkedCD(ci pipelineConfig.CiPipeline) bool {
}

// IsLinkedCI will return if the pipelineConfig.CiPipeline is a Linked CI
// Currently there are inconsistent values present in PipelineType ("CI_EXTERNAL", "LINKED") 207_ci_external.up
// TODO migrate the deprecated values and maintain a consistent PipelineType
func IsLinkedCI(ci pipelineConfig.CiPipeline) bool {
return ci.ParentCiPipeline != 0 &&
(ci.PipelineType == string(CiPipeline.CI_EXTERNAL) || ci.PipelineType == string(CiPipeline.LINKED))
ci.PipelineType == string(CiPipeline.LINKED)
}

// IsCIJob will return if the pipelineConfig.CiPipeline is a CI JOB
Expand Down
22 changes: 15 additions & 7 deletions pkg/pipeline/bean/CiPipeline/CiBuildConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ const Main = "main"
const UniquePlaceHolderForAppName = "$etron"

const PIPELINE_NAME_ALREADY_EXISTS_ERROR = "pipeline name already exist"
const PIPELINE_TYPE_IS_NOT_VALID = "PipelineType is not valid for pipeline %s"

type PipelineType string

const (
NORMAL PipelineType = "NORMAL"
LINKED PipelineType = "LINKED"
// CI_EXTERNAL field is been sent from the dashboard in CreateLinkedCI request and directly gets saved to Database without any validations
CI_EXTERNAL PipelineType = "CI_EXTERNAL" // Deprecated Enum: TODO fix the PipelineTypes in code and database
EXTERNAL PipelineType = "EXTERNAL"
CI_JOB PipelineType = "CI_JOB"
LINKED_CD PipelineType = "LINKED_CD"
CI_BUILD PipelineType = "CI_BUILD"
LINKED PipelineType = "LINKED"
EXTERNAL PipelineType = "EXTERNAL"
CI_JOB PipelineType = "CI_JOB"
LINKED_CD PipelineType = "LINKED_CD"
)

type CiBuildConfigBean struct {
Expand Down Expand Up @@ -58,3 +57,12 @@ type BuildPackConfig struct {
Args map[string]string `json:"args"`
ProjectPath string `json:"projectPath,omitempty"`
}

func (pType PipelineType) IsValidPipelineType() bool {
switch pType {
case CI_BUILD, LINKED, EXTERNAL, CI_JOB, LINKED_CD:
return true
default:
return false
}
}
1 change: 1 addition & 0 deletions scripts/sql/246_pipeline_type.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---- Not Required
6 changes: 6 additions & 0 deletions scripts/sql/246_pipeline_type.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UPDATE "public"."ci_pipeline" SET ci_pipeline_type='LINKED' WHERE ci_pipeline_type='CI_EXTERNAL';

UPDATE "public"."ci_pipeline"
SET ci_pipeline_type = 'CI_BUILD'
FROM app
WHERE ci_pipeline.app_id = app.id AND ci_pipeline.ci_pipeline_type IS NULL AND app.app_type in( 0,2);
Loading