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

feat: Helm async deploy Devtron Apps #4045

Merged
merged 58 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a8b50fd
wip: refactored deployment code
Ash-exp Oct 9, 2023
091f113
feat: helm async install for devtron apps
Ash-exp Oct 9, 2023
e7802ee
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 9, 2023
6fbe666
updated: pubsub lib version
Ash-exp Oct 9, 2023
9786c0f
removed unnecessary comments
Ash-exp Oct 9, 2023
61968e9
removed: unnecessary code
Ash-exp Oct 10, 2023
2a76b77
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 10, 2023
0ba51de
feat: deployment cron updated
Ash-exp Oct 10, 2023
a88b62c
updated: review comments
Ash-exp Oct 10, 2023
11157af
refactored: deployment status cron job logic
Ash-exp Oct 11, 2023
bffcbb0
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 11, 2023
f1a9c55
updated: runner states for deployment
Ash-exp Oct 11, 2023
d9bb5d8
fixed: unable to update cdWorkflowRunner
Ash-exp Oct 11, 2023
63d9923
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 12, 2023
3023319
chore: main merge
Ash-exp Oct 12, 2023
9d06bfe
updated: cdWfr for gitops deployment
Ash-exp Oct 13, 2023
5217ce3
fixed: cdWfr skipped status list
Ash-exp Oct 13, 2023
cd88d1d
fixed: test file arguments
Ash-exp Oct 13, 2023
c433178
fixed: handled for event redelivery case
Ash-exp Oct 13, 2023
d8ebf23
used the constant
Ash-exp Oct 13, 2023
c3a46ba
handling for context deadline exceeded
Ash-exp Oct 13, 2023
0401195
updated: context deadline error expression
Ash-exp Oct 13, 2023
b59543b
handled: error in unmarshalling
Ash-exp Oct 13, 2023
a53ac2c
fixed: context deadline error in cdWfr
Ash-exp Oct 13, 2023
8c68538
handled: pending-install state
Ash-exp Oct 16, 2023
fed6eeb
chore: main merge
Ash-exp Oct 19, 2023
f69e92e
feat: helm install/upgrade with ctx
Ash-exp Oct 20, 2023
51c48c0
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 20, 2023
97d6c50
handling: nil pointer
Ash-exp Oct 20, 2023
b8f2b1a
updated: error handling
Ash-exp Oct 20, 2023
f83c55e
updated: error message
Ash-exp Oct 20, 2023
940ad76
fixed: updatePreviousDeploymentStatus handling
Ash-exp Oct 20, 2023
5e3ff18
fixed: updatePreviousDeploymentStatus handling
Ash-exp Oct 20, 2023
ea3af2d
feat: refactored
Ash-exp Oct 20, 2023
acfa3ec
chore: main merge
Ash-exp Oct 23, 2023
17fb50f
chore: main merge
Ash-exp Oct 25, 2023
8f74652
updated variable name
Ash-exp Oct 25, 2023
81b15ae
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 26, 2023
9dc6e25
updated default value for env
Ash-exp Oct 26, 2023
6cff43a
updated GetValuesOverrideForTrigger
Ash-exp Oct 26, 2023
2f7b842
updated GetValuesOverrideForTrigger
Ash-exp Oct 26, 2023
88018fd
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 26, 2023
5df6382
code review comments
kripanshdevtron Oct 30, 2023
ad53ee0
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 30, 2023
243ac2e
incorporated review suggestions
Ash-exp Oct 31, 2023
25f72d4
chore: main merge
Ash-exp Oct 31, 2023
aaad742
Merge branch 'main' into feat-async-install-devtron
Ash-exp Oct 31, 2023
f94a3fa
chore: removed unnecessary env flag
Ash-exp Oct 31, 2023
27c377b
handled: context deadline error
Ash-exp Oct 31, 2023
06f2256
fixed: migration
Ash-exp Oct 31, 2023
fc67c41
fixed: update status in progress
Ash-exp Oct 31, 2023
12560d0
fine-tuned and refactoring
Ash-exp Nov 1, 2023
93aacf9
chore: main merge
Ash-exp Nov 1, 2023
6ff5310
handling for hibernate app
Ash-exp Nov 1, 2023
5b81688
chore: main merge
Ash-exp Nov 16, 2023
0ec86ae
chore: main merge
Ash-exp Nov 16, 2023
add60a9
Merge branch 'main' into feat-async-install-devtron
Ash-exp Nov 20, 2023
115c62a
chore: main merge
Ash-exp Nov 21, 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
Prev Previous commit
Next Next commit
feat: deployment cron updated
  • Loading branch information
