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

chore: removing deprecated function and it's usage #5871

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -1325,17 +1325,16 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsByCDPipeline(w http.Re
return
}
//rbac block ends here
var ciArtifactResponse *bean.CiArtifactResponse
if handler.pipelineRestHandlerEnvConfig.UseArtifactListApiV2 {
artifactsListFilterOptions := &bean2.ArtifactsListFilterOptions{
Limit: limit,
Offset: offset,
SearchString: searchString,
}
ciArtifactResponse, err = handler.pipelineBuilder.RetrieveArtifactsByCDPipelineV2(pipeline, bean2.WorkflowType(stage), artifactsListFilterOptions)
} else {
ciArtifactResponse, err = handler.pipelineBuilder.RetrieveArtifactsByCDPipeline(pipeline, bean2.WorkflowType(stage))
artifactsListFilterOptions := &bean2.ArtifactsListFilterOptions{
Limit: limit,
Offset: offset,
SearchString: searchString,
}

//RetrieveArtifactsByCDPipeline is deprecated and method is removed from code
//ciArtifactResponse, err = handler.pipelineBuilder.RetrieveArtifactsByCDPipeline(pipeline, bean2.WorkflowType(stage))

ciArtifactResponse, err := handler.pipelineBuilder.RetrieveArtifactsByCDPipelineV2(pipeline, bean2.WorkflowType(stage), artifactsListFilterOptions)
if err != nil {
handler.Logger.Errorw("service err, GetArtifactsByCDPipeline", "err", err, "cdPipelineId", cdPipelineId, "stage", stage)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import (
)

type PipelineRestHandlerEnvConfig struct {
UseArtifactListApiV2 bool `env:"USE_ARTIFACT_LISTING_API_V2" envDefault:"true"`
UseArtifactListApiV2 bool `env:"USE_ARTIFACT_LISTING_API_V2" envDefault:"true"` //deprecated
}

type DevtronAppRestHandler interface {
Expand Down
5 changes: 5 additions & 0 deletions internal/sql/repository/CiArtifactRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/devtron-labs/devtron/util"
"golang.org/x/exp/slices"
"strings"
"time"
Expand Down Expand Up @@ -84,6 +85,10 @@ type CiArtifact struct {
sql.AuditLog
}

func (artifact *CiArtifact) ExtractImageRepoAndTag() (repo string, tag string) {
return util.ExtractImageRepoAndTag(artifact.Image)
}

func (artifact *CiArtifact) IsMigrationRequired() bool {
validDataSourceTypeList := []string{CI_RUNNER, WEBHOOK, PRE_CD, POST_CD, POST_CI, GOCD}
if slices.Contains(validDataSourceTypeList, artifact.DataSource) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/bulkAction/BulkUpdateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,12 @@ func (impl BulkUpdateServiceImpl) BulkDeploy(request *BulkApplicationForEnvironm
continue
}

artifactResponse, err := impl.pipelineBuilder.RetrieveArtifactsByCDPipeline(pipeline, bean.CD_WORKFLOW_TYPE_DEPLOY)
artifactsListingFilterOptions := &bean.ArtifactsListFilterOptions{
Limit: 10,
Offset: 0,
SearchString: "",
}
artifactResponse, err := impl.pipelineBuilder.RetrieveArtifactsByCDPipelineV2(pipeline, bean.CD_WORKFLOW_TYPE_DEPLOY, artifactsListingFilterOptions)
if err != nil {
impl.logger.Errorw("service err, GetArtifactsByCDPipeline", "err", err, "cdPipelineId", pipeline.Id)
//return nil, err
Expand Down
17 changes: 3 additions & 14 deletions pkg/deployment/manifest/ManifestCreationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import (
"go.uber.org/zap"
k8sApiV1 "k8s.io/api/core/v1"
"net/http"
"strings"
"time"
)

Expand Down Expand Up @@ -711,18 +710,9 @@ func (impl *ManifestCreationServiceImpl) getReleaseOverride(envOverride *chartCo
imageName := ""
tag := ""
if artifact != nil {
artifactImage := artifact.Image
imageTag := strings.Split(artifactImage, ":")

imageTagLen := len(imageTag)

for i := 0; i < imageTagLen-1; i++ {
if i != imageTagLen-2 {
imageName = imageName + imageTag[i] + ":"
} else {
imageName = imageName + imageTag[i]
}
}
imageName = artifact.Image
_, tag = globalUtil.ExtractImageRepoAndTag(imageName)

digestConfigurationRequest := imageDigestPolicy.DigestPolicyConfigurationRequest{PipelineId: overrideRequest.PipelineId}
digestPolicyConfigurations, err := impl.imageDigestPolicyService.GetDigestPolicyConfigurations(digestConfigurationRequest)
Expand All @@ -732,10 +722,9 @@ func (impl *ManifestCreationServiceImpl) getReleaseOverride(envOverride *chartCo
}

if digestPolicyConfigurations.UseDigestForTrigger() {
imageTag[imageTagLen-1] = fmt.Sprintf("%s@%s", imageTag[imageTagLen-1], artifact.ImageDigest)
tag = fmt.Sprintf("%s@%s", tag, artifact.ImageDigest)
}

tag = imageTag[imageTagLen-1]
}

override, err := app.NewReleaseAttributes(imageName, tag, overrideRequest.PipelineName, deploymentStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ func (impl *TriggerServiceImpl) getDockerTagAndCustomTagIdForPlugin(pipelineStag
customTagId := -1 // if customTag is not configured id=-1 will be saved in image_path_reservation table for image reservation
if !customTag.Enabled {
// case when custom tag is not configured - source image tag will be taken as docker image tag
pluginTriggerImageSplit := strings.Split(artifact.Image, ":")
DockerImageTag = pluginTriggerImageSplit[len(pluginTriggerImageSplit)-1]
_, DockerImageTag = artifact.ExtractImageRepoAndTag()
} else {
// for copyContainerImage plugin parse destination images and save its data in image path reservation table
customTagDbObject, customDockerImageTag, err := impl.customTagService.GetCustomTag(pipelineStageEntityType, strconv.Itoa(pipelineId))
Expand Down
9 changes: 2 additions & 7 deletions pkg/eventProcessor/celEvaluator/WorkFlowTriggerEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/devtron-labs/devtron/pkg/team"
"github.com/go-pg/pg"
"go.uber.org/zap"
"strings"
)

type TriggerEventEvaluator interface {
Expand Down Expand Up @@ -84,12 +83,8 @@ func (impl *TriggerEventEvaluatorImpl) getParamsForPriorityDeployment(valuesOver
impl.logger.Errorw("error while getting project", "projectId", valuesOverrideResponse.Pipeline.App.TeamId, "err", err)
return nil, err
}
lastColonIndex := strings.LastIndex(valuesOverrideResponse.Artifact.Image, ":")
var containerRepository, containerImageTag string
if len(valuesOverrideResponse.Artifact.Image)-1 > lastColonIndex && lastColonIndex != 1 {
containerRepository = valuesOverrideResponse.Artifact.Image[:lastColonIndex]
containerImageTag = valuesOverrideResponse.Artifact.Image[lastColonIndex+1:]
}
containerRepository, containerImageTag := valuesOverrideResponse.Artifact.ExtractImageRepoAndTag()

containerImage := valuesOverrideResponse.Artifact.Image
params := []cel.ExpressionParam{
{
Expand Down
149 changes: 0 additions & 149 deletions pkg/pipeline/AppArtifactManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import (
)

type AppArtifactManager interface {
//RetrieveArtifactsByCDPipeline : RetrieveArtifactsByCDPipeline returns all the artifacts for the cd pipeline (pre / deploy / post)
RetrieveArtifactsByCDPipeline(pipeline *pipelineConfig.Pipeline, stage bean.WorkflowType) (*bean2.CiArtifactResponse, error)

RetrieveArtifactsByCDPipelineV2(pipeline *pipelineConfig.Pipeline, stage bean.WorkflowType, artifactListingFilterOpts *bean.ArtifactsListFilterOptions) (*bean2.CiArtifactResponse, error)

//FetchArtifactForRollback :
Expand Down Expand Up @@ -420,152 +417,6 @@ func (impl *AppArtifactManagerImpl) BuildRollbackArtifactsList(artifactListingFi

}

func (impl *AppArtifactManagerImpl) RetrieveArtifactsByCDPipeline(pipeline *pipelineConfig.Pipeline, stage bean.WorkflowType) (*bean2.CiArtifactResponse, error) {

// retrieve parent details
parentId, parentType, err := impl.cdPipelineConfigService.RetrieveParentDetails(pipeline.Id)
if err != nil {
impl.logger.Errorw("failed to retrieve parent details",
"cdPipelineId", pipeline.Id,
"err", err)
return nil, err
}

parentCdId := 0
if parentType == bean.CD_WORKFLOW_TYPE_POST || (parentType == bean.CD_WORKFLOW_TYPE_DEPLOY && stage != bean.CD_WORKFLOW_TYPE_POST) {
// parentCdId is being set to store the artifact currently deployed on parent cd (if applicable).
// Parent component is CD only if parent type is POST/DEPLOY
parentCdId = parentId
}

if stage == bean.CD_WORKFLOW_TYPE_DEPLOY {
pipelinePreStage, err := impl.pipelineStageService.GetCdStageByCdPipelineIdAndStageType(pipeline.Id, repository2.PIPELINE_STAGE_TYPE_PRE_CD)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in fetching PRE-CD stage by cd pipeline id", "pipelineId", pipeline.Id, "err", err)
return nil, err
}
if (pipelinePreStage != nil && pipelinePreStage.Id != 0) || len(pipeline.PreStageConfig) > 0 {
// Parent type will be PRE for DEPLOY stage
parentId = pipeline.Id
parentType = bean.CD_WORKFLOW_TYPE_PRE
}
}
if stage == bean.CD_WORKFLOW_TYPE_POST {
// Parent type will be DEPLOY for POST stage
parentId = pipeline.Id
parentType = bean.CD_WORKFLOW_TYPE_DEPLOY
}

// Build artifacts for cd stages
var ciArtifacts []bean2.CiArtifactBean
ciArtifactsResponse := &bean2.CiArtifactResponse{}

artifactMap := make(map[int]int)
limit := 10

ciArtifacts, artifactMap, latestWfArtifactId, latestWfArtifactStatus, err := impl.
BuildArtifactsForCdStage(pipeline.Id, stage, ciArtifacts, artifactMap, false, limit, parentCdId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in getting artifacts for child cd stage", "err", err, "stage", stage)
return nil, err
}

ciArtifacts, err = impl.BuildArtifactsForParentStage(pipeline.Id, parentId, parentType, ciArtifacts, artifactMap, limit, parentCdId)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in getting artifacts for cd", "err", err, "parentStage", parentType, "stage", stage)
return nil, err
}

//sorting ci artifacts on the basis of creation time
if ciArtifacts != nil {
sort.SliceStable(ciArtifacts, func(i, j int) bool {
return ciArtifacts[i].Id > ciArtifacts[j].Id
})
}

artifactIds := make([]int, 0, len(ciArtifacts))
for _, artifact := range ciArtifacts {
artifactIds = append(artifactIds, artifact.Id)
}

artifacts, err := impl.ciArtifactRepository.GetArtifactParentCiAndWorkflowDetailsByIds(artifactIds)
if err != nil {
return ciArtifactsResponse, err
}
imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(pipeline.AppId)
if err != nil {
impl.logger.Errorw("error in getting image tagging data with appId", "err", err, "appId", pipeline.AppId)
return ciArtifactsResponse, err
}

imageCommentsDataMap, err := impl.imageTaggingService.GetImageCommentsDataMapByArtifactIds(artifactIds)
if err != nil {
impl.logger.Errorw("error in getting GetImageCommentsDataMapByArtifactIds", "err", err, "appId", pipeline.AppId, "artifactIds", artifactIds)
return ciArtifactsResponse, err
}

for i, artifact := range artifacts {
if imageTaggingResp := imageTagsDataMap[ciArtifacts[i].Id]; imageTaggingResp != nil {
ciArtifacts[i].ImageReleaseTags = imageTaggingResp
}
if imageCommentResp := imageCommentsDataMap[ciArtifacts[i].Id]; imageCommentResp != nil {
ciArtifacts[i].ImageComment = imageCommentResp
}

if artifact.ExternalCiPipelineId != 0 {
// if external webhook continue
continue
}
var dockerRegistryId string
if artifact.PipelineId != 0 {
ciPipeline, err := impl.CiPipelineRepository.FindByIdIncludingInActive(artifact.PipelineId)
if err != nil {
impl.logger.Errorw("error in fetching ciPipeline", "ciPipelineId", ciPipeline.Id, "error", err)
return nil, err
}
dockerRegistryId = *ciPipeline.CiTemplate.DockerRegistryId
} else {
if artifact.CredentialsSourceType == repository.GLOBAL_CONTAINER_REGISTRY {
dockerRegistryId = artifact.CredentialSourceValue
}
}
if len(dockerRegistryId) > 0 {
dockerArtifact, err := impl.dockerArtifactRegistry.FindOne(dockerRegistryId)
if err != nil {
impl.logger.Errorw("error in getting docker registry details", "err", err, "dockerArtifactStoreId", dockerRegistryId)
}
ciArtifacts[i].RegistryType = string(dockerArtifact.RegistryType)
ciArtifacts[i].RegistryName = dockerRegistryId
}
var ciWorkflow *pipelineConfig.CiWorkflow
if artifact.ParentCiArtifact != 0 {
ciWorkflow, err = impl.ciWorkflowRepository.FindLastTriggeredWorkflowGitTriggersByArtifactId(artifact.ParentCiArtifact)
if err != nil {
impl.logger.Errorw("error in getting ci_workflow for artifacts", "err", err, "artifact", artifact, "parentStage", parentType, "stage", stage)
return ciArtifactsResponse, err
}

} else {
ciWorkflow, err = impl.ciWorkflowRepository.FindCiWorkflowGitTriggersById(*artifact.WorkflowId)
if err != nil {
impl.logger.Errorw("error in getting ci_workflow for artifacts", "err", err, "artifact", artifact, "parentStage", parentType, "stage", stage)
return ciArtifactsResponse, err
}
}
ciArtifacts[i].CiConfigureSourceType = ciWorkflow.GitTriggers[ciWorkflow.CiPipelineId].CiConfigureSourceType
ciArtifacts[i].CiConfigureSourceValue = ciWorkflow.GitTriggers[ciWorkflow.CiPipelineId].CiConfigureSourceValue
}

ciArtifactsResponse.CdPipelineId = pipeline.Id
ciArtifactsResponse.LatestWfArtifactId = latestWfArtifactId
ciArtifactsResponse.LatestWfArtifactStatus = latestWfArtifactStatus
if ciArtifacts == nil {
ciArtifacts = []bean2.CiArtifactBean{}
}
ciArtifactsResponse.CiArtifacts = ciArtifacts
return ciArtifactsResponse, nil
}

func (impl *AppArtifactManagerImpl) extractParentMetaDataByPipeline(pipeline *pipelineConfig.Pipeline, stage bean.WorkflowType) (parentId int, parentType bean.WorkflowType, parentCdId int, err error) {
// retrieve parent details
parentId, parentType, err = impl.cdPipelineConfigService.RetrieveParentDetails(pipeline.Id)
Expand Down
17 changes: 13 additions & 4 deletions pkg/pipeline/AppDeploymentTypeChangeManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
bean5 "github.com/devtron-labs/devtron/api/bean"
"github.com/devtron-labs/devtron/api/bean/gitOps"
"github.com/devtron-labs/devtron/api/helm-app/service"
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
Expand Down Expand Up @@ -192,8 +193,12 @@ func (impl *AppDeploymentTypeChangeManagerImpl) ChangeDeploymentType(ctx context

for _, pipeline := range pipelines {

artifactDetails, err := impl.appArtifactManager.RetrieveArtifactsByCDPipeline(pipeline, "DEPLOY")

artifactsListingFilterOptions := &bean5.ArtifactsListFilterOptions{
Limit: 10,
Offset: 0,
SearchString: "",
}
artifactDetails, err := impl.appArtifactManager.RetrieveArtifactsByCDPipelineV2(pipeline, bean5.CD_WORKFLOW_TYPE_DEPLOY, artifactsListingFilterOptions)
if err != nil {
impl.logger.Errorw("failed to fetch artifact details for cd pipeline",
"pipelineId", pipeline.Id,
Expand Down Expand Up @@ -381,8 +386,12 @@ func (impl *AppDeploymentTypeChangeManagerImpl) TriggerDeploymentAfterTypeChange

for _, pipeline := range pipelines {

artifactDetails, err := impl.appArtifactManager.RetrieveArtifactsByCDPipeline(pipeline, "DEPLOY")

artifactsListingFilterOptions := &bean5.ArtifactsListFilterOptions{
Limit: 10,
Offset: 0,
SearchString: "",
}
artifactDetails, err := impl.appArtifactManager.RetrieveArtifactsByCDPipelineV2(pipeline, bean5.CD_WORKFLOW_TYPE_DEPLOY, artifactsListingFilterOptions)
if err != nil {
impl.logger.Errorw("failed to fetch artifact details for cd pipeline",
"pipelineId", pipeline.Id,
Expand Down
23 changes: 23 additions & 0 deletions util/dockerUtil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package util

import "strings"

const (
DEFAULT_TAG_VALUE = "latest"
)

func ExtractImageRepoAndTag(imagePath string) (repo string, tag string) {
if len(imagePath) == 0 {
return "", ""
}
var containerRepository, containerImageTag string
lastColonIndex := strings.LastIndex(imagePath, ":")
if lastColonIndex == -1 {
containerRepository = imagePath
containerImageTag = DEFAULT_TAG_VALUE
} else {
containerRepository = imagePath[:lastColonIndex]
containerImageTag = imagePath[lastColonIndex+1:]
}
return containerRepository, containerImageTag
}
Loading