Skip to content

Commit 61c2f17

Browse files
Feat: Chart build history and status update (#1387)
* chart build history and its status update added * remove chart history older trigger,not required anymore * db migration added for version history for charts * values api for chart build history * version field fixed in chart history * resoponse modification review changes * fixes * auth added for history and history info api for charts * open api spec added for chart history api * review changes - fix * removed unused function from installed app repo * history response handling for no history found case * history id fix * wire changes values to app store * history info values yaml to json * fix * build history chart name fix replace to appstore from appname * added installedAppVersion Id in history response
1 parent 5743052 commit 61c2f17

18 files changed

+557
-104
lines changed

api/appStore/AppStoreDeploymentRestHandler.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type InstalledAppRestHandler interface {
5353
CheckAppExists(w http.ResponseWriter, r *http.Request)
5454
DefaultComponentInstallation(w http.ResponseWriter, r *http.Request)
5555
FetchAppDetailsForInstalledApp(w http.ResponseWriter, r *http.Request)
56+
GetDeploymentHistory(w http.ResponseWriter, r *http.Request)
57+
GetDeploymentHistoryValues(w http.ResponseWriter, r *http.Request)
5658
}
5759

5860
type InstalledAppRestHandlerImpl struct {
@@ -467,3 +469,73 @@ func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w htt
467469
}
468470
common.WriteJsonResp(w, err, appDetail, http.StatusOK)
469471
}
472+
473+
func (handler *InstalledAppRestHandlerImpl) GetDeploymentHistory(w http.ResponseWriter, r *http.Request) {
474+
vars := mux.Vars(r)
475+
installedAppId, err := strconv.Atoi(vars["installedAppId"])
476+
if err != nil {
477+
handler.Logger.Errorw("request err", "error", err, "installedAppId", installedAppId)
478+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
479+
return
480+
}
481+
token := r.Header.Get("token")
482+
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(installedAppId)
483+
if err != nil {
484+
handler.Logger.Errorw("service err, GetDeploymentHistoryValues", "err", err, "installedAppId", installedAppId)
485+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
486+
return
487+
}
488+
//rbac block starts from here
489+
object := handler.enforcerUtil.GetHelmObject(installedApp.AppId, installedApp.EnvironmentId)
490+
if ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object); !ok {
491+
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
492+
return
493+
}
494+
//rback block ends here
495+
response, err := handler.installedAppService.GetInstalledAppVersionHistory(installedAppId)
496+
if err != nil {
497+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
498+
return
499+
}
500+
501+
common.WriteJsonResp(w, err, response, http.StatusOK)
502+
}
503+
504+
func (handler *InstalledAppRestHandlerImpl) GetDeploymentHistoryValues(w http.ResponseWriter, r *http.Request) {
505+
vars := mux.Vars(r)
506+
installedAppId, err := strconv.Atoi(vars["installedAppId"])
507+
if err != nil {
508+
handler.Logger.Errorw("request err", "error", err, "installedAppId", installedAppId)
509+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
510+
return
511+
}
512+
installedAppVersionHistoryId, err := strconv.Atoi(vars["version"])
513+
if err != nil {
514+
handler.Logger.Errorw("request err", "error", err, "installedAppVersionHistoryId", installedAppVersionHistoryId)
515+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
516+
return
517+
}
518+
519+
token := r.Header.Get("token")
520+
installedApp, err := handler.appStoreDeploymentService.GetInstalledApp(installedAppId)
521+
if err != nil {
522+
handler.Logger.Errorw("service err, GetDeploymentHistoryValues", "err", err, "installedAppId", installedAppId)
523+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
524+
return
525+
}
526+
//rbac block starts from here
527+
object := handler.enforcerUtil.GetHelmObject(installedApp.AppId, installedApp.EnvironmentId)
528+
if ok := handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object); !ok {
529+
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
530+
return
531+
}
532+
//rback block ends here
533+
534+
response, err := handler.installedAppService.GetInstalledAppVersionHistoryValues(installedAppVersionHistoryId)
535+
if err != nil {
536+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
537+
return
538+
}
539+
540+
common.WriteJsonResp(w, err, response, http.StatusOK)
541+
}

