Skip to content

Commit

Permalink
fix: Bulk deploy panic and docker tag handling (#5949)
Browse files Browse the repository at this point in the history
* removing fetchArtifacts V1 usage and abstracting tag extraction logic

* docker tag and repo method in util

* modifying image tag logic in release override

* wip: adding empty path check

* review changes

* fix: app update migration (#5903)

* wip: adding app name check

* wip

* wip

* wip

* moving migration to code

* wip: adding app name in log

* wip: moving sql logic to code

* pg no rows handling

* adding db migration call

* fixing fetch app query

* wip: adding pg multiple rows handling

* audit log update

* fix: nil ptr fix in copying extraEnvVars

* feat:  Docker lint plugin (#5694)

* added up script for docker linit plugin

* rename of script file

* docker lint down script

* changes in docker lint

* hadolint image

* change in name of plugin

* changes in down script

* chnages in docker lint

* chnages in down script

* change in hadolint image

* rename  down script file

* renaming sql script

* feat: Added Devtron CI Trigger v1.1.0 (#5934)

* Create 028901_019_devtron_ci_trigger_v1_1.down.sql

* Create 028901_019_devtron_ci_trigger_v1_1.up.sql

* Update 028901_019_devtron_ci_trigger_v1_1.up.sql

---------

Co-authored-by: Prakarsh <71125043+prakarsh-dt@users.noreply.github.com>

* renaming docker lint script file (#5937)

* fix: err handling for configmap access

* release: PR for v0.7.3 (#5942)

* Update Chart.yaml

* Update devtron-bom.yaml

* Update values.yaml

* Update devtron-installer.yaml

* Update installation-script

* Update version.txt

* Update devtron.yaml

* Update releasenotes.md

* Update devtron-bom.yaml

* Update values.yaml

* Update releasenotes.md

* Update releasenotes.md

* Updated release-notes files

* Update releasenotes.md

* Update release.txt

* Updated release-notes files

* Update release-notes-v0.7.2.md

---------

Co-authored-by: ReleaseBot <prakarsh@devtron.ai>

* wip: modifying tags function

* sync

---------

Co-authored-by: Gireesh Naidu <gireesh@devtron.ai>
Co-authored-by: Gireesh Naidu <111440205+gireesh-naidu@users.noreply.github.com>
Co-authored-by: kamal-devtron <128121299+kamal-devtron@users.noreply.github.com>
Co-authored-by: Kiran <155609672+kirandevtn@users.noreply.github.com>
Co-authored-by: Prakarsh <71125043+prakarsh-dt@users.noreply.github.com>
Co-authored-by: Pawan Mehta <117346502+pawan-mehta-dt@users.noreply.github.com>
Co-authored-by: ReleaseBot <prakarsh@devtron.ai>
  • Loading branch information
8 people authored Oct 3, 2024
1 parent f6092df commit fcfa897
Show file tree
Hide file tree
Showing 35 changed files with 419 additions and 386 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG/release-notes-v0.7.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## v0.7.3



## Bugs
- fix: Builds set to auto not getting triggered (#5925)
- fix: User Rbac Fixes (#5940)
4 changes: 4 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import (
security2 "github.com/devtron-labs/devtron/internal/sql/repository/security"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/app/dbMigration"
"github.com/devtron-labs/devtron/pkg/app/status"
"github.com/devtron-labs/devtron/pkg/appClone"
"github.com/devtron-labs/devtron/pkg/appClone/batch"
Expand Down Expand Up @@ -1005,6 +1006,9 @@ func InitializeApp() (*App, error) {

repocreds.NewServiceClientImpl,
wire.Bind(new(repocreds.ServiceClient), new(*repocreds.ServiceClientImpl)),

dbMigration.NewDbMigrationServiceImpl,
wire.Bind(new(dbMigration.DbMigration), new(*dbMigration.DbMigrationServiceImpl)),
)
return &App{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1337,17 +1337,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
Binary file added assets/hadolint-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions charts/devtron/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: devtron-operator
appVersion: 0.7.2
appVersion: 0.7.3
description: Chart to configure and install Devtron. Devtron is a Kubernetes Orchestration system.
keywords:
- Devtron
Expand All @@ -11,7 +11,7 @@ keywords:
- argocd
- Hyperion
engine: gotpl
version: 0.22.74
version: 0.22.75
sources:
- https://github.com/devtron-labs/charts
dependencies:
Expand Down
6 changes: 3 additions & 3 deletions charts/devtron/devtron-bom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ global:
containerRegistry: "quay.io/devtron"
extraManifests: []
installer:
release: "v0.7.2"
release: "v0.7.3"
registry: ""
image: "inception"
tag: "473deaa4-185-21582"
Expand Down Expand Up @@ -38,8 +38,8 @@ components:
imagePullPolicy: IfNotPresent
devtron:
registry: ""
image: "hyperion:3f68456b-280-25566"
cicdImage: "devtron:3f68456b-434-25567"
image: "hyperion:e17c52eb-280-25812"
cicdImage: "devtron:e17c52eb-434-25813"
imagePullPolicy: IfNotPresent
customOverrides: {}
ciRunner:
Expand Down
6 changes: 3 additions & 3 deletions charts/devtron/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ global:
extraManifests: []
installer:
repo: "devtron-labs/devtron"
release: "v0.7.2"
release: "v0.7.3"
registry: ""
image: inception
tag: 473deaa4-185-21582
Expand Down Expand Up @@ -81,8 +81,8 @@ components:
imagePullPolicy: IfNotPresent
devtron:
registry: ""
image: "hyperion:3f68456b-280-25566"
cicdImage: "devtron:3f68456b-434-25567"
image: "hyperion:e17c52eb-280-25812"
cicdImage: "devtron:e17c52eb-434-25813"
imagePullPolicy: IfNotPresent
customOverrides: {}
serviceMonitor:
Expand Down
8 changes: 8 additions & 0 deletions client/telemetry/TelemetryEventClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ func (impl *TelemetryEventClientImpl) SendTelemetryDashboardAccessEvent() error
return err
}
cm, err := impl.K8sUtil.GetConfigMap(impl.aCDAuthConfig.ACDConfigMapNamespace, DevtronUniqueClientIdConfigMap, client)
if err != nil {
impl.logger.Errorw("DashboardAccessed EventForTelemetry,failed to get DevtronUniqueClientIdConfigMap", "error", err)
return err
}
datamap := cm.Data

accessEventValue, installEventKeyExists := datamap[UIEventKey]
Expand Down Expand Up @@ -667,6 +671,10 @@ func (impl *TelemetryEventClientImpl) SendTelemetryDashboardLoggedInEvent() erro
return err
}
cm, err := impl.K8sUtil.GetConfigMap(impl.aCDAuthConfig.ACDConfigMapNamespace, DevtronUniqueClientIdConfigMap, client)
if err != nil {
impl.logger.Errorw("DashboardLoggedIn EventForTelemetry,failed to get DevtronUniqueClientIdConfigMap", "error", err)
return err
}
datamap := cm.Data

accessEventValue, installEventKeyExists := datamap[UIEventKey]
Expand Down
4 changes: 4 additions & 0 deletions cmd/external-app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
security2 "github.com/devtron-labs/devtron/internal/sql/repository/security"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/app/dbMigration"
repository4 "github.com/devtron-labs/devtron/pkg/appStore/chartGroup/repository"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/EAMode"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deployment"
Expand Down Expand Up @@ -253,6 +254,9 @@ func InitializeApp() (*App, error) {

argoRepositoryCreds.NewRepositorySecret,
wire.Bind(new(argoRepositoryCreds.RepositorySecret), new(*argoRepositoryCreds.RepositorySecretImpl)),

dbMigration.NewDbMigrationServiceImpl,
wire.Bind(new(dbMigration.DbMigration), new(*dbMigration.DbMigrationServiceImpl)),
)
return &App{}, nil
}
6 changes: 4 additions & 2 deletions cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 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,14 @@ type CiArtifact struct {
sql.AuditLog
}

func (artifact *CiArtifact) ExtractImageRepoAndTag() (repo string, tag string, err error) {
imageMetadata, err := util.ExtractImageRepoAndTag(artifact.Image)
if err != nil {
return "", "", err
}
return imageMetadata.Repo, imageMetadata.Tag, nil
}

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
79 changes: 13 additions & 66 deletions internal/sql/repository/app/AppRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type AppRepository interface {
UpdateWithTxn(app *App, tx *pg.Tx) error
SetDescription(id int, description string, userId int32) error
FindActiveByName(appName string) (pipelineGroup *App, err error)
FindAllActiveByName(appName string) ([]*App, error)
FindAppIdByName(appName string) (int, error)

FindJobByDisplayName(appName string) (pipelineGroup *App, err error)
Expand Down Expand Up @@ -134,35 +135,24 @@ func (repo AppRepositoryImpl) SetDescription(id int, description string, userId
}

func (repo AppRepositoryImpl) FindActiveByName(appName string) (*App, error) {
pipelineGroup := &App{}
err := repo.dbConnection.
Model(pipelineGroup).
Where("app_name = ?", appName).
Where("active = ?", true).
Order("id DESC").Limit(1).
Select()
return pipelineGroup, err
}

func (repo AppRepositoryImpl) FindAllActiveByName(appName string) ([]*App, error) {
var apps []*App
err := repo.dbConnection.
Model(&apps).
Where("app_name = ?", appName).
Where("active = ?", true).
Order("id DESC").
Select()
if len(apps) == 1 {
return apps[0], nil
} else if len(apps) > 1 {
isHelmApp := true
for _, app := range apps {
if app.AppType != helper.ChartStoreApp && app.AppType != helper.ExternalChartStoreApp {
isHelmApp = false
break
}
}
if isHelmApp {
err := repo.fixMultipleHelmAppsWithSameName(appName)
if err != nil {
repo.logger.Errorw("error in fixing duplicate helm apps with same name")
return nil, err
}
}
return apps[0], nil
} else {
err = pg.ErrNoRows
}
return nil, err
return apps, err
}

func (repo AppRepositoryImpl) FindAppIdByName(appName string) (int, error) {
Expand Down Expand Up @@ -351,52 +341,9 @@ func (repo AppRepositoryImpl) FindAppAndProjectByAppName(appName string) (*App,
Where("app.app_name = ?", appName).
Where("app.active=?", true).
Select()

if err == pg.ErrMultiRows && (app.AppType == helper.ChartStoreApp || app.AppType == helper.ExternalChartStoreApp) {
// this case can arise in helms apps only

err := repo.fixMultipleHelmAppsWithSameName(appName)
if err != nil {
repo.logger.Errorw("error in fixing duplicate helm apps with same name")
return nil, err
}

err = repo.dbConnection.Model(app).Column("Team").
Where("app.app_name = ?", appName).
Where("app.active=?", true).
Select()
if err != nil {
repo.logger.Errorw("error in fetching apps by name", "appName", appName, "err", err)
return nil, err
}
}
return app, err
}

func (repo AppRepositoryImpl) fixMultipleHelmAppsWithSameName(appName string) error {
// updating installed apps setting app_id = max app_id
installAppUpdateQuery := `update installed_apps set
app_id=(select max(id) as id from app where app_name = ?)
where app_id in (select id from app where app_name= ? )`

_, err := repo.dbConnection.Exec(installAppUpdateQuery, appName, appName)
if err != nil {
repo.logger.Errorw("error in updating maxAppId in installedApps", "appName", appName, "err", err)
return err
}

maxAppIdQuery := repo.dbConnection.Model((*App)(nil)).ColumnExpr("max(id)").
Where("app_name = ? ", appName).
Where("active = ? ", true)

// deleting all apps other than app with max id
_, err = repo.dbConnection.Model((*App)(nil)).
Set("active = ?", false).Set("updated_by = ?", SYSTEM_USER_ID).Set("updated_on = ?", time.Now()).
Where("id not in (?) ", maxAppIdQuery).Update()

return nil
}

func (repo AppRepositoryImpl) FindAllMatchesByAppName(appName string, appType helper.AppType) ([]*App, error) {
var apps []*App
var err error
Expand Down
2 changes: 1 addition & 1 deletion manifests/install/devtron-installer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
name: installer-devtron
namespace: devtroncd
spec:
url: https://raw.githubusercontent.com/devtron-labs/devtron/v0.7.2/manifests/installation-script
url: https://raw.githubusercontent.com/devtron-labs/devtron/v0.7.3/manifests/installation-script
2 changes: 1 addition & 1 deletion manifests/installation-script
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LTAG="v0.7.2";
LTAG="v0.7.3";
REPO_RAW_URL="https://raw.githubusercontent.com/devtron-labs/devtron/";

log("executed devtron setup installation");
2 changes: 1 addition & 1 deletion manifests/release.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
stable -1 v0.7.2
stable -1 v0.7.3
2 changes: 1 addition & 1 deletion manifests/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.7.1
v0.7.3
2 changes: 1 addition & 1 deletion manifests/yamls/devtron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ spec:
runAsUser: 1000
containers:
- name: devtron
image: "quay.io/devtron/devtron:b5a2f8ba-434-25563"
image: "quay.io/devtron/devtron:0b51ad37-434-25810"
securityContext:
allowPrivilegeEscalation: false
runAsUser: 1000
Expand Down
Loading

0 comments on commit fcfa897

Please sign in to comment.