Skip to content

Commit c1d1cb9

Browse files
committed
Merge branch 'main' into feat-notifier-behind-nats
2 parents 5fe7a12 + fbf9176 commit c1d1cb9

15 files changed

+108
-9
lines changed

config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
| DEVTRON_HELM_RELEASE_NAME | devtron | Name of the Devtron Helm release. |
9898
| ENABLE_LEGACY_API | "false" | Enable the legacy API. |
9999
| INSTALLATION_THROUGH_HELM | "True" | Installation through Helm (True or False). |
100+
| USE_IMAGE_TAG_FROM_GIT_PROVIDER_FOR_TAG_BASED_BUILD | "True" | Tag Image same as Git provider for Tag based Build (True or False) |
100101

101102

102103
# DEVTRON SECRET PARAMETER

internal/sql/repository/security/CveStoreRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type CveStore struct {
3030
tableName struct{} `sql:"cve_store" pg:",discard_unknown_columns"`
3131
Name string `sql:"name,pk"`
3232
Severity Severity `sql:"severity,notnull"`
33-
Package string `sql:"package,notnull"`
33+
Package string `sql:"package,notnull"` // deprecated
3434
Version string `sql:"version,notnull"`
3535
FixedVersion string `sql:"fixed_version,notnull"`
3636
sql.AuditLog

internal/sql/repository/security/ImageScanResultRepository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ImageScanExecutionResult struct {
2727
CveStoreName string `sql:"cve_store_name,notnull"`
2828
ImageScanExecutionHistoryId int `sql:"image_scan_execution_history_id"`
2929
ScanToolId int `sql:"scan_tool_id"`
30+
Package string `sql:"package"`
3031
CveStore CveStore
3132
ImageScanExecutionHistory ImageScanExecutionHistory
3233
}

pkg/app/AppCrudOperationService.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,25 @@ func (impl AppCrudOperationServiceImpl) getExtraAppLabelsToPropagate(appId int,
613613
impl.logger.Errorw("error in finding app and project by appId", "appId", appId, "err", err)
614614
return nil, err
615615
}
616-
return map[string]string{
617-
bean3.AppNameDevtronLabel: appName,
618-
bean3.EnvNameDevtronLabel: envName,
619-
bean3.ProjectNameDevtronLabel: appMetaInfo.Team.Name,
620-
}, nil
616+
regexp := regexp.MustCompile(LabelMatchingRegex)
617+
extraAppLabels := make(map[string]string)
618+
619+
extraAppLabels[bean3.AppNameDevtronLabel] = appName
620+
extraAppLabels[bean3.EnvNameDevtronLabel] = envName
621+
extraAppLabels[bean3.ProjectNameDevtronLabel] = appMetaInfo.Team.Name
622+
623+
extraAppLabels = sanitizeLabels(extraAppLabels)
624+
for labelKey, labelValue := range extraAppLabels {
625+
if regexp.MatchString(labelValue) {
626+
extraAppLabels[labelKey] = labelValue
627+
} else {
628+
// in case extra labels are failing k8s official label matching regex even after sanitization then
629+
//delete the label as this can break deployments.
630+
impl.logger.Warnw("extra label failed LabelMatchingRegex validation, regex:- ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$", "labelKey", labelKey, "labelValue", labelValue)
631+
delete(extraAppLabels, labelKey)
632+
}
633+
}
634+
return extraAppLabels, nil
621635
}
622636

