Skip to content

fix: handle argo delete event for charts and added socket config #4471

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

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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