-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gitops async with timeline (#5286)
* feat: replace user_deployment_request.status with pipeline_status_timelines * updated schema migration script * fix: migration script * update readme to include multi arch flag (#4998) * updated trigger event func and timeline names * review comment incorporation * fix: GetAllInCompleteRequests query * fix: GetAllInCompleteRequests query * fixed: UpdatePreviousQueuedRunnerStatus error * fix: loogers * doc: Added enhancements to security doc (#5203) * Rough Draft Initiated * Created Security Enhancement Docs + Other Adhoc Fixes * Incorporated PM Feedback * Modified Portforward Section to Kubectl Section (#5236) * feat: cd pipeline deployment history refactoring (#5200) * searchableKey service move * migrated cd deployment history code * idempotency of triggerPipeline func and minor fixes * timeline fixes * updated: NewTriggerEvent func * updated ErrorDeploymentSuperseded err handling * updated: GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses statuses * fix: timeline status * refactored: UpdatePreviousQueuedRunnerStatus * fix: GetPreviousQueuedRunners query * fix: UpdateRunnerStatusToFailedForIds query * fix: buildTriggerEventForOverrideRequest func * fix: UpdateRunnerStatusToFailedForIds query * fix: UpdateRunnerStatusToFailedForIds query * updated: handleAsyncTriggerReleaseError func * fix: concurrent case handlings * updated folder name * updated GetLastStatusPublishedTimeForWfrId func * feat: removed audit timeline and error handlings * fix: FetchTimelinesForWfrIdExcludingStatuses query * fix: deleted pipeline flow * timeline handling * timeline handling fixed * removed unused const * chore: updated go-bitbucket version * removed unnecessary alais --------- Co-authored-by: ayu-devtron <167413063+ayu-devtron@users.noreply.github.com> Co-authored-by: ashokdevtron <141001279+ashokdevtron@users.noreply.github.com> Co-authored-by: kartik-579 <84493919+kartik-579@users.noreply.github.com>
- Loading branch information
1 parent
afee443
commit 2dafe78
Showing
112 changed files
with
1,846 additions
and
1,273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
api/devtronResource/DevtronResourceHistoryRestHandler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package devtronResource | ||
|
||
import ( | ||
"fmt" | ||
apiBean "github.com/devtron-labs/devtron/api/devtronResource/bean" | ||
"github.com/devtron-labs/devtron/api/restHandler/common" | ||
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/adapter" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/bean" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/history/deployment/cdPipeline" | ||
"github.com/devtron-labs/devtron/util/rbac" | ||
"github.com/gorilla/schema" | ||
"go.uber.org/zap" | ||
"net/http" | ||
) | ||
|
||
type HistoryRestHandler interface { | ||
GetDeploymentHistory(w http.ResponseWriter, r *http.Request) | ||
GetDeploymentHistoryConfigList(w http.ResponseWriter, r *http.Request) | ||
} | ||
|
||
type HistoryRestHandlerImpl struct { | ||
logger *zap.SugaredLogger | ||
enforcer casbin.Enforcer | ||
deploymentHistoryService cdPipeline.DeploymentHistoryService | ||
apiReqDecoderService devtronResource.APIReqDecoderService | ||
enforcerUtil rbac.EnforcerUtil | ||
} | ||
|
||
func NewHistoryRestHandlerImpl(logger *zap.SugaredLogger, | ||
enforcer casbin.Enforcer, | ||
deploymentHistoryService cdPipeline.DeploymentHistoryService, | ||
apiReqDecoderService devtronResource.APIReqDecoderService, | ||
enforcerUtil rbac.EnforcerUtil) *HistoryRestHandlerImpl { | ||
return &HistoryRestHandlerImpl{ | ||
logger: logger, | ||
enforcer: enforcer, | ||
deploymentHistoryService: deploymentHistoryService, | ||
apiReqDecoderService: apiReqDecoderService, | ||
enforcerUtil: enforcerUtil, | ||
} | ||
} | ||
|
||
func (handler *HistoryRestHandlerImpl) GetDeploymentHistory(w http.ResponseWriter, r *http.Request) { | ||
kind, _, _, caughtError := getKindSubKindVersion(w, r) | ||
if caughtError || kind != bean.DevtronResourceCdPipeline.ToString() { | ||
common.WriteJsonResp(w, fmt.Errorf(apiBean.RequestInvalidKindVersionErrMessage), nil, http.StatusBadRequest) | ||
return | ||
} | ||
v := r.URL.Query() | ||
var decoder = schema.NewDecoder() | ||
decoder.IgnoreUnknownKeys(true) | ||
queryParams := apiBean.GetHistoryQueryParams{} | ||
err := decoder.Decode(&queryParams, v) | ||
if err != nil { | ||
common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
return | ||
} | ||
decodedReqBean, err := handler.apiReqDecoderService.GetFilterCriteriaParamsForDeploymentHistory(queryParams.FilterCriteria) | ||
if err != nil { | ||
handler.logger.Errorw("error in getting filter criteria params", "err", err, "filterCriteria", queryParams.FilterCriteria) | ||
common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
return | ||
} | ||
|
||
// RBAC START | ||
token := r.Header.Get("token") | ||
resourceName := handler.enforcerUtil.GetAppRBACNameByAppId(decodedReqBean.AppId) | ||
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !ok { | ||
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden) | ||
return | ||
} | ||
// RBAC END | ||
|
||
resp, err := handler.deploymentHistoryService. | ||
GetCdPipelineDeploymentHistory(adapter.GetCDDeploymentHistoryListReq(&queryParams, decodedReqBean)) | ||
if err != nil { | ||
handler.logger.Errorw("service error, GetCdPipelineDeploymentHistory", "err", err) | ||
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
return | ||
} | ||
common.WriteJsonResp(w, err, resp, http.StatusOK) | ||
return | ||
} | ||
|
||
func (handler *HistoryRestHandlerImpl) GetDeploymentHistoryConfigList(w http.ResponseWriter, r *http.Request) { | ||
kind, _, _, caughtError := getKindSubKindVersion(w, r) | ||
if caughtError || kind != bean.DevtronResourceCdPipeline.ToString() { | ||
common.WriteJsonResp(w, fmt.Errorf(apiBean.RequestInvalidKindVersionErrMessage), nil, http.StatusBadRequest) | ||
return | ||
} | ||
v := r.URL.Query() | ||
var decoder = schema.NewDecoder() | ||
decoder.IgnoreUnknownKeys(true) | ||
queryParams := apiBean.GetHistoryConfigQueryParams{} | ||
err := decoder.Decode(&queryParams, v) | ||
if err != nil { | ||
common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
return | ||
} | ||
decodedReqBean, err := handler.apiReqDecoderService.GetFilterCriteriaParamsForDeploymentHistory(queryParams.FilterCriteria) | ||
if err != nil { | ||
handler.logger.Errorw("error in getting filter criteria params", "err", err, "filterCriteria", queryParams.FilterCriteria) | ||
common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
return | ||
} | ||
//RBAC START | ||
token := r.Header.Get("token") | ||
resourceName := handler.enforcerUtil.GetAppRBACNameByAppId(decodedReqBean.AppId) | ||
if isValidated := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, resourceName); !isValidated { | ||
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden) | ||
return | ||
} | ||
//RBAC END | ||
resp, err := handler.deploymentHistoryService. | ||
GetCdPipelineDeploymentHistoryConfigList(adapter.GetCDDeploymentHistoryConfigListReq(&queryParams, decodedReqBean)) | ||
if err != nil { | ||
handler.logger.Errorw("service error, GetCdPipelineDeploymentHistoryConfigList", "err", err) | ||
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
return | ||
} | ||
common.WriteJsonResp(w, err, resp, http.StatusOK) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package devtronResource | ||
|
||
import "github.com/gorilla/mux" | ||
|
||
type HistoryRouter interface { | ||
InitDtResourceHistoryRouter(devtronResourceRouter *mux.Router) | ||
} | ||
|
||
type HistoryRouterImpl struct { | ||
dtResourceHistoryRestHandler HistoryRestHandler | ||
} | ||
|
||
func NewHistoryRouterImpl(dtResourceHistoryRestHandler HistoryRestHandler) *HistoryRouterImpl { | ||
return &HistoryRouterImpl{dtResourceHistoryRestHandler: dtResourceHistoryRestHandler} | ||
} | ||
|
||
func (router *HistoryRouterImpl) InitDtResourceHistoryRouter(historyRouter *mux.Router) { | ||
historyRouter.Path("/deployment/config/{kind:[a-zA-Z0-9/-]+}/{version:[a-zA-Z0-9]+}"). | ||
HandlerFunc(router.dtResourceHistoryRestHandler.GetDeploymentHistoryConfigList).Methods("GET") | ||
|
||
historyRouter.Path("/deployment/{kind:[a-zA-Z0-9/-]+}/{version:[a-zA-Z0-9]+}"). | ||
HandlerFunc(router.dtResourceHistoryRestHandler.GetDeploymentHistory).Methods("GET") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package devtronResource | ||
|
||
import ( | ||
"fmt" | ||
apiBean "github.com/devtron-labs/devtron/api/devtronResource/bean" | ||
"github.com/devtron-labs/devtron/api/restHandler/common" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/helper" | ||
"github.com/gorilla/mux" | ||
"net/http" | ||
) | ||
|
||
func getKindSubKindVersion(w http.ResponseWriter, r *http.Request) (kind string, subKind string, version string, caughtError bool) { | ||
vars := mux.Vars(r) | ||
kindVar := vars[apiBean.PathParamKind] | ||
versionVar := vars[apiBean.PathParamVersion] | ||
kind, subKind, statusCode, err := resolveKindSubKindValues(kindVar) | ||
if err != nil { | ||
common.WriteJsonResp(w, err, nil, statusCode) | ||
caughtError = true | ||
} | ||
return kind, subKind, versionVar, caughtError | ||
} | ||
|
||
func resolveKindSubKindValues(kindVar string) (kind, subKind string, statusCode int, err error) { | ||
kind, subKind, err = helper.GetKindAndSubKindFrom(kindVar) | ||
if err != nil { | ||
err = fmt.Errorf("invalid parameter: kind") | ||
statusCode = http.StatusBadRequest | ||
} | ||
return kind, subKind, statusCode, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package devtronResource | ||
|
||
import "github.com/gorilla/mux" | ||
|
||
type DevtronResourceRouter interface { | ||
InitDevtronResourceRouter(devtronResourceRouter *mux.Router) | ||
} | ||
|
||
type DevtronResourceRouterImpl struct { | ||
historyRouter HistoryRouter | ||
} | ||
|
||
func NewDevtronResourceRouterImpl(historyRouter HistoryRouter) *DevtronResourceRouterImpl { | ||
return &DevtronResourceRouterImpl{ | ||
historyRouter: historyRouter, | ||
} | ||
} | ||
|
||
func (router *DevtronResourceRouterImpl) InitDevtronResourceRouter(devtronResourceRouter *mux.Router) { | ||
historyRouter := devtronResourceRouter.PathPrefix("/history").Subrouter() | ||
router.historyRouter.InitDtResourceHistoryRouter(historyRouter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bean | ||
|
||
type GetHistoryQueryParams struct { | ||
FilterCriteria []string `schema:"filterCriteria"` | ||
OffSet int `schema:"offSet"` | ||
Limit int `schema:"limit"` | ||
} | ||
|
||
type GetHistoryConfigQueryParams struct { | ||
BaseConfigurationId int `schema:"baseConfigurationId"` | ||
HistoryComponent string `schema:"historyComponent"` | ||
HistoryComponentName string `schema:"historyComponentName"` | ||
FilterCriteria []string `schema:"filterCriteria"` | ||
} | ||
|
||
const ( | ||
RequestInvalidKindVersionErrMessage = "Invalid kind and version! Implementation not supported." | ||
PathParamKind = "kind" | ||
PathParamVersion = "version" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package devtronResource | ||
|
||
import ( | ||
"github.com/devtron-labs/devtron/pkg/devtronResource" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/history/deployment/cdPipeline" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/read" | ||
"github.com/devtron-labs/devtron/pkg/devtronResource/repository" | ||
"github.com/google/wire" | ||
) | ||
|
||
var DevtronResourceWireSet = wire.NewSet( | ||
//old bindings, migrated from wire.go | ||
read.NewDevtronResourceSearchableKeyServiceImpl, | ||
wire.Bind(new(read.DevtronResourceSearchableKeyService), new(*read.DevtronResourceSearchableKeyServiceImpl)), | ||
repository.NewDevtronResourceSearchableKeyRepositoryImpl, | ||
wire.Bind(new(repository.DevtronResourceSearchableKeyRepository), new(*repository.DevtronResourceSearchableKeyRepositoryImpl)), | ||
|
||
NewDevtronResourceRouterImpl, | ||
wire.Bind(new(DevtronResourceRouter), new(*DevtronResourceRouterImpl)), | ||
|
||
NewHistoryRouterImpl, | ||
wire.Bind(new(HistoryRouter), new(*HistoryRouterImpl)), | ||
NewHistoryRestHandlerImpl, | ||
wire.Bind(new(HistoryRestHandler), new(*HistoryRestHandlerImpl)), | ||
cdPipeline.NewDeploymentHistoryServiceImpl, | ||
wire.Bind(new(cdPipeline.DeploymentHistoryService), new(*cdPipeline.DeploymentHistoryServiceImpl)), | ||
|
||
devtronResource.NewAPIReqDecoderServiceImpl, | ||
wire.Bind(new(devtronResource.APIReqDecoderService), new(*devtronResource.APIReqDecoderServiceImpl)), | ||
) |
Oops, something went wrong.