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: DT19-v1 bug fixes #3962

Merged
merged 22 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cd1be97
fix:Image tag not propagated in Rollback (#3897)
adi6859 Sep 14, 2023
cdb33ed
fix: block trigger for vulnerable image (#3888)
Ash-exp Sep 14, 2023
0ee6c16
fix: invalid post deployment status in App group (#3880)
Ash-exp Sep 14, 2023
55fd8f7
fixed: updated invalid installed version error message (#3889)
Ash-exp Sep 14, 2023
20fc9f0
feat: updated error message for installed app (#3894)
Ash-exp Sep 14, 2023
56a6234
bug fix (#3903)
ShashwatDadhich Sep 14, 2023
c1ade39
bug fix (#3907)
ShashwatDadhich Sep 14, 2023
86fcf91
Merge branch 'main' into stable-dt19-v1
ShashwatDadhich Sep 14, 2023
dbfbfec
fix: Deployment is breaking due to invalid environment name (#3896)
Ashish-devtron Sep 14, 2023
6f2381c
Merge branch 'main' into stable-dt19-v1
Ash-exp Sep 15, 2023
e4edc7c
fix: invalid cluster details fetched for partial delete state (#3898)
Ash-exp Sep 15, 2023
5d78911
fix: Security scan list fix (#3901)
ShashwatDadhich Sep 15, 2023
f029130
Merge branch 'main' into stable-dt19-v1
Ash-exp Sep 18, 2023
40d723b
fix: updated previous deployment status (#3939)
Ash-exp Sep 20, 2023
77fe044
Merge branch 'main' into stable-dt19-v1
Ash-exp Sep 21, 2023
e0bce0f
fix: updated delete installed app error (#3941)
Ash-exp Sep 21, 2023
0cca0de
check for update access while updating (#3944)
Ashish-devtron Sep 21, 2023
6cf379b
fix: workflow not created for auto trigger (#3947)
Ash-exp Sep 21, 2023
13618c1
fix: helm app delete error (#3949)
Ash-exp Sep 21, 2023
5b7ccc1
Merge branch 'main' into stable-dt19-v1
Ash-exp Sep 25, 2023
9799684
Merge branch 'main' into stable-dt19-v1
vikramdevtron Sep 26, 2023
51ca975
Merge branch 'main' into stable-dt19-v1
vikramdevtron Sep 26, 2023
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
6 changes: 6 additions & 0 deletions api/appStore/deployment/AppStoreDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/go-pg/pg"
"github.com/gorilla/mux"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
Expand Down Expand Up @@ -291,6 +292,11 @@ func (handler AppStoreDeploymentRestHandlerImpl) DeleteInstalledApp(w http.Respo
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(installAppId)
if err != nil {
handler.Logger.Error(err)
if err == pg.ErrNoRows {
err = &util.ApiError{Code: "404", HttpStatusCode: 404, UserMessage: "App not found in database", InternalMessage: err.Error()}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion api/cluster/EnvironmentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func (impl EnvironmentRestHandlerImpl) GetEnvironmentConnection(w http.ResponseW
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
clusterBean, err := impl.environmentClusterMappingsService.FindClusterByEnvId(bean.ClusterId)
clusterBean, err := impl.environmentClusterMappingsService.FindClusterByEnvId(envId)
if err != nil {
impl.logger.Errorw("request err, FindById", "err", err, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
6 changes: 4 additions & 2 deletions api/restHandler/ChartGroupRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ func (impl *ChartGroupRestHandlerImpl) SaveChartGroupEntries(w http.ResponseWrit
token := r.Header.Get("token")
rbacObject := request.Name
if ok := impl.enforcer.Enforce(token, casbin.ResourceChartGroup, casbin.ActionCreate, rbacObject); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
if ok1 := impl.enforcer.Enforce(token, casbin.ResourceChartGroup, casbin.ActionUpdate, rbacObject); !ok1 {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
//RBAC block ends here
res, err := impl.ChartGroupService.SaveChartGroupEntries(&request)
Expand Down
21 changes: 20 additions & 1 deletion api/restHandler/app/DeploymentPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,13 +1362,32 @@ func (handler PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Resp
return
}
//rbac block ends here
//rbac for edit tags access
triggerAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionTrigger, object)

ciArtifactResponse, err := handler.pipelineBuilder.FetchArtifactForRollback(cdPipelineId, offset, limit)
ciArtifactResponse, err := handler.pipelineBuilder.FetchArtifactForRollback(cdPipelineId, app.Id, offset, limit)
if err != nil {
handler.Logger.Errorw("service err, GetArtifactsForRollback", "err", err, "cdPipelineId", cdPipelineId)
common.WriteJsonResp(w, err, "unable to fetch artifacts", http.StatusInternalServerError)
return
}
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(app.Id)
if err != nil {
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", app.Id)
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
return
}

ciArtifactResponse.AppReleaseTagNames = appTags

prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(cdPipelineId)
ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
if err != nil {
handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", app.Id)
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusOK)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (impl ImageScanDeployInfoRepositoryImpl) scanListQueryWithoutObject(request
}
query = query + " INNER JOIN environment env on env.id=info.env_id"
query = query + " INNER JOIN cluster clus on clus.id=env.cluster_id"
query = query + " WHERE info.scan_object_meta_id > 0 and env.active=true"
query = query + " WHERE info.scan_object_meta_id > 0 and env.active=true and info.image_scan_execution_history_id[1] != -1"
if len(deployInfoIds) > 0 {
ids := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(deployInfoIds)), ","), "[]")
query = query + " AND info.id IN (" + ids + ")"
Expand Down Expand Up @@ -232,7 +232,7 @@ func (impl ImageScanDeployInfoRepositoryImpl) scanListQueryWithObject(request *I
}
query = query + " INNER JOIN environment env on env.id=info.env_id"
query = query + " INNER JOIN cluster c on c.id=env.cluster_id"
query = query + " WHERE info.scan_object_meta_id > 0 and env.active=true"
query = query + " WHERE info.scan_object_meta_id > 0 and env.active=true and info.image_scan_execution_history_id[1] != -1"
if len(deployInfoIds) > 0 {
ids := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(deployInfoIds)), ","), "[]")
query = query + " AND info.id IN (" + ids + ")"
Expand Down
21 changes: 12 additions & 9 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type AppService interface {
GetConfigMapAndSecretJson(appId int, envId int, pipelineId int) ([]byte, error)
UpdateCdWorkflowRunnerByACDObject(app *v1alpha1.Application, cdWfrId int, updateTimedOutStatus bool) error
GetCmSecretNew(appId int, envId int, isJob bool) (*bean.ConfigMapJson, *bean.ConfigSecretJson, error)
MarkImageScanDeployed(appId int, envId int, imageDigest string, clusterId int) error
MarkImageScanDeployed(appId int, envId int, imageDigest string, clusterId int, isScanEnabled bool) error
UpdateDeploymentStatusForGitOpsPipelines(app *v1alpha1.Application, statusTime time.Time, isAppStore bool) (bool, bool, error)
WriteCDSuccessEvent(appId int, envId int, override *chartConfig.PipelineOverride)
GetGitOpsRepoPrefix() string
Expand Down Expand Up @@ -1833,11 +1833,9 @@ func (impl *AppServiceImpl) TriggerPipeline(overrideRequest *bean.ValuesOverride

go impl.WriteCDTriggerEvent(overrideRequest, valuesOverrideResponse.Artifact, valuesOverrideResponse.PipelineOverride.PipelineReleaseCounter, valuesOverrideResponse.PipelineOverride.Id)

if valuesOverrideResponse.Artifact.ScanEnabled {
_, span := otel.Tracer("orchestrator").Start(ctx, "MarkImageScanDeployed")
_ = impl.MarkImageScanDeployed(overrideRequest.AppId, valuesOverrideResponse.EnvOverride.TargetEnvironment, valuesOverrideResponse.Artifact.ImageDigest, overrideRequest.ClusterId)
span.End()
}
_, spann := otel.Tracer("orchestrator").Start(ctx, "MarkImageScanDeployed")
_ = impl.MarkImageScanDeployed(overrideRequest.AppId, valuesOverrideResponse.EnvOverride.TargetEnvironment, valuesOverrideResponse.Artifact.ImageDigest, overrideRequest.ClusterId, valuesOverrideResponse.Artifact.ScanEnabled)
spann.End()

middleware.CdTriggerCounter.WithLabelValues(overrideRequest.AppName, overrideRequest.EnvName).Inc()

Expand Down Expand Up @@ -1986,7 +1984,7 @@ func (impl *AppServiceImpl) autoHealChartLocationInChart(ctx context.Context, en
return nil
}

func (impl *AppServiceImpl) MarkImageScanDeployed(appId int, envId int, imageDigest string, clusterId int) error {
func (impl *AppServiceImpl) MarkImageScanDeployed(appId int, envId int, imageDigest string, clusterId int, isScanEnabled bool) error {
impl.logger.Debugw("mark image scan deployed for normal app, from cd auto or manual trigger", "imageDigest", imageDigest)
executionHistory, err := impl.imageScanHistoryRepository.FindByImageDigest(imageDigest)
if err != nil && err != pg.ErrNoRows {
Expand All @@ -2004,7 +2002,7 @@ func (impl *AppServiceImpl) MarkImageScanDeployed(appId int, envId int, imageDig
ot, err := impl.imageScanDeployInfoRepository.FindByTypeMetaAndTypeId(appId, security.ScanObjectType_APP) //todo insure this touple unique in db
if err != nil && err != pg.ErrNoRows {
return err
} else if err == pg.ErrNoRows {
} else if err == pg.ErrNoRows && isScanEnabled {
imageScanDeployInfo := &security.ImageScanDeployInfo{
ImageScanExecutionHistoryId: ids,
ScanObjectMetaId: appId,
Expand All @@ -2025,7 +2023,12 @@ func (impl *AppServiceImpl) MarkImageScanDeployed(appId int, envId int, imageDig
}
} else {
// Updating Execution history for Latest Deployment to fetch out security Vulnerabilities for latest deployed info
ot.ImageScanExecutionHistoryId = ids
if isScanEnabled {
ot.ImageScanExecutionHistoryId = ids
} else {
arr := []int{-1}
ot.ImageScanExecutionHistoryId = arr
}
err = impl.imageScanDeployInfoRepository.Update(ot)
if err != nil {
impl.logger.Errorw("error in updating deploy info for latest deployed image", "err", err)
Expand Down
10 changes: 8 additions & 2 deletions pkg/appStore/deployment/service/AppStoreDeploymentService.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ func (impl AppStoreDeploymentServiceImpl) DeleteInstalledApp(ctx context.Context

app, err := impl.appRepository.FindById(installAppVersionRequest.AppId)
if err != nil {
if err == pg.ErrNoRows {
return nil, fmt.Errorf("App not found in database")
}
return nil, err
}
model, err := impl.installedAppRepository.GetInstalledApp(installAppVersionRequest.InstalledAppId)
Expand Down Expand Up @@ -857,7 +860,7 @@ func (impl AppStoreDeploymentServiceImpl) createEnvironmentIfNotExists(installAp
}

environmentBean := &cluster2.EnvironmentBean{
Environment: cluster2.BuildEnvironmentIdentifer(cluster.ClusterName, namespace),
Environment: cluster2.BuildEnvironmentName(cluster.ClusterName, namespace),
ClusterId: clusterId,
Namespace: namespace,
Default: false,
Expand Down Expand Up @@ -1318,7 +1321,7 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
installedAppVersion, err = impl.installedAppRepository.GetInstalledAppVersion(installAppVersionRequest.Id)
if err != nil {
impl.logger.Errorw("error in fetching installedAppVersion by installAppVersionRequest id ", "err", err)
return nil, err
return nil, fmt.Errorf("The values are outdated. Please make your changes to the latest version and try again.")
}
// version is upgraded if appStoreApplication version from request payload is not equal to installed app version saved in DB
if installedAppVersion.AppStoreApplicationVersionId != installAppVersionRequest.AppStoreVersion {
Expand Down Expand Up @@ -1519,6 +1522,9 @@ func (impl *AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Contex
func (impl AppStoreDeploymentServiceImpl) GetInstalledAppVersion(id int, userId int32) (*appStoreBean.InstallAppVersionDTO, error) {
app, err := impl.installedAppRepository.GetInstalledAppVersion(id)
if err != nil {
if err == pg.ErrNoRows {
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
}
impl.logger.Errorw("error while fetching from db", "error", err)
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/appStore/deployment/service/InstalledAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,14 @@ func (impl *InstalledAppServiceImpl) FindAppDetailsForAppstoreApplication(instal
func (impl *InstalledAppServiceImpl) FetchChartNotes(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error) {
//check notes.txt in db
installedApp, err := impl.installedAppRepository.FetchNotes(installedAppId)
if err != nil && err != pg.ErrNoRows {
return "", err
}
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
if err != nil {
if err == pg.ErrNoRows {
return "", fmt.Errorf("values are outdated. please fetch the latest version and try again")
}
impl.logger.Errorw("error fetching installed app version in installed app service", "err", err)
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ func (impl AppStoreDeploymentArgoCdServiceImpl) GetDeploymentHistory(ctx context

installedAppVersions, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdMeta(installedAppDto.InstalledAppId)
if err != nil {
if err == pg.ErrNoRows {
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
}
impl.Logger.Errorw("error while fetching installed version", "error", err)
return result, err
}
Expand Down
13 changes: 9 additions & 4 deletions pkg/cluster/EnvironmentUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

package cluster

import "fmt"
import (
"fmt"
"strings"
)

func BuildEnvironmentIdentifer(clusterName string, namespace string) string {
return fmt.Sprintf("%s__%s", clusterName, namespace)
}
func BuildEnvironmentName(clusterName string, namespace string) string {
// Here we are replacing the (_) with (-) in clusterName as we don't support (_) in environment Name
clusterName = strings.ReplaceAll(clusterName, "_", "-")
return fmt.Sprintf("%s--%s", clusterName, namespace)
}
3 changes: 3 additions & 0 deletions pkg/k8s/application/k8sApplicationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ func (impl *K8sApplicationServiceImpl) GetAllApiResourceGVKWithoutAuthorization(
k8sEventIndex = index
}
}
if gvk.Kind == "Node" {
allApiResources = append(allApiResources[:index], allApiResources[index+1:]...)
}
}
if k8sEventIndex > -1 && v1EventIndex > -1 {
allApiResources = append(allApiResources[:v1EventIndex], allApiResources[v1EventIndex+1:]...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerViewForEnvironment(re
cdWorkflowStatus.PreStatus = statusMap[item.WfrId]
} else if item.WorkflowType == WorklowTypeDeploy {
cdWorkflowStatus.DeployStatus = statusMap[item.WfrId]
} else if item.WorkflowType == WorklowTypePre {
} else if item.WorkflowType == WorklowTypePost {
cdWorkflowStatus.PostStatus = statusMap[item.WfrId]
}
cdMap[item.PipelineId] = cdWorkflowStatus
Expand Down
27 changes: 25 additions & 2 deletions pkg/pipeline/PipelineBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type PipelineBuilder interface {
/* CreateCdPipelines(cdPipelines bean.CdPipelines) (*bean.CdPipelines, error)*/
RetrieveArtifactsByCDPipeline(pipeline *pipelineConfig.Pipeline, stage bean2.WorkflowType) (*bean.CiArtifactResponse, error)
RetrieveParentDetails(pipelineId int) (parentId int, parentType bean2.WorkflowType, err error)
FetchArtifactForRollback(cdPipelineId, offset, limit int) (bean.CiArtifactResponse, error)
FetchArtifactForRollback(cdPipelineId, appId, offset, limit int) (bean.CiArtifactResponse, error)
FindAppsByTeamId(teamId int) ([]*AppBean, error)
FindAppsByTeamName(teamName string) ([]AppBean, error)
FindPipelineById(cdPipelineId int) (*pipelineConfig.Pipeline, error)
Expand Down Expand Up @@ -3842,7 +3842,7 @@ func (impl *PipelineBuilderImpl) BuildArtifactsForCIParent(cdPipelineId int, par
return ciArtifacts, nil
}

func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset, limit int) (bean.CiArtifactResponse, error) {
func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, appId, offset, limit int) (bean.CiArtifactResponse, error) {
var deployedCiArtifacts []bean.CiArtifactBean
var deployedCiArtifactsResponse bean.CiArtifactResponse

Expand All @@ -3863,6 +3863,14 @@ func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset,
for _, item := range users {
userEmails[item.Id] = item.EmailId
}

imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(appId)
if err != nil {
impl.logger.Errorw("error in getting image tagging data with appId", "err", err, "appId", appId)
return deployedCiArtifactsResponse, err
}
artifactIds := make([]int, 0)

for _, cdWfr := range cdWfrs {
ciArtifact := &repository.CiArtifact{}
if cdWfr.CdWorkflow != nil && cdWfr.CdWorkflow.CiArtifact != nil {
Expand All @@ -3885,6 +3893,21 @@ func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset,
WfrId: cdWfr.Id,
DeployedBy: userEmail,
})
artifactIds = append(artifactIds, ciArtifact.Id)
}
imageCommentsDataMap, err := impl.imageTaggingService.GetImageCommentsDataMapByArtifactIds(artifactIds)
if err != nil {
impl.logger.Errorw("error in getting GetImageCommentsDataMapByArtifactIds", "err", err, "appId", appId, "artifactIds", artifactIds)
return deployedCiArtifactsResponse, err
}

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

deployedCiArtifactsResponse.CdPipelineId = cdPipelineId
Expand Down
Loading
Loading