Skip to content

Commit

Permalink
Merge pull request #6027 from devtron-labs/release-candidate-v0.21.0
Browse files Browse the repository at this point in the history
release: Release candidate v0.21.0
  • Loading branch information
vikramdevtron authored Oct 24, 2024
2 parents 78709a3 + 6d7f925 commit fb1cbf5
Show file tree
Hide file tree
Showing 203 changed files with 22,638 additions and 346 deletions.
12 changes: 10 additions & 2 deletions api/restHandler/DeploymentConfigurationRestHandler.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package restHandler

import (
"context"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/configDiff"
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/schema"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
"net/http"
"time"
)

type DeploymentConfigurationRestHandler interface {
Expand Down Expand Up @@ -88,6 +91,7 @@ func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.Resp
return
}

configDataQueryParams.UserId = userId
//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACName(configDataQueryParams.AppName)
Expand All @@ -97,8 +101,12 @@ func (handler *DeploymentConfigurationRestHandlerImpl) GetConfigData(w http.Resp
return
}
//RBAC END

res, err := handler.deploymentConfigurationService.GetAllConfigData(r.Context(), configDataQueryParams)
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*")
userHasAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object)
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
defer cancel()
ctx = util2.SetSuperAdminInContext(ctx, isSuperAdmin)
res, err := handler.deploymentConfigurationService.GetAllConfigData(ctx, configDataQueryParams, userHasAdminAccess)
if err != nil {
handler.logger.Errorw("service err, GetAllConfigData ", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1562,12 +1562,16 @@ func (handler *PipelineConfigRestHandlerImpl) CancelWorkflow(w http.ResponseWrit
return
}
var forceAbort bool
forceAbort, err = strconv.ParseBool(queryVars.Get("forceAbort"))
if err != nil {
handler.Logger.Errorw("request err, CancelWorkflow", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
forceAbortQueryParam := queryVars.Get("forceAbort")
if len(forceAbortQueryParam) > 0 {
forceAbort, err = strconv.ParseBool(forceAbortQueryParam)
if err != nil {
handler.Logger.Errorw("request err, CancelWorkflow", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}

handler.Logger.Infow("request payload, CancelWorkflow", "workflowId", workflowId, "pipelineId", pipelineId)

ciPipeline, err := handler.ciPipelineRepository.FindById(pipelineId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,16 @@ func (handler *PipelineConfigRestHandlerImpl) CancelStage(w http.ResponseWriter,
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
var forceAbort bool
forceAbortQueryParam := r.URL.Query().Get("forceAbort")
if len(forceAbortQueryParam) > 0 {
forceAbort, err = strconv.ParseBool(forceAbortQueryParam)
if err != nil {
handler.Logger.Errorw("request err, CancelWorkflow", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
handler.Logger.Infow("request payload, CancelStage", "pipelineId", pipelineId, "workflowRunnerId", workflowRunnerId)

//RBAC
Expand All @@ -2082,7 +2092,7 @@ func (handler *PipelineConfigRestHandlerImpl) CancelStage(w http.ResponseWriter,
}
//RBAC

resp, err := handler.cdHandler.CancelStage(workflowRunnerId, userId)
resp, err := handler.cdHandler.CancelStage(workflowRunnerId, forceAbort, userId)
if err != nil {
handler.Logger.Errorw("service err, CancelStage", "err", err, "pipelineId", pipelineId, "workflowRunnerId", workflowRunnerId)
if util.IsErrNoRows(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ func (handler PipelineTriggerRestHandlerImpl) OverrideConfig(w http.ResponseWrit
triggerContext := bean3.TriggerContext{
Context: ctx,
}
mergeResp, err := handler.cdTriggerService.ManualCdTrigger(triggerContext, &overrideRequest)
mergeResp, helmPackageName, err := handler.cdTriggerService.ManualCdTrigger(triggerContext, &overrideRequest)
span.End()
if err != nil {
handler.logger.Errorw("request err, OverrideConfig", "err", err, "payload", overrideRequest)
common.WriteJsonResp(w, err, err.Error(), http.StatusInternalServerError)
return
}
res := map[string]interface{}{"releaseId": mergeResp}
res := map[string]interface{}{"releaseId": mergeResp, "helmPackageName": helmPackageName}
common.WriteJsonResp(w, err, res, http.StatusOK)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect

replace (
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.10
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241010131105-e2c23f9c80da
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
k8s.io/api => k8s.io/api v0.29.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ github.com/devtron-labs/argo-workflows/v3 v3.5.10 h1:6rxQOesOzDz6SgQCMDQNHaehsKF
github.com/devtron-labs/argo-workflows/v3 v3.5.10/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8 h1:2+Q7Jdhpo/uMiaQiZZzAh+ZX7wEJIFuMFG6DEiMuo64=
github.com/devtron-labs/authenticator v0.4.35-0.20240809073103-6e11da8083f8/go.mod h1:702R6WIf5y9UzKGoCGxQ+x3l5Ws+l0fXg2xlCpSGFZI=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241010131105-e2c23f9c80da h1:vC6SMz6BM1doN+ZBGiDGyERJ/LphFQi5+Ab/YQkNJVo=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241010131105-e2c23f9c80da/go.mod h1:KpKnF4OSpQNDJmb4wVZq3Za88ePBw4xec2GOAGRm5UQ=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136 h1:rNGxjU5L6NvObxGMt0+vNFmjkqstm7zDASiS+pakrgQ=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20241024135802-b4888f54a136/go.mod h1:KpKnF4OSpQNDJmb4wVZq3Za88ePBw4xec2GOAGRm5UQ=
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=
Expand Down
3 changes: 2 additions & 1 deletion internal/sql/repository/DeploymentTemplateRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DeploymentTemplateComparisonMetadata struct {
EnvironmentId int `json:"environmentId,omitempty"`
EnvironmentName string `json:"environmentName,omitempty"`
DeploymentTemplateHistoryId int `json:"deploymentTemplateHistoryId,omitempty"`
WfrId int `json:"wfrId,omitempty"`
StartedOn *time.Time `json:"startedOn,omitempty"`
FinishedOn *time.Time `json:"finishedOn,omitempty"`
Status string `json:"status,omitempty"`
Expand Down Expand Up @@ -69,7 +70,7 @@ func (impl DeploymentTemplateRepositoryImpl) FetchDeploymentHistoryWithChartRefs
limit := 15

query := "select p.id as pipeline_id, dth.id as deployment_template_history_id," +
" wfr.finished_on, wfr.status, c.chart_ref_id, c.chart_version FROM cd_workflow_runner wfr" +
" wfr.id as wfr_id, wfr.finished_on, wfr.status, c.chart_ref_id, c.chart_version FROM cd_workflow_runner wfr" +
" JOIN cd_workflow wf ON wf.id = wfr.cd_workflow_id JOIN pipeline p ON p.id = wf.pipeline_id" +
" JOIN deployment_template_history dth ON dth.deployed_on = wfr.started_on " +
"JOIN pipeline_config_override pco ON pco.cd_workflow_id = wf.id " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,10 @@ func (impl *CdWorkflowRepositoryImpl) GetLatestTriggersOfHelmPipelinesStuckInNon
Where("cd_workflow_runner.cd_workflow_id in"+
" (SELECT max(cd_workflow.id) as id from cd_workflow"+
" INNER JOIN cd_workflow_runner on cd_workflow.id = cd_workflow_runner.cd_workflow_id"+
" WHERE cd_workflow_runner.status != ?"+
" WHERE cd_workflow_runner.workflow_type = ? "+
" AND cd_workflow_runner.status != ?"+
" GROUP BY cd_workflow.pipeline_id"+
" ORDER BY cd_workflow.pipeline_id desc)", cdWorkflow.WorkflowInQueue).
" ORDER BY cd_workflow.pipeline_id desc)", apiBean.CD_WORKFLOW_TYPE_DEPLOY, cdWorkflow.WorkflowInQueue).
Where("(cd_workflow__pipeline.deployment_app_type=? or dc.deployment_app_type=?)", util.PIPELINE_DEPLOYMENT_TYPE_HELM, util.PIPELINE_DEPLOYMENT_TYPE_HELM).
Where("cd_workflow_runner.started_on > NOW() - INTERVAL '? hours'", getPipelineDeployedWithinHours).
Where("cd_workflow__pipeline.deleted=?", false).
Expand Down
3 changes: 3 additions & 0 deletions pkg/bean/configSecretData.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type SecretList struct {
ConfigData []*ConfigData `json:"secrets"`
}

// there is an adapter written in pkg/bean folder to convert below ConfigData struct to pipeline/bean's ConfigData

// TODO refactoring: duplicate struct of ConfigData in ConfigMapBean.go
type ConfigData struct {
Name string `json:"name"`
Expand All @@ -49,6 +51,7 @@ type ConfigData struct {
SubPath bool `json:"subPath"`
ESOSubPath []string `json:"esoSubPath"`
FilePermission string `json:"filePermission"`
Overridden bool `json:"overridden"`
}

func (c *ConfigData) IsESOExternalSecretType() bool {
Expand Down
12 changes: 12 additions & 0 deletions pkg/cluster/repository/EnvironmentRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type EnvironmentRepository interface {
FindAllActiveWithFilter() ([]*Environment, error)
FindEnvClusterInfosByIds([]int) ([]*EnvCluserInfo, error)
FindEnvLinkedWithCiPipelines(externalCi bool, ciPipelineIds []int) ([]*Environment, error)
FindEnvByNameWithClusterDetails(envName string) (*Environment, error)
}

func NewEnvironmentRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger, appStatusRepository appStatus.AppStatusRepository) *EnvironmentRepositoryImpl {
Expand Down Expand Up @@ -160,6 +161,17 @@ func (repositoryImpl EnvironmentRepositoryImpl) FindByName(name string) (*Enviro
return environment, err
}

func (repositoryImpl EnvironmentRepositoryImpl) FindEnvByNameWithClusterDetails(envName string) (*Environment, error) {
environment := &Environment{}
err := repositoryImpl.dbConnection.
Model(environment).
Column("environment.*", "Cluster").
Where("environment.environment_name = ?", envName).
Where("environment.active = ?", true).
Select()
return environment, err
}

func (repositoryImpl EnvironmentRepositoryImpl) FindIdByName(name string) (int, error) {
environment := &Environment{}
err := repositoryImpl.dbConnection.
Expand Down
Loading

0 comments on commit fb1cbf5

Please sign in to comment.