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: Bugathon DT-19 version-2 fixes #4105

Merged
merged 20 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b274420
setting scan enabled flag (#3925)
Shivam-nagar23 Sep 20, 2023
0c25485
fix: revert app and workflow creation in case of error (#3923)
Ashish-devtron Sep 20, 2023
6fee8b7
check for update access while updating (#3936)
Ashish-devtron Sep 20, 2023
98dd439
fix: cloning app with seq cd pipeline fix (#3926)
prakash100198 Sep 22, 2023
1be49e3
soft delete chart-group deployment
ashishdevtron Sep 22, 2023
328a8ff
Merge remote-tracking branch 'origin/stable-dt19-v2' into running-dep…
ashishdevtron Sep 22, 2023
a57e73d
fix: Security Pagination Count wrong fix (#3950)
Shivam-nagar23 Sep 22, 2023
328c267
Revert "soft delete chart-group deployment"
ashishdevtron Sep 22, 2023
605a289
fix: Base configmap get more precedence than override (#3940)
adi6859 Sep 22, 2023
baa3700
fix: Pass/Failure Condition is not working as expected in pre build s…
adi6859 Sep 22, 2023
74e1a25
fix: data not flowing into table ImageScanDeployInfo for triggers (#3…
subhashish-devtron Sep 22, 2023
44ebe96
removed virtual environments from unnecessary places (#3960)
Ash-exp Sep 25, 2023
7b3bbfb
soft delete chart-group deployment (#3958)
ashishdevtron Sep 25, 2023
e3f07e4
update wire injection
ashishdevtron Sep 27, 2023
fa7e9a6
chore: main merge
Ash-exp Sep 29, 2023
ff71ea5
main merge
adi6859 Oct 4, 2023
4ae3a64
main sync
prakash100198 Oct 12, 2023
88ad370
Merge branch 'main' into stable-dt19-v2-oss
prakash100198 Oct 13, 2023
eb74d4b
main sync
prakash100198 Oct 16, 2023
14c6c81
sql script number change
prakash100198 Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/bean/ConfigMapAndSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bean

import (
"encoding/json"
"github.com/devtron-labs/devtron/util"
)

type ConfigMapRootJson struct {
Expand Down Expand Up @@ -61,3 +62,10 @@ func (configSecret ConfigSecretMap) GetDataMap() (map[string]string, error) {
err := json.Unmarshal(configSecret.Data, &datamap)
return datamap, err
}
func (configSecretJson ConfigSecretJson) GetDereferencedSecrets() []ConfigSecretMap {
return util.GetDeReferencedArray(configSecretJson.Secrets)
}

func (configSecretJson *ConfigSecretJson) SetReferencedSecrets(secrets []ConfigSecretMap) {
configSecretJson.Secrets = util.GetReferencedArray(secrets)
}
5 changes: 2 additions & 3 deletions api/k8s/capacity/k8sCapacityRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (handler *K8sCapacityRestHandlerImpl) GetClusterListRaw(w http.ResponseWrit
return
}
token := r.Header.Get("token")
clusters, err := handler.clusterService.FindAll()
clusters, err := handler.clusterService.FindAllExceptVirtual()
if err != nil {
handler.logger.Errorw("error in getting all clusters", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand All @@ -83,7 +83,6 @@ func (handler *K8sCapacityRestHandlerImpl) GetClusterListRaw(w http.ResponseWrit
Id: cluster.Id,
Name: cluster.ClusterName,
ErrorInConnection: cluster.ErrorInConnecting,
IsVirtualCluster: cluster.IsVirtualCluster,
}
clusterDetailList = append(clusterDetailList, clusterDetail)
}
Expand All @@ -102,7 +101,7 @@ func (handler *K8sCapacityRestHandlerImpl) GetClusterListWithDetail(w http.Respo
return
}
token := r.Header.Get("token")
clusters, err := handler.clusterService.FindAll()
clusters, err := handler.clusterService.FindAllExceptVirtual()
if err != nil {
handler.logger.Errorw("error in getting all clusters", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
96 changes: 61 additions & 35 deletions api/restHandler/CoreAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,45 +1192,50 @@ func (handler CoreAppRestHandlerImpl) deleteApp(ctx context.Context, appId int,

// delete all CD pipelines for app starts
cdPipelines, err := handler.pipelineBuilder.GetCdPipelinesForApp(appId)
if err != nil {
if err != nil && err != pg.ErrNoRows {
handler.logger.Errorw("service err, GetCdPipelines in DeleteApp", "err", err, "appId", appId)
return err
}

for _, cdPipeline := range cdPipelines.Pipelines {
cdPipelineDeleteRequest := &bean.CDPatchRequest{
AppId: appId,
UserId: userId,
Action: bean.CD_DELETE,
ForceDelete: true,
NonCascadeDelete: false,
Pipeline: cdPipeline,
}
_, err = handler.pipelineBuilder.PatchCdPipelines(cdPipelineDeleteRequest, ctx)
if err != nil {
handler.logger.Errorw("err in deleting cd pipeline in DeleteApp", "err", err, "payload", cdPipelineDeleteRequest)
return err
if err != pg.ErrNoRows {
for _, cdPipeline := range cdPipelines.Pipelines {
cdPipelineDeleteRequest := &bean.CDPatchRequest{
AppId: appId,
UserId: userId,
Action: bean.CD_DELETE,
ForceDelete: true,
NonCascadeDelete: false,
Pipeline: cdPipeline,
}
_, err = handler.pipelineBuilder.PatchCdPipelines(cdPipelineDeleteRequest, ctx)
if err != nil {
handler.logger.Errorw("err in deleting cd pipeline in DeleteApp", "err", err, "payload", cdPipelineDeleteRequest)
return err
}
}

}
// delete all CD pipelines for app ends

// delete all CI pipelines for app starts
ciPipelines, err := handler.pipelineBuilder.GetCiPipeline(appId)
if err != nil {
if err != nil && err != pg.ErrNoRows {
handler.logger.Errorw("service err, GetCiPipelines in DeleteApp", "err", err, "appId", appId)
return err
}
for _, ciPipeline := range ciPipelines.CiPipelines {
ciPipelineDeleteRequest := &bean.CiPatchRequest{
AppId: appId,
UserId: userId,
Action: bean.DELETE,
CiPipeline: ciPipeline,
}
_, err := handler.pipelineBuilder.PatchCiPipeline(ciPipelineDeleteRequest)
if err != nil {
handler.logger.Errorw("err in deleting ci pipeline in DeleteApp", "err", err, "payload", ciPipelineDeleteRequest)
return err
if err != pg.ErrNoRows {

for _, ciPipeline := range ciPipelines.CiPipelines {
ciPipelineDeleteRequest := &bean.CiPatchRequest{
AppId: appId,
UserId: userId,
Action: bean.DELETE,
CiPipeline: ciPipeline,
}
_, err := handler.pipelineBuilder.PatchCiPipeline(ciPipelineDeleteRequest)
if err != nil {
handler.logger.Errorw("err in deleting ci pipeline in DeleteApp", "err", err, "payload", ciPipelineDeleteRequest)
return err
}
}
}
// delete all CI pipelines for app ends
Expand Down Expand Up @@ -1551,16 +1556,37 @@ func (handler CoreAppRestHandlerImpl) createWorkflows(ctx context.Context, appId
//Creating workflow ends

//Creating CI pipeline starts
ciPipelineId, err := handler.createCiPipeline(appId, userId, workflowId, workflow.CiPipeline)
ciPipeline, err := handler.createCiPipeline(appId, userId, workflowId, workflow.CiPipeline)
if err != nil {
err1 := handler.appWorkflowService.DeleteAppWorkflow(workflowId, userId)
if err1 != nil {
handler.logger.Errorw("service err, DeleteAppWorkflow ")
return err1, http.StatusInternalServerError
}
handler.logger.Errorw("err in saving ci pipelines", err, "appId", appId)
return err, http.StatusInternalServerError
}
//Creating CI pipeline ends

//Creating CD pipeline starts
err = handler.createCdPipelines(ctx, appId, userId, workflowId, ciPipelineId, workflow.CdPipelines)
err = handler.createCdPipelines(ctx, appId, userId, workflowId, ciPipeline.Id, workflow.CdPipelines)
if err != nil {
ciPipelineDeleteRequest := &bean.CiPatchRequest{
AppId: appId,
UserId: userId,
Action: bean.DELETE,
CiPipeline: ciPipeline,
}
_, err1 := handler.pipelineBuilder.PatchCiPipeline(ciPipelineDeleteRequest)
if err1 != nil {
handler.logger.Errorw("err in deleting ci pipeline in DeleteApp", "err", err, "payload", ciPipelineDeleteRequest)
return err1, http.StatusInternalServerError
}
err1 = handler.appWorkflowService.DeleteAppWorkflow(workflowId, userId)
if err1 != nil {
handler.logger.Errorw("service err, DeleteAppWorkflow ")
return err1, http.StatusInternalServerError
}
handler.logger.Errorw("err in saving cd pipelines", err, "appId", appId)
return err, http.StatusInternalServerError
}
Expand Down Expand Up @@ -1590,13 +1616,13 @@ func (handler CoreAppRestHandlerImpl) createWorkflowInDb(workflowName string, ap
return savedAppWf.Id, nil
}

func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32, workflowId int, ciPipelineData *appBean.CiPipelineDetails) (int, error) {
func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32, workflowId int, ciPipelineData *appBean.CiPipelineDetails) (*bean.CiPipeline, error) {

// if ci pipeline is of external type, then throw error as we are not supporting it as of now
if ciPipelineData.ParentCiPipeline == 0 && ciPipelineData.ParentAppId == 0 && ciPipelineData.IsExternal {
err := errors.New("external ci pipeline creation is not supported yet")
handler.logger.Error("external ci pipeline creation is not supported yet")
return 0, err
return nil, err
}

// build ci pipeline materials starts
Expand All @@ -1613,13 +1639,13 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
}
if err != nil {
handler.logger.Errorw("service err, FindByAppIdAndCheckoutPath in CreateWorkflows", "err", err, "appId", appId)
return 0, err
return nil, err
}

if gitMaterial == nil {
err = errors.New("gitMaterial is nil")
handler.logger.Errorw("gitMaterial is nil", "checkoutPath", ciMaterial.CheckoutPath)
return 0, err
return nil, err
}

ciMaterialRequest := &bean.CiMaterial{
Expand Down Expand Up @@ -1664,10 +1690,10 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
res, err := handler.pipelineBuilder.PatchCiPipeline(ciPipelineRequest)
if err != nil {
handler.logger.Errorw("service err, PatchCiPipelines", "err", err, "appId", appId)
return 0, err
return nil, err
}

return res.CiPipelines[0].Id, nil
return res.CiPipelines[0], nil
}

func (handler CoreAppRestHandlerImpl) createCdPipelines(ctx context.Context, appId int, userId int32, workflowId int, ciPipelineId int, cdPipelines []*appBean.CdPipelineDetails) error {
Expand Down
7 changes: 7 additions & 0 deletions cmd/external-app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/app"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
repository3 "github.com/devtron-labs/devtron/pkg/appStore/deployment/repository"
appStoreDeploymentTool "github.com/devtron-labs/devtron/pkg/appStore/deployment/tool"
appStoreDeploymentGitopsTool "github.com/devtron-labs/devtron/pkg/appStore/deployment/tool/gitops"
"github.com/devtron-labs/devtron/pkg/attributes"
Expand Down Expand Up @@ -199,6 +200,12 @@ func InitializeApp() (*App, error) {
wire.Bind(new(dockerRegistryRepository.DockerRegistryIpsConfigRepository), new(*dockerRegistryRepository.DockerRegistryIpsConfigRepositoryImpl)),
dockerRegistryRepository.NewOCIRegistryConfigRepositoryImpl,
wire.Bind(new(dockerRegistryRepository.OCIRegistryConfigRepository), new(*dockerRegistryRepository.OCIRegistryConfigRepositoryImpl)),

// chart group repository layer wire injection started
repository3.NewChartGroupDeploymentRepositoryImpl,
wire.Bind(new(repository3.ChartGroupDeploymentRepository), new(*repository3.ChartGroupDeploymentRepositoryImpl)),
// chart group repository layer wire injection ended

// end: docker registry wire set injection
)
return &App{}, nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/external-app/wire_gen.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type CiWorkflow struct {
CiBuildType string `sql:"ci_build_type"`
EnvironmentId int `sql:"environment_id"`
ReferenceCiWorkflowId int `sql:"ref_ci_workflow_id"`
ParentCiWorkFlowId int `sql:"parent_ci_workflow_id"`
ParentCiWorkFlowId int `sql:"parent_ci_workflow_id"`
CiPipeline *CiPipeline
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ func (impl ImageScanDeployInfoRepositoryImpl) FetchListingGroupByObject(size int
}

func (impl ImageScanDeployInfoRepositoryImpl) FetchByAppIdAndEnvId(appId int, envId int, objectType []string) (*ImageScanDeployInfo, error) {
var model ImageScanDeployInfo
err := impl.dbConnection.Model(&model).
var model *ImageScanDeployInfo
err := impl.dbConnection.Model(model).
Where("scan_object_meta_id = ?", appId).
Where("env_id = ?", envId).Where("object_type in (?)", pg.In(objectType)).
Order("created_on desc").Limit(1).
Select()
return &model, err
return model, err
}

func (impl ImageScanDeployInfoRepositoryImpl) FindByTypeMetaAndTypeId(scanObjectMetaId int, objectType string) (*ImageScanDeployInfo, error) {
Expand Down Expand Up @@ -185,7 +185,8 @@ 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 and info.image_scan_execution_history_id[1] != -1"
query = query + " LEFT JOIN app ap on ap.id = info.scan_object_meta_id and info.object_type='app' WHERE ap.active=true"
query = query + " AND 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