api/appStore/AppStoreRouter.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func NewAppStoreRouterImpl(restHandler InstalledAppRestHandler,
3939
appStoreValuesRouter appStoreValues.AppStoreValuesRouter, appStoreDiscoverRouter appStoreDiscover.AppStoreDiscoverRouter,
4040
appStoreDeploymentRouter appStoreDeployment.AppStoreDeploymentRouter) *AppStoreRouterImpl {
4141
return &AppStoreRouterImpl{
42-
deployRestHandler: restHandler,
43-
appStoreValuesRouter: appStoreValuesRouter,
44-
appStoreDiscoverRouter: appStoreDiscoverRouter,
42+
deployRestHandler: restHandler,
43+
appStoreValuesRouter: appStoreValuesRouter,
44+
appStoreDiscoverRouter: appStoreDiscoverRouter,
4545
appStoreDeploymentRouter: appStoreDeploymentRouter,
4646
}
4747
}
@@ -83,4 +83,9 @@ func (router AppStoreRouterImpl) Init(configRouter *mux.Router) {
8383

8484
configRouter.Path("/cluster-component/install/{clusterId}").
8585
HandlerFunc(router.deployRestHandler.DefaultComponentInstallation).Methods("POST")
86+
87+
configRouter.Path("/installed-app/deployment-history").Queries("installedAppId", "{installedAppId}").
88+
HandlerFunc(router.deployRestHandler.GetDeploymentHistory).Methods("GET")
89+
configRouter.Path("/installed-app/deployment-history/info").Queries("installedAppId", "{installedAppId}").Queries("version", "{version}").
90+
HandlerFunc(router.deployRestHandler.GetDeploymentHistoryValues).Methods("GET")
8691
}

api/appStore/deployment/AppStoreDeploymentRestHandler.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/devtron-labs/devtron/internal/util"
3030
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
3131
appStoreDeployment "github.com/devtron-labs/devtron/pkg/appStore/deployment"
32+
appStoreDeploymentCommon "github.com/devtron-labs/devtron/pkg/appStore/deployment/common"
3233
"github.com/devtron-labs/devtron/pkg/user"
3334
"github.com/devtron-labs/devtron/pkg/user/casbin"
3435
util2 "github.com/devtron-labs/devtron/util"
@@ -51,29 +52,31 @@ type AppStoreDeploymentRestHandler interface {
5152
}
5253

5354
type AppStoreDeploymentRestHandlerImpl struct {
54-
Logger *zap.SugaredLogger
55-
userAuthService user.UserService
56-
enforcer casbin.Enforcer
57-
enforcerUtil rbac.EnforcerUtil
58-
enforcerUtilHelm rbac.EnforcerUtilHelm
59-
appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService
60-
validator *validator.Validate
61-
helmAppService client.HelmAppService
55+
Logger *zap.SugaredLogger
56+
userAuthService user.UserService
57+
enforcer casbin.Enforcer
58+
enforcerUtil rbac.EnforcerUtil
59+
enforcerUtilHelm rbac.EnforcerUtilHelm
60+
appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService
61+
appStoreDeploymentServiceC appStoreDeploymentCommon.AppStoreDeploymentCommonService
62+
validator *validator.Validate
63+
helmAppService client.HelmAppService
6264
}
6365

6466
func NewAppStoreDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
6567
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, enforcerUtilHelm rbac.EnforcerUtilHelm, appStoreDeploymentService appStoreDeployment.AppStoreDeploymentService,
66-
validator *validator.Validate, helmAppService client.HelmAppService,
68+
validator *validator.Validate, helmAppService client.HelmAppService, appStoreDeploymentServiceC appStoreDeploymentCommon.AppStoreDeploymentCommonService,
6769
) *AppStoreDeploymentRestHandlerImpl {
6870
return &AppStoreDeploymentRestHandlerImpl{
69-
Logger: Logger,
70-
userAuthService: userAuthService,
71-
enforcer: enforcer,
72-
enforcerUtil: enforcerUtil,
73-
enforcerUtilHelm: enforcerUtilHelm,
74-
appStoreDeploymentService: appStoreDeploymentService,
75-
validator: validator,
76-
helmAppService: helmAppService,
71+
Logger: Logger,
72+
userAuthService: userAuthService,
73+
enforcer: enforcer,
74+
enforcerUtil: enforcerUtil,
75+
enforcerUtilHelm: enforcerUtilHelm,
76+
appStoreDeploymentService: appStoreDeploymentService,
77+
validator: validator,
78+
helmAppService: helmAppService,
79+
appStoreDeploymentServiceC: appStoreDeploymentServiceC,
7780
}
7881
}
7982

