Skip to content

Commit

Permalink
fix: handle argo delete event for charts and added socket config (#4471)
Browse files Browse the repository at this point in the history
* added config for socket handler

* added config for socket handler

* added check for helm delete nats flow

* fix

* added info log

* pr comments
  • Loading branch information
subhashish-devtron authored Dec 28, 2023
1 parent 6b596a8 commit e09ddae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
17 changes: 15 additions & 2 deletions api/router/pubsub/ApplicationStatusHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (impl *ApplicationStatusHandlerImpl) Subscribe() error {

func (impl *ApplicationStatusHandlerImpl) SubscribeDeleteStatus() error {
callback := func(msg *model.PubSubMsg) {
impl.logger.Debug("received app delete event")

impl.logger.Debugw("APP_STATUS_DELETE_REQ", "stage", "raw", "data", msg.Data)
applicationDetail := ApplicationDetail{}
Expand All @@ -185,9 +184,11 @@ func (impl *ApplicationStatusHandlerImpl) SubscribeDeleteStatus() error {
if app == nil {
return
}
impl.logger.Infow("argo delete event received", "appName", app.Name, "namespace", app.Namespace, "deleteTimestamp", app.DeletionTimestamp)

err = impl.updateArgoAppDeleteStatus(app)
if err != nil {
impl.logger.Errorw("error in updating pipeline delete status", "err", err)
impl.logger.Errorw("error in updating pipeline delete status", "err", err, "appName", app.Name)
}
}
err := impl.pubsubClient.Subscribe(pubsub.APPLICATION_STATUS_DELETE_TOPIC, callback)
Expand Down Expand Up @@ -221,6 +222,18 @@ func (impl *ApplicationStatusHandlerImpl) updateArgoAppDeleteStatus(app *v1alpha
impl.logger.Errorw("error in fetching installed app by git hash from installed app repository", "err", err)
return err
}

// Check to ensure that delete request for app was received
installedApp, err := impl.installedAppService.CheckAppExistsByInstalledAppId(model.InstalledAppId)
if err == pg.ErrNoRows {
impl.logger.Errorw("App not found in database", "installedAppId", model.InstalledAppId, "err", err)
return fmt.Errorf("app not found in database %s", err)
} else if installedApp.DeploymentAppDeleteRequest == false {
//TODO 4465 remove app from log after final RCA
impl.logger.Infow("Deployment delete not requested for app, not deleting app from DB", "appName", app.Name, "app", app)
return nil
}

deleteRequest := &appStoreBean.InstallAppVersionDTO{}
deleteRequest.ForceDelete = false
deleteRequest.NonCascadeDelete = false
Expand Down
19 changes: 18 additions & 1 deletion pkg/terminal/terminalSesion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/common-lib/utils/k8s"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/cluster/repository"
Expand All @@ -30,6 +31,7 @@ import (
"net/http"
"strings"
"sync"
"time"

"gopkg.in/igm/sockjs-go.v3/sockjs"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -217,9 +219,24 @@ func handleTerminalSession(session sockjs.Session) {
terminalSession.bound <- nil
}

type SocketConfig struct {
SocketHeartbeatSeconds int `env:"SOCKET_HEARTBEAT_SECONDS" envDefault:"25"`
SocketDisconnectDelay int `env:"SOCKET_DISCONNECT_DELAY_SECONDS" envDefault:"5"`
}

var cfg *SocketConfig

// CreateAttachHandler is called from main for /api/sockjs
func CreateAttachHandler(path string) http.Handler {
return sockjs.NewHandler(path, sockjs.DefaultOptions, handleTerminalSession)
if cfg == nil {
cfg = &SocketConfig{}
env.Parse(cfg)
}

opts := sockjs.DefaultOptions
opts.HeartbeatDelay = time.Duration(cfg.SocketHeartbeatSeconds) * time.Second
opts.DisconnectDelay = time.Duration(cfg.SocketDisconnectDelay) * time.Second
return sockjs.NewHandler(path, opts, handleTerminalSession)
}

// startProcess is called by handleAttach
Expand Down

0 comments on commit e09ddae

Please sign in to comment.