623637
func (impl AppCrudOperationServiceImpl) GetAppLabelsForDeployment(appId int, appName, envName string) ([]byte, error) {

pkg/app/helper.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package app
1818

19+
import "strings"
20+
21+
// LabelMatchingRegex is the official k8s label matching regex, pls refer https://github.com/kubernetes/apimachinery/blob/bfd2aff97e594f6aad77acbe2cbbe190acc93cbc/pkg/util/validation/validation.go#L167
22+
const LabelMatchingRegex = "^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$"
23+
1924
// MergeChildMapToParentMap merges child map of generic type map into parent map of generic type
2025
// and returns merged mapping, if parentMap is nil then nil is returned.
2126
func MergeChildMapToParentMap[T comparable, R any](parentMap map[T]R, toMergeMap map[T]R) map[T]R {
@@ -29,3 +34,12 @@ func MergeChildMapToParentMap[T comparable, R any](parentMap map[T]R, toMergeMap
2934
}
3035
return parentMap
3136
}
37+
38+
func sanitizeLabels(extraAppLabels map[string]string) map[string]string {
39+
for lkey, lvalue := range extraAppLabels {
40+
if strings.Contains(lvalue, " ") {
41+
extraAppLabels[lkey] = strings.ReplaceAll(lvalue, " ", "_")
42+
}
43+
}
44+
return extraAppLabels
45+
}

pkg/deployment/gitOps/git/GitOpsHelper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ func (impl *GitOpsHelper) Pull(repoRoot string) (err error) {
9696
return impl.gitCommandManager.Pull(ctx, repoRoot)
9797
}
9898

99+
const PushErrorMessage = "failed to push some refs"
100+
99101
func (impl GitOpsHelper) CommitAndPushAllChanges(repoRoot, commitMsg, name, emailId string) (commitHash string, err error) {
100102
start := time.Now()
101103
defer func() {
102104
util.TriggerGitOpsMetrics("CommitAndPushAllChanges", "GitService", start, err)
103105
}()
104106
ctx := git.BuildGitContext(context.Background()).WithCredentials(impl.Auth)
105-
return impl.gitCommandManager.CommitAndPush(ctx, repoRoot, commitMsg, name, emailId)
107+
commitHash, err = impl.gitCommandManager.CommitAndPush(ctx, repoRoot, commitMsg, name, emailId)
108+
if err != nil && strings.Contains(err.Error(), PushErrorMessage) {
109+
return commitHash, fmt.Errorf("%s %v", "push failed due to conflicts", err)
110+
}
111+
return commitHash, nil
106112
}
107113

108114
func (impl *GitOpsHelper) pullFromBranch(ctx git.GitContext, rootDir string) (string, string, error) {

pkg/deployment/gitOps/git/commandManager/GitCliManager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (impl *GitCliManagerImpl) add(ctx GitContext, rootDir string) (response, er
132132

133133
func (impl *GitCliManagerImpl) push(ctx GitContext, rootDir string) (response, errMsg string, err error) {
134134
impl.logger.Debugw("git push ", "location", rootDir)
135-
cmd, cancel := impl.createCmdWithContext(ctx, "git", "-C", rootDir, "push", "origin", "master", "--force")
135+
cmd, cancel := impl.createCmdWithContext(ctx, "git", "-C", rootDir, "push", "origin", "master")
136136
defer cancel()
137137
output, errMsg, err := impl.runCommandWithCred(cmd, ctx.auth)
138138
impl.logger.Debugw("git add output", "root", rootDir, "opt", output, "errMsg", errMsg, "error", err)

pkg/deployment/gitOps/git/commandManager/GitCommandBaseManager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (impl *GitManagerBaseImpl) runCommand(cmd *exec.Cmd) (response, errMsg stri
9292
if err != nil {
9393
exErr, ok := err.(*exec.ExitError)
9494
if !ok {
95-
return "", "", err
95+
return "", "", fmt.Errorf("%s %v", outBytes, err)
9696
}
9797
errOutput := string(exErr.Stderr)
9898
return "", errOutput, err

pkg/eventProcessor/in/WorkflowEventProcessorService.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func (impl *WorkflowEventProcessorImpl) SubscribeCDStageCompleteEvent() error {
152152
impl.logger.Errorw("could not get wf runner", "err", err)
153153
return
154154
}
155+
156+
if wfr.Status != string(v1alpha1.NodeSucceeded) {
157+
impl.logger.Debugw("event received from ci runner, updating workflow runner status as succeeded", "savedWorkflowRunnerId", wfr.Id, "oldStatus", wfr.Status, "podStatus", wfr.PodStatus)
158+
err = impl.cdWorkflowRunnerService.UpdateWfrStatus(wfr, string(v1alpha1.NodeSucceeded), 1)
159+
if err != nil {
160+
impl.logger.Errorw("update cd-wf-runner failed for id ", "cdWfrId", wfr.Id, "err", err)
161+
return
162+
}
163+
}
164+
155165
triggerContext := bean5.TriggerContext{
156166
ReferenceId: pointer.String(msg.MsgId),
157167
}

pkg/security/ImageScanService.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ func (impl ImageScanServiceImpl) FetchExecutionDetailResult(request *ImageScanRe
372372
Severity: item.CveStore.Severity.String(),
373373
//Permission: "BLOCK", TODO
374374
}
375+
if len(item.Package) > 0 {
376+
// data already migrated hence get package from image_scan_execution_result
377+
vulnerability.Package = item.Package
378+
}
375379
if item.CveStore.Severity == security.Critical {
376380
highCount = highCount + 1
377381
} else if item.CveStore.Severity == security.Medium {

pkg/security/policyService.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ func (impl *PolicyServiceImpl) VerifyImage(verifyImageRequest *VerifyImageReques
242242
impl.logger.Errorw("error in fetching vulnerability ", "err", err)
243243
return nil, err
244244
}
245+
cveNameToScanResultPackageNameMapping := make(map[string]string)
245246
var cveStores []*security.CveStore
246247
for _, scanResult := range scanResults {
248+
cveNameToScanResultPackageNameMapping[scanResult.CveStoreName] = scanResult.Package
247249
cveStores = append(cveStores, &scanResult.CveStore)
248250
if _, ok := scanResultsIdMap[scanResult.ImageScanExecutionHistoryId]; !ok {
249251
scanResultsIdMap[scanResult.ImageScanExecutionHistoryId] = scanResult.ImageScanExecutionHistoryId
@@ -259,6 +261,13 @@ func (impl *PolicyServiceImpl) VerifyImage(verifyImageRequest *VerifyImageReques
259261
Version: cve.Version,
260262
FixedVersion: cve.FixedVersion,
261263
}
264+
if packageName, ok := cveNameToScanResultPackageNameMapping[cve.Name]; ok {
265+
if len(packageName) > 0 {
266+
// fetch package name from image_scan_execution_result table
267+
vr.Package = packageName
268+
}
269+
270+
}
262271
imageBlockedCves[image] = append(imageBlockedCves[image], vr)
263272
}
264273
}

pkg/workflow/cd/CdWorkflowRunnerService.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
2323
"github.com/go-pg/pg"
2424
"go.uber.org/zap"
25+
"time"
2526
)
2627

2728
type CdWorkflowRunnerService interface {
2829
FindWorkflowRunnerById(wfrId int) (*bean.CdWorkflowRunnerDto, error)
2930
CheckIfWfrLatest(wfrId, pipelineId int) (isLatest bool, err error)
31+
UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error
3032
}
3133

3234
type CdWorkflowRunnerServiceImpl struct {
@@ -60,3 +62,16 @@ func (impl *CdWorkflowRunnerServiceImpl) CheckIfWfrLatest(wfrId, pipelineId int)
6062
}
6163
return isLatest, nil
6264
}
65+
66+
func (impl *CdWorkflowRunnerServiceImpl) UpdateWfrStatus(dto *bean.CdWorkflowRunnerDto, status string, updatedBy int) error {
67+
runnerDbObj := adapter.ConvertCdWorkflowRunnerDtoToDbObj(dto)
68+
runnerDbObj.Status = status
69+
runnerDbObj.UpdatedBy = int32(updatedBy)
70+
runnerDbObj.UpdatedOn = time.Now()
71+
err := impl.cdWorkflowRepository.UpdateWorkFlowRunner(runnerDbObj)
72+
if err != nil {
73+
impl.logger.Errorw("error in updating runner status in db", "runnerId", runnerDbObj.Id, "err", err)
74+
return err
75+
}
76+
return nil
77+
}

pkg/workflow/cd/adapter/adapter.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,26 @@ func ConvertCdWorkflowDtoToDbObj(dto *bean.CdWorkflowDto) *pipelineConfig.CdWork
6262
},
6363
}
6464
}
65+
66+
func ConvertCdWorkflowRunnerDtoToDbObj(dto *bean.CdWorkflowRunnerDto) *pipelineConfig.CdWorkflowRunner {
67+
return &pipelineConfig.CdWorkflowRunner{
68+
Id: dto.Id,
69+
Name: dto.Name,
70+
WorkflowType: dto.WorkflowType,
71+
ExecutorType: dto.ExecutorType,
72+
Status: dto.Status,
73+
PodStatus: dto.PodStatus,
74+
Message: dto.Message,
75+
StartedOn: dto.StartedOn,
76+
FinishedOn: dto.FinishedOn,
77+
Namespace: dto.Namespace,
78+
LogLocation: dto.LogLocation,
79+
TriggeredBy: dto.TriggeredBy,
80+
CdWorkflowId: dto.CdWorkflowId,
81+
PodName: dto.PodName,
82+
BlobStorageEnabled: dto.BlobStorageEnabled,
83+
RefCdWorkflowRunnerId: dto.RefCdWorkflowRunnerId,
84+
ImagePathReservationIds: dto.ImagePathReservationIds,
85+
ReferenceId: dto.ReferenceId,
86+
}
87+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "image_scan_execution_result" DROP COLUMN "package";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "image_scan_execution_result" ADD COLUMN "package" text;

0 commit comments

Comments
 (0)