Ash-exp committed Oct 10, 2023
commit 0ba51de3f620eb08b566de16fa65e44b4d06a0a0
16 changes: 7 additions & 9 deletions api/helm-app/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
type HelmAppService interface {
ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool)
GetApplicationDetail(ctx context.Context, app *AppIdentifier) (*AppDetail, error)
GetApplicationStatus(ctx context.Context, app *AppIdentifier) (string, error)
GetApplicationAndReleaseStatus(ctx context.Context, app *AppIdentifier) (*AppStatus, error)
GetApplicationDetailWithFilter(ctx context.Context, app *AppIdentifier, resourceTreeFilter *ResourceTreeFilter) (*AppDetail, error)
HibernateApplication(ctx context.Context, app *AppIdentifier, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error)
UnHibernateApplication(ctx context.Context, app *AppIdentifier, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error)
Expand Down Expand Up @@ -274,8 +274,8 @@ func (impl *HelmAppServiceImpl) GetApplicationDetail(ctx context.Context, app *A
return impl.getApplicationDetail(ctx, app, nil)
}

func (impl *HelmAppServiceImpl) GetApplicationStatus(ctx context.Context, app *AppIdentifier) (string, error) {
return impl.getApplicationStatus(ctx, app)
func (impl *HelmAppServiceImpl) GetApplicationAndReleaseStatus(ctx context.Context, app *AppIdentifier) (*AppStatus, error) {
return impl.getApplicationAndReleaseStatus(ctx, app)
}

func (impl *HelmAppServiceImpl) GetApplicationDetailWithFilter(ctx context.Context, app *AppIdentifier, resourceTreeFilter *ResourceTreeFilter) (*AppDetail, error) {
Expand Down Expand Up @@ -318,12 +318,11 @@ func (impl *HelmAppServiceImpl) getApplicationDetail(ctx context.Context, app *A
return appdetail, err
}

func (impl *HelmAppServiceImpl) getApplicationStatus(ctx context.Context, app *AppIdentifier) (string, error) {
applicationStatus := ""
func (impl *HelmAppServiceImpl) getApplicationAndReleaseStatus(ctx context.Context, app *AppIdentifier) (*AppStatus, error) {
config, err := impl.GetClusterConf(app.ClusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return applicationStatus, err
return nil, err
}
req := &AppDetailRequest{
ClusterConfig: config,
Expand All @@ -333,10 +332,9 @@ func (impl *HelmAppServiceImpl) getApplicationStatus(ctx context.Context, app *A
appStatus, err := impl.helmAppClient.GetAppStatus(ctx, req)
if err != nil {
impl.logger.Errorw("error in fetching app status", "err", err)
return applicationStatus, err
return nil, err
}
applicationStatus = appStatus.ApplicationStatus
return applicationStatus, err
return appStatus, err
}

func (impl *HelmAppServiceImpl) GetDeploymentHistory(ctx context.Context, app *AppIdentifier) (*HelmAppDeploymentHistory, error) {
Expand Down
1,045 changes: 534 additions & 511 deletions api/helm-app/applist.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/helm-app/applist.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ message AppDetail{

message AppStatus{
string applicationStatus = 1;
string ReleaseStatus = 2;
google.protobuf.Timestamp LastDeployed = 3;
}

message ReleaseStatus {
Expand Down
103 changes: 40 additions & 63 deletions api/helm-app/applist_grpc.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/util/ErrorUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ func GetGRPCErrorDetailedMessage(err error) string {
if errStatus, ok := status.FromError(err); ok {
return errStatus.Message()
}
return ""
return err.Error()
}
39 changes: 25 additions & 14 deletions pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
resourceGroup2 "github.com/devtron-labs/devtron/pkg/resourceGroup"
serverBean "github.com/devtron-labs/devtron/pkg/server/bean"
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/devtron-labs/devtron/pkg/user"
util3 "github.com/devtron-labs/devtron/util"
Expand Down Expand Up @@ -460,26 +461,36 @@ func (impl *CdHandlerImpl) CheckHelmAppStatusPeriodicallyAndUpdateInDb(helmPipel
Namespace: wfr.CdWorkflow.Pipeline.Environment.Namespace,
ReleaseName: wfr.CdWorkflow.Pipeline.DeploymentAppName,
}
helmAppStatus, err := impl.helmAppService.GetApplicationStatus(context.Background(), appIdentifier)
helmInstalledDevtronApp, err := impl.helmAppService.GetApplicationAndReleaseStatus(context.Background(), appIdentifier)
if err != nil {
impl.Logger.Errorw("error in getting helm app release status ", "appIdentifier", appIdentifier, "err", err)
//return err
//skip this error and continue for next workflow status
impl.Logger.Warnw("found error, skipping helm apps status update for this trigger", "appIdentifier", appIdentifier, "err", err)

// Handle release not found errors
if !strings.Contains(err.Error(), "release: not found") {
if util.GetGRPCErrorDetailedMessage(err) != client.ErrReleaseNotFound {
//skip this error and continue for next workflow status
impl.Logger.Warnw("found error, skipping helm apps status update for this trigger", "appIdentifier", appIdentifier, "err", err)
continue
} else {
// If release not found, mark the deployment as failure
wfr.Status = pipelineConfig.WorkflowFailed
wfr.FinishedOn = time.Now()
}
}
if helmAppStatus == application.Healthy {
} else if helmInstalledDevtronApp.GetLastDeployed().AsTime().Before(wfr.StartedOn) {
//skip if there is no deployment after wfr.StartedOn and continue for next workflow status
impl.Logger.Warnw("release mismatched, skipping helm apps status update for this trigger", "appIdentifier", appIdentifier, "err", err)
continue
} else if helmInstalledDevtronApp.GetReleaseStatus() == serverBean.HelmReleaseStatusPendingInstall {
if time.Now().After(helmInstalledDevtronApp.GetLastDeployed().AsTime().Add(5 * time.Minute)) {
// If release status is in pending-install for more than 5 mins, then mark the deployment as failure
wfr.Status = pipelineConfig.WorkflowFailed
wfr.FinishedOn = time.Now()
} else {
wfr.Status = pipelineConfig.WorkflowInProgress
}
} else if helmInstalledDevtronApp.GetReleaseStatus() == serverBean.HelmReleaseStatusDeployed &&
helmInstalledDevtronApp.GetApplicationStatus() == application.Healthy {
// mark the deployment as succeed
wfr.Status = pipelineConfig.WorkflowSucceeded
wfr.FinishedOn = time.Now()

} else if err != nil && strings.Contains(err.Error(), "release: not found") {
// If release not found, mark the deployment as failure
wfr.Status = pipelineConfig.WorkflowFailed

} else {
wfr.Status = pipelineConfig.WorkflowInProgress
}
Expand All @@ -499,7 +510,7 @@ func (impl *CdHandlerImpl) CheckHelmAppStatusPeriodicallyAndUpdateInDb(helmPipel
}
util3.TriggerCDMetrics(cdMetrics, impl.config.ExposeCDMetrics)
impl.Logger.Infow("updated workflow runner status for helm app", "wfr", wfr)
if helmAppStatus == application.Healthy {
if wfr.Status == pipelineConfig.WorkflowSucceeded {
pipelineOverride, err := impl.pipelineOverrideRepository.FindLatestByCdWorkflowId(wfr.CdWorkflowId)
if err != nil {
impl.Logger.Errorw("error in getting latest pipeline override by cdWorkflowId", "err", err, "cdWorkflowId", wfr.CdWorkflowId)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/WorkflowDagExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ func (impl *WorkflowDagExecutorImpl) MarkCurrentDeploymentFailed(runner *pipelin
//update current WF with error status
impl.logger.Errorw("error in triggering cd WF, setting wf status as fail ", "wfId", runner.Id, "err", releaseErr)
runner.Status = pipelineConfig.WorkflowFailed
runner.Message = releaseErr.Error()
runner.Message = util.GetGRPCErrorDetailedMessage(releaseErr)
runner.FinishedOn = time.Now()
runner.UpdatedOn = time.Now()
runner.UpdatedBy = triggeredBy
Expand Down
Loading