@@ -307,14 +310,16 @@ func (handler *AppStoreDeploymentRestHandlerImpl) LinkHelmApplicationToChartStor
307310
handler.Logger.Errorw("Error in UpdateApplicationWithChartStoreLinking", "err", err, "payload", request)
308311
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
309312
return
310-
}else if !isChartRepoActive {
313+
} else if !isChartRepoActive {
311314
common.WriteJsonResp(w, fmt.Errorf("chart repo is disabled"), nil, http.StatusNotAcceptable)
312315
return
313316
}
314317

315318
common.WriteJsonResp(w, err, res, http.StatusOK)
316319
}
317320

321+
322+
318323
func (handler *AppStoreDeploymentRestHandlerImpl) RollbackApplication(w http.ResponseWriter, r *http.Request) {
319324
request := &openapi2.RollbackReleaseRequest{}
320325
decoder := json.NewDecoder(r.Body)

api/appStore/deployment/wire_appStoreDeployment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ var AppStoreDeploymentWireSet = wire.NewSet(
2727
wire.Bind(new(history.AppStoreChartsHistoryService), new(*history.AppStoreChartsHistoryServiceImpl)),
2828
repository.NewAppStoreChartsHistoryRepositoryImpl,
2929
wire.Bind(new(repository.AppStoreChartsHistoryRepository), new(*repository.AppStoreChartsHistoryRepositoryImpl)),
30+
appStoreRepository.NewInstalledAppVersionHistoryRepositoryImpl,
31+
wire.Bind(new(appStoreRepository.InstalledAppVersionHistoryRepository), new(*appStoreRepository.InstalledAppVersionHistoryRepositoryImpl)),
3032
)

api/router/pubsub/ApplicationStatusUpdateHandler.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
v1alpha12 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
2323
"github.com/devtron-labs/devtron/client/pubsub"
2424
"github.com/devtron-labs/devtron/pkg/app"
25+
"github.com/devtron-labs/devtron/pkg/appStore"
2526
"github.com/devtron-labs/devtron/pkg/pipeline"
27+
"github.com/go-pg/pg"
2628
"github.com/nats-io/stan.go"
2729
"go.uber.org/zap"
2830
"time"
@@ -37,19 +39,21 @@ type ApplicationStatusUpdateHandlerImpl struct {
3739
pubsubClient *pubsub.PubSubClient
3840
appService app.AppService
3941
workflowDagExecutor pipeline.WorkflowDagExecutor
42+
installedAppService appStore.InstalledAppService
4043
}
4144

4245
const applicationStatusUpdate = "APPLICATION_STATUS_UPDATE"
4346
const applicationStatusUpdateGroup = "APPLICATION_STATUS_UPDATE_GROUP-1"
4447
const applicationStatusUpdateDurable = "APPLICATION_STATUS_UPDATE_DURABLE-1"
4548

4649
func NewApplicationStatusUpdateHandlerImpl(logger *zap.SugaredLogger, pubsubClient *pubsub.PubSubClient, appService app.AppService,
47-
workflowDagExecutor pipeline.WorkflowDagExecutor) *ApplicationStatusUpdateHandlerImpl {
50+
workflowDagExecutor pipeline.WorkflowDagExecutor, installedAppService appStore.InstalledAppService) *ApplicationStatusUpdateHandlerImpl {
4851
appStatusUpdateHandlerImpl := &ApplicationStatusUpdateHandlerImpl{
4952
logger: logger,
5053
pubsubClient: pubsubClient,
5154
appService: appService,
5255
workflowDagExecutor: workflowDagExecutor,
56+
installedAppService: installedAppService,
5357
}
5458
err := appStatusUpdateHandlerImpl.Subscribe()
5559
if err != nil {
@@ -73,6 +77,17 @@ func (impl *ApplicationStatusUpdateHandlerImpl) Subscribe() error {
7377
isHealthy, err := impl.appService.UpdateApplicationStatusAndCheckIsHealthy(application)
7478
if err != nil {
7579
impl.logger.Errorw("error on application status update", "err", err, "msg", string(msg.Data))
80+
81+
//TODO - check update for charts - fix this call
82+
if err == pg.ErrNoRows {
83+
// if not found in charts (which is for devtron apps) try to find in installed app (which is for devtron charts)
84+
_, err := impl.installedAppService.UpdateInstalledAppVersionStatus(application)
85+
if err != nil {
86+
impl.logger.Errorw("error on application status update", "err", err, "msg", string(msg.Data))
87+
return
88+
}
89+
}
90+
// return anyways weather updates or failure, no further processing for charts status update
7691
return
7792
}
7893

0 commit comments

Comments
 (0)