Skip to content

Commit

Permalink
Merge branch 'main' into devtron-cd-trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokdevtron authored Aug 29, 2024
2 parents 7b1f247 + 7ee4a32 commit d2021f8
Show file tree
Hide file tree
Showing 1,165 changed files with 59,508 additions and 124,022 deletions.
7 changes: 4 additions & 3 deletions .gitbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ redirects:
setup/upgrade/devtron-upgrade-0.2.x-0.3.x: getting-started/upgrade/devtron-upgrade-0.2.x-0.3.x
setup/global-configurations: user-guide/global-configurations/README.md
setup/global-configurations/gitops: user-guide/global-configurations/gitops.md
setup/global-configurations/custom-charts: user-guide/global-configurations/custom-charts.md
setup/global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
setup/global-configurations/user-access: user-guide/global-configurations/authorization/user-access.md
setup/global-configurations/external-links: user-guide/global-configurations/external-links.md
setup/global-configurations/projects: user-guide/global-configurations/projects.md
Expand Down Expand Up @@ -109,7 +109,7 @@ redirects:
getting-started/global-configurations/filter-condition: user-guide/global-configurations/filter-condition.md
getting-started/global-configurations/build-infra: user-guide/global-configurations/build-infra.md
getting-started/global-configurations/gitops: user-guide/global-configurations/gitops.md
getting-started/global-configurations/custom-charts: user-guide/global-configurations/custom-charts.md
getting-started/global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
getting-started/global-configurations/external-links: user-guide/global-configurations/external-links.md
getting-started/global-configurations/projects: user-guide/global-configurations/projects.md
getting-started/global-configurations/manage-notification: user-guide/global-configurations/manage-notification.md
Expand All @@ -127,4 +127,5 @@ redirects:
user-guide/clusters: user-guide/resource-browser.md
usage/clusters: user-guide/resource-browser.md
global-configurations/authorization/sso-login/okta: user-guide/global-configurations/authorization/sso/okta.md
usage/applications/creating-application/ci-pipeline/ci-build-pre-post-plugins: user-guide/creating-application/workflow/ci-build-pre-post-plugins.md
usage/applications/creating-application/ci-pipeline/ci-build-pre-post-plugins: user-guide/creating-application/workflow/ci-build-pre-post-plugins.md
global-configurations/custom-charts: user-guide/global-configurations/deployment-charts.md
16 changes: 15 additions & 1 deletion Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/devtron-labs/devtron/api/deployment"
"github.com/devtron-labs/devtron/api/devtronResource"
"github.com/devtron-labs/devtron/api/externalLink"
fluxApplication "github.com/devtron-labs/devtron/api/fluxApplication"
client "github.com/devtron-labs/devtron/api/helm-app"
"github.com/devtron-labs/devtron/api/infraConfig"
"github.com/devtron-labs/devtron/api/k8s"
Expand Down Expand Up @@ -115,6 +116,7 @@ import (
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deploymentTypeChange"
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource"
"github.com/devtron-labs/devtron/pkg/appWorkflow"
"github.com/devtron-labs/devtron/pkg/argoRepositoryCreds"
"github.com/devtron-labs/devtron/pkg/asyncProvider"
"github.com/devtron-labs/devtron/pkg/attributes"
"github.com/devtron-labs/devtron/pkg/build"
Expand All @@ -123,6 +125,7 @@ import (
"github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig"
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
"github.com/devtron-labs/devtron/pkg/commonService"
"github.com/devtron-labs/devtron/pkg/configDiff"
delete2 "github.com/devtron-labs/devtron/pkg/delete"
deployment2 "github.com/devtron-labs/devtron/pkg/deployment"
"github.com/devtron-labs/devtron/pkg/deployment/common"
Expand Down Expand Up @@ -175,6 +178,7 @@ func InitializeApp() (*App, error) {
externalLink.ExternalLinkWireSet,
team.TeamsWireSet,
AuthWireSet,
util4.GetRuntimeConfig,
util4.NewK8sUtil,
wire.Bind(new(util4.K8sService), new(*util4.K8sServiceImpl)),
user.UserWireSet,
Expand All @@ -198,7 +202,7 @@ func InitializeApp() (*App, error) {
build.BuildWireSet,
deployment2.DeploymentWireSet,
argoApplication.ArgoApplicationWireSet,

fluxApplication.FluxApplicationWireSet,
eventProcessor.EventProcessorWireSet,
workflow3.WorkflowWireSet,

Expand Down Expand Up @@ -708,6 +712,13 @@ func InitializeApp() (*App, error) {
scopedVariable.NewScopedVariableRestHandlerImpl,
wire.Bind(new(scopedVariable.ScopedVariableRestHandler), new(*scopedVariable.ScopedVariableRestHandlerImpl)),

router.NewDeploymentConfigurationRouter,
wire.Bind(new(router.DeploymentConfigurationRouter), new(*router.DeploymentConfigurationRouterImpl)),
restHandler.NewDeploymentConfigurationRestHandlerImpl,
wire.Bind(new(restHandler.DeploymentConfigurationRestHandler), new(*restHandler.DeploymentConfigurationRestHandlerImpl)),
configDiff.NewDeploymentConfigurationServiceImpl,
wire.Bind(new(configDiff.DeploymentConfigurationService), new(*configDiff.DeploymentConfigurationServiceImpl)),

router.NewTelemetryRouterImpl,
wire.Bind(new(router.TelemetryRouter), new(*router.TelemetryRouterImpl)),
restHandler.NewTelemetryRestHandlerImpl,
Expand Down Expand Up @@ -989,6 +1000,9 @@ func InitializeApp() (*App, error) {
common.NewDeploymentConfigServiceImpl,
wire.Bind(new(common.DeploymentConfigService), new(*common.DeploymentConfigServiceImpl)),

argoRepositoryCreds.NewRepositorySecret,
wire.Bind(new(argoRepositoryCreds.RepositorySecret), new(*argoRepositoryCreds.RepositorySecretImpl)),

repocreds.NewServiceClientImpl,
wire.Bind(new(repocreds.ServiceClient), new(*repocreds.ServiceClientImpl)),
)
Expand Down
3 changes: 3 additions & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type AppEnvironmentContainer struct {
type DeploymentDetailContainer struct {
InstalledAppId int `json:"installedAppId,omitempty"`
AppId int `json:"appId,omitempty"`
PcoId int `json:"pcoId"`
CdPipelineId int `json:"cdPipelineId,omitempty"`
TriggerType string `json:"triggerType,omitempty"`
ParentEnvironmentName string `json:"parentEnvironmentName"`
Expand Down Expand Up @@ -183,6 +184,8 @@ type DeploymentDetailContainer struct {
HelmPackageName string `json:"helmPackageName"`
HelmReleaseInstallStatus string `json:"-"`
DeploymentConfig *bean.DeploymentConfig `json:"-"`
IsPipelineTriggered bool `json:"isPipelineTriggered"`
ReleaseMode string `json:"releaseMode"`
}

type AppDetailContainer struct {
Expand Down
1 change: 1 addition & 0 deletions api/bean/ConfigMapAndSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ConfigMapJson struct {
type ConfigSecretRootJson struct {
ConfigSecretJson ConfigSecretJson `json:"ConfigSecrets"`
}

type ConfigSecretJson struct {
Enabled bool `json:"enabled"`
Secrets []*ConfigSecretMap `json:"secrets"`
Expand Down
94 changes: 94 additions & 0 deletions api/fluxApplication/FluxApplicationRestHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package fluxApplication

import (
"errors"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
"github.com/devtron-labs/devtron/pkg/fluxApplication"
"github.com/gorilla/mux"
"go.uber.org/zap"
"net/http"
)

type FluxApplicationRestHandler interface {
ListFluxApplications(w http.ResponseWriter, r *http.Request)
GetApplicationDetail(w http.ResponseWriter, r *http.Request)
}

type FluxApplicationRestHandlerImpl struct {
fluxApplicationService fluxApplication.FluxApplicationService
logger *zap.SugaredLogger
enforcer casbin.Enforcer
}

func NewFluxApplicationRestHandlerImpl(fluxApplicationService fluxApplication.FluxApplicationService,
logger *zap.SugaredLogger, enforcer casbin.Enforcer) *FluxApplicationRestHandlerImpl {
return &FluxApplicationRestHandlerImpl{
fluxApplicationService: fluxApplicationService,
logger: logger,
enforcer: enforcer,
}

}

func (handler *FluxApplicationRestHandlerImpl) ListFluxApplications(w http.ResponseWriter, r *http.Request) {

//handle super-admin RBAC
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}
v := r.URL.Query()
clusterIdString := v.Get("clusterIds")
var clusterIds []int
var err error

//handling when the clusterIds string is empty ,it will not support the
if len(clusterIdString) == 0 {
handler.logger.Errorw("error in getting cluster ids", "error", err, "clusterIds", clusterIds)
common.WriteJsonResp(w, errors.New("error in getting cluster ids"), nil, http.StatusBadRequest)
return
}
clusterIds, err = common.ExtractIntArrayQueryParam(w, r, "clusterIds")
if err != nil {
handler.logger.Errorw("error in parsing cluster ids", "error", err, "clusterIds", clusterIds)
return
}
handler.logger.Debugw("extracted ClusterIds successfully ", "clusterIds", clusterIds)
handler.fluxApplicationService.ListFluxApplications(r.Context(), clusterIds, w)
}

func (handler *FluxApplicationRestHandlerImpl) GetApplicationDetail(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appIdString := vars["appId"]
appIdentifier, err := fluxApplication.DecodeFluxExternalAppId(appIdString)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if appIdentifier.IsKustomizeApp == true && appIdentifier.Name == "flux-system" && appIdentifier.Namespace == "flux-system" {

common.WriteJsonResp(w, errors.New("cannot proceed for the flux system root level "), nil, http.StatusBadRequest)
return
}

// handle super-admin RBAC
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

res, err := handler.fluxApplicationService.GetFluxAppDetail(r.Context(), appIdentifier)
if err != nil {
apiError := clientErrors.ConvertToApiError(err)
if apiError != nil {
err = apiError
}
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
}
27 changes: 27 additions & 0 deletions api/fluxApplication/FluxApplicationRouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fluxApplication

import (
"github.com/gorilla/mux"
)

type FluxApplicationRouter interface {
InitFluxApplicationRouter(fluxApplicationRouter *mux.Router)
}

type FluxApplicationRouterImpl struct {
fluxApplicationRestHandler FluxApplicationRestHandler
}

func NewFluxApplicationRouterImpl(fluxApplicationRestHandler FluxApplicationRestHandler) *FluxApplicationRouterImpl {
return &FluxApplicationRouterImpl{
fluxApplicationRestHandler: fluxApplicationRestHandler,
}
}

func (impl *FluxApplicationRouterImpl) InitFluxApplicationRouter(fluxApplicationRouter *mux.Router) {
fluxApplicationRouter.Path("").
Methods("GET").
HandlerFunc(impl.fluxApplicationRestHandler.ListFluxApplications)
fluxApplicationRouter.Path("/app").Queries("appId", "{appId}").
HandlerFunc(impl.fluxApplicationRestHandler.GetApplicationDetail).Methods("GET")
}
17 changes: 17 additions & 0 deletions api/fluxApplication/wire_fluxApplication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fluxApplication

import (
"github.com/devtron-labs/devtron/pkg/fluxApplication"
"github.com/google/wire"
)

var FluxApplicationWireSet = wire.NewSet(
fluxApplication.NewFluxApplicationServiceImpl,
wire.Bind(new(fluxApplication.FluxApplicationService), new(*fluxApplication.FluxApplicationServiceImpl)),

NewFluxApplicationRestHandlerImpl,
wire.Bind(new(FluxApplicationRestHandler), new(*FluxApplicationRestHandlerImpl)),

NewFluxApplicationRouterImpl,
wire.Bind(new(FluxApplicationRouter), new(*FluxApplicationRouterImpl)),
)
Loading

0 comments on commit d2021f8

Please sign in to comment.