Skip to content
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

fix: wrong registry creds is used in CD stage (PRE/POST) #4717

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/restHandler/CoreAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
ParentCiPipeline: ciPipelineData.ParentCiPipeline,
ParentAppId: ciPipelineData.ParentAppId,
LinkedCount: ciPipelineData.LinkedCount,
PipelineType: bean.PipelineType(ciPipelineData.PipelineType),
PipelineType: bean2.PipelineType(ciPipelineData.PipelineType),
},
}

Expand Down
4 changes: 2 additions & 2 deletions client/cron/CiTriggerCron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
repository2 "github.com/devtron-labs/devtron/internal/sql/repository"
"github.com/devtron-labs/devtron/pkg/bean"
"github.com/devtron-labs/devtron/pkg/pipeline"
bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
pipelineConfigBean "github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/pipeline/repository"
repository3 "github.com/devtron-labs/devtron/pkg/plugin/repository"
cron2 "github.com/devtron-labs/devtron/util/cron"
Expand Down Expand Up @@ -84,7 +84,7 @@ func (impl *CiTriggerCronImpl) TriggerCiCron() {
CiPipelineMaterial: ciPipelineMaterials,
TriggeredBy: 1,
InvalidateCache: false,
PipelineType: bean2.CI_JOB,
PipelineType: string(pipelineConfigBean.CI_JOB),
}
_, err = impl.ciHandler.HandleCIManual(ciTriggerRequest)
if err != nil {
Expand Down
16 changes: 10 additions & 6 deletions internal/sql/repository/CiArtifactRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ type CiArtifact struct {
sql.AuditLog
}

func (c *CiArtifact) IsMigrationRequired() bool {
func (artifact *CiArtifact) IsMigrationRequired() bool {
validDataSourceTypeList := []string{CI_RUNNER, WEBHOOK, PRE_CD, POST_CD, POST_CI, GOCD}
if slices.Contains(validDataSourceTypeList, c.DataSource) {
if slices.Contains(validDataSourceTypeList, artifact.DataSource) {
return false
}
return true
}

func (artifact *CiArtifact) IsRegistryCredentialMapped() bool {
return artifact.CredentialsSourceType == GLOBAL_CONTAINER_REGISTRY
}

type CiArtifactRepository interface {
Save(artifact *CiArtifact) error
Delete(artifact *CiArtifact) error
Expand Down Expand Up @@ -502,12 +506,12 @@ func (impl CiArtifactRepositoryImpl) GetArtifactsByCDPipelineAndRunnerType(cdPip
}

// return map of gitUrl:hash
func (info *CiArtifact) ParseMaterialInfo() (map[string]string, error) {
if info.DataSource != GOCD && info.DataSource != CI_RUNNER && info.DataSource != WEBHOOK && info.DataSource != EXT {
return nil, fmt.Errorf("datasource: %s not supported", info.DataSource)
func (artifact *CiArtifact) ParseMaterialInfo() (map[string]string, error) {
if artifact.DataSource != GOCD && artifact.DataSource != CI_RUNNER && artifact.DataSource != WEBHOOK && artifact.DataSource != EXT {
return nil, fmt.Errorf("datasource: %s not supported", artifact.DataSource)
}
var ciMaterials []*CiMaterialInfo
err := json.Unmarshal([]byte(info.MaterialInfo), &ciMaterials)
err := json.Unmarshal([]byte(artifact.MaterialInfo), &ciMaterials)
scmMap := map[string]string{}
for _, material := range ciMaterials {
var url string
Expand Down
14 changes: 14 additions & 0 deletions internal/sql/repository/pipelineConfig/CiPipelineRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ type CiPipelineRepository interface {
FindByIdIncludingInActive(id int) (pipeline *CiPipeline, err error)
//find non deleted pipeline
FindById(id int) (pipeline *CiPipeline, err error)
// FindOneWithAppData is to be used for fetching minimum data (including app.App) for CiPipeline for the given CiPipeline.Id
FindOneWithAppData(id int) (pipeline *CiPipeline, err error)
FindCiEnvMappingByCiPipelineId(ciPipelineId int) (*CiEnvMapping, error)
FindParentCiPipelineMapByAppId(appId int) ([]*CiPipeline, []int, error)
FindByCiAndAppDetailsById(pipelineId int) (pipeline *CiPipeline, err error)
Expand Down Expand Up @@ -325,6 +327,18 @@ func (impl CiPipelineRepositoryImpl) FindById(id int) (pipeline *CiPipeline, err

return pipeline, err
}

// FindOneWithAppData is to be used for fetching minimum data (including app.App) for CiPipeline for the given CiPipeline.Id
func (impl CiPipelineRepositoryImpl) FindOneWithAppData(id int) (pipeline *CiPipeline, err error) {
pipeline = &CiPipeline{}
err = impl.dbConnection.Model(pipeline).
Column("ci_pipeline.*", "App").
Where("ci_pipeline.id= ?", id).
Where("ci_pipeline.deleted =? ", false).
Select()

return pipeline, err
}
func (impl CiPipelineRepositoryImpl) FindCiEnvMappingByCiPipelineId(ciPipelineId int) (*CiEnvMapping, error) {
ciEnvMapping := &CiEnvMapping{}
err := impl.dbConnection.Model(ciEnvMapping).
Expand Down
38 changes: 15 additions & 23 deletions pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type CiPipeline struct {
BeforeDockerBuildScripts []*CiScript `json:"beforeDockerBuildScripts,omitempty" validate:"dive"`
AfterDockerBuildScripts []*CiScript `json:"afterDockerBuildScripts,omitempty" validate:"dive"`
LinkedCount int `json:"linkedCount"`
PipelineType PipelineType `json:"pipelineType,omitempty"`
PipelineType bean.PipelineType `json:"pipelineType,omitempty"`
ScanEnabled bool `json:"scanEnabled,notnull"`
AppWorkflowId int `json:"appWorkflowId,omitempty"`
PreBuildStage *bean.PipelineStageDto `json:"preBuildStage,omitempty"`
Expand All @@ -138,14 +138,14 @@ type DockerConfigOverride struct {
}

type CiPipelineMin struct {
Name string `json:"name,omitempty" validate:"name-component,max=100"` //name suffix of corresponding pipeline. required, unique, validation corresponding to gocd pipelineName will be applicable
Id int `json:"id,omitempty" `
Version string `json:"version,omitempty"` //matchIf token version in gocd . used for update request
IsExternal bool `json:"isExternal,omitempty"`
ParentCiPipeline int `json:"parentCiPipeline"`
ParentAppId int `json:"parentAppId"`
PipelineType PipelineType `json:"pipelineType,omitempty"`
ScanEnabled bool `json:"scanEnabled,notnull"`
Name string `json:"name,omitempty" validate:"name-component,max=100"` //name suffix of corresponding pipeline. required, unique, validation corresponding to gocd pipelineName will be applicable
Id int `json:"id,omitempty" `
Version string `json:"version,omitempty"` //matchIf token version in gocd . used for update request
IsExternal bool `json:"isExternal,omitempty"`
ParentCiPipeline int `json:"parentCiPipeline"`
ParentAppId int `json:"parentAppId"`
PipelineType bean.PipelineType `json:"pipelineType,omitempty"`
ScanEnabled bool `json:"scanEnabled,notnull"`
}

type CiScript struct {
Expand Down Expand Up @@ -189,14 +189,6 @@ const (
//DEACTIVATE //pause/deactivate this pipeline
)

const (
NORMAL PipelineType = "NORMAL"
LINKED PipelineType = "LINKED"
EXTERNAL PipelineType = "EXTERNAL"
CI_JOB PipelineType = "CI_JOB"
LINKED_CD PipelineType = "LINKED_CD"
)

const (
CASCADE_DELETE int = iota
NON_CASCADE_DELETE
Expand Down Expand Up @@ -286,12 +278,12 @@ type CiPatchRequest struct {
IsJob bool `json:"-"`
IsCloneJob bool `json:"isCloneJob,omitempty"`

ParentCDPipeline int `json:"parentCDPipeline"`
DeployEnvId int `json:"deployEnvId"`
SwitchFromCiPipelineId int `json:"switchFromCiPipelineId"`
SwitchFromExternalCiPipelineId int `json:"switchFromExternalCiPipelineId"`
SwitchFromCiPipelineType PipelineType `json:"-"`
SwitchToCiPipelineType PipelineType `json:"-"`
ParentCDPipeline int `json:"parentCDPipeline"`
DeployEnvId int `json:"deployEnvId"`
SwitchFromCiPipelineId int `json:"switchFromCiPipelineId"`
SwitchFromExternalCiPipelineId int `json:"switchFromExternalCiPipelineId"`
SwitchFromCiPipelineType bean.PipelineType `json:"-"`
SwitchToCiPipelineType bean.PipelineType `json:"-"`
}

func (ciPatchRequest CiPatchRequest) IsSwitchCiPipelineRequest() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (impl *TriggerServiceImpl) TriggerPostStage(request bean.TriggerRequest) er
}
return fmt.Errorf("found vulnerability for image digest %s", cdWf.CiArtifact.ImageDigest)
}

cdStageWorkflowRequest, err := impl.buildWFRequest(runner, cdWf, pipeline, triggeredBy)
if err != nil {
impl.logger.Errorw("error in building wfRequest", "err", err, "runner", runner, "cdWf", cdWf, "pipeline", pipeline)
Expand Down