Skip to content

Commit

Permalink
Merge branch 'main' into artifact-api-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gireesh-naidu committed Nov 7, 2023
2 parents 84b3911 + b691cca commit fa09e81
Show file tree
Hide file tree
Showing 61 changed files with 1,488 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ func InitializeApp() (*App, error) {
wire.Bind(new(repository9.DevtronResourceSearchableKeyRepository), new(*repository9.DevtronResourceSearchableKeyRepositoryImpl)),

devtronResource.NewDevtronResourceSearchableKeyServiceImpl,
wire.Bind(new(devtronResource.DevtronResourceService), new(*devtronResource.DevtronResourceSearchableKeyServiceImpl)),
wire.Bind(new(devtronResource.DevtronResourceSearchableKeyService), new(*devtronResource.DevtronResourceSearchableKeyServiceImpl)),

argocdServer.NewArgoClientWrapperServiceImpl,
wire.Bind(new(argocdServer.ArgoClientWrapperService), new(*argocdServer.ArgoClientWrapperServiceImpl)),
Expand Down
3 changes: 2 additions & 1 deletion api/appStore/AppStoreRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (router AppStoreRouterImpl) Init(configRouter *mux.Router) {
chartProviderSubRouter := configRouter.PathPrefix("/chart-provider").Subrouter()
router.chartProviderRouter.Init(chartProviderSubRouter)
// chart provider router ends

configRouter.Path("/overview").Queries("installedAppId", "{installedAppId}").
HandlerFunc(router.deployRestHandler.FetchAppOverview).Methods("GET")
configRouter.Path("/application/exists").
HandlerFunc(router.deployRestHandler.CheckAppExists).Methods("POST")
configRouter.Path("/group/install").
Expand Down
44 changes: 43 additions & 1 deletion api/appStore/InstalledAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/devtron-labs/devtron/internal/constants"
"github.com/devtron-labs/devtron/internal/middleware"
util2 "github.com/devtron-labs/devtron/internal/util"
app2 "github.com/devtron-labs/devtron/pkg/app"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/repository"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
Expand All @@ -53,6 +54,7 @@ import (
)

type InstalledAppRestHandler interface {
FetchAppOverview(w http.ResponseWriter, r *http.Request)
GetAllInstalledApp(w http.ResponseWriter, r *http.Request)
DeployBulk(w http.ResponseWriter, r *http.Request)
CheckAppExists(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -82,6 +84,7 @@ type InstalledAppRestHandlerImpl struct {
cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler
installedAppRepository repository.InstalledAppRepository
K8sApplicationService application2.K8sApplicationService
appCrudOperationService app2.AppCrudOperationService
}

func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
Expand All @@ -91,7 +94,7 @@ func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService u
argoUserService argo.ArgoUserService,
cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler,
installedAppRepository repository.InstalledAppRepository,
) *InstalledAppRestHandlerImpl {
appCrudOperationService app2.AppCrudOperationService) *InstalledAppRestHandlerImpl {
return &InstalledAppRestHandlerImpl{
Logger: Logger,
userAuthService: userAuthService,
Expand All @@ -108,8 +111,47 @@ func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService u
argoUserService: argoUserService,
cdApplicationStatusUpdateHandler: cdApplicationStatusUpdateHandler,
installedAppRepository: installedAppRepository,
appCrudOperationService: appCrudOperationService,
}
}
func (handler *InstalledAppRestHandlerImpl) FetchAppOverview(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, nil, http.StatusUnauthorized)
return
}

vars := mux.Vars(r)
installedAppId, err := strconv.Atoi(vars["installedAppId"])
if err != nil {
handler.Logger.Errorw("request err, FetchAppOverview", "err", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
handler.Logger.Infow("request payload, FindAppOverview", "installedAppId", installedAppId)
installedApp, err := handler.installedAppService.CheckAppExistsByInstalledAppId(installedAppId)
appOverview, err := handler.appCrudOperationService.GetAppMetaInfo(installedApp.AppId, installedAppId, installedApp.EnvironmentId)
if err != nil {
handler.Logger.Errorw("service err, FetchAppOverview", "err", err, "appId", installedApp.AppId, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

//rbac block starts from here
object, object2 := handler.enforcerUtil.GetHelmObject(appOverview.AppId, installedApp.EnvironmentId)
var ok bool
if object2 == "" {
ok = handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object)
} else {
ok = handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object) || handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object2)
}
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
common.WriteJsonResp(w, nil, appOverview, http.StatusOK)
}

func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
Expand Down
4 changes: 4 additions & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ type Environment struct {
Prod bool `json:"prod"`
ChartRefId int `json:"chartRefId"`
LastDeployed string `json:"lastDeployed"`
LastDeployedBy string `json:"lastDeployedBy"`
LastDeployedImage string `json:"lastDeployedImage"`
DeploymentAppDeleteRequest bool `json:"deploymentAppDeleteRequest"`
Description string `json:"description" validate:"max=40"`
IsVirtualEnvironment bool `json:"isVirtualEnvironment"`
ClusterId int `json:"clusterId"`
PipelineId int `json:"pipelineId"`
LatestCdWorkflowRunnerId int `json:"latestCdWorkflowRunnerId,omitempty"`
}

type InstanceDetail struct {
Expand Down
40 changes: 40 additions & 0 deletions api/cluster/ClusterRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ClusterRestHandler interface {
FindById(w http.ResponseWriter, r *http.Request)
FindNoteByClusterId(w http.ResponseWriter, r *http.Request)
Update(w http.ResponseWriter, r *http.Request)
UpdateClusterDescription(w http.ResponseWriter, r *http.Request)
UpdateClusterNote(w http.ResponseWriter, r *http.Request)
FindAllForAutoComplete(w http.ResponseWriter, r *http.Request)
DeleteCluster(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -453,6 +454,45 @@ func (impl ClusterRestHandlerImpl) Update(w http.ResponseWriter, r *http.Request
common.WriteJsonResp(w, err, bean, http.StatusOK)
}

func (impl ClusterRestHandlerImpl) UpdateClusterDescription(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
decoder := json.NewDecoder(r.Body)
userId, err := impl.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
impl.logger.Errorw("service err, Update", "error", err, "userId", userId)
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
var bean cluster.ClusterBean
err = decoder.Decode(&bean)
if err != nil {
impl.logger.Errorw("request err, UpdateClusterDescription", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
impl.logger.Infow("request payload, UpdateClusterDescription", "payload", bean)
//TODO: add apt validation
clusterDescription, err := impl.clusterDescriptionService.FindByClusterIdWithClusterDetails(bean.Id)
if err != nil {
impl.logger.Errorw("service err, FindById", "err", err, "clusterId", bean.Id)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
// RBAC enforcer applying
if ok := impl.enforcer.Enforce(token, casbin.ResourceCluster, casbin.ActionUpdate, strings.ToLower(clusterDescription.ClusterName)); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}
// RBAC enforcer ends
err = impl.clusterService.UpdateClusterDescription(&bean, userId)
if err != nil {
impl.logger.Errorw("service err, UpdateClusterDescription", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, "Cluster description updated successfully", http.StatusOK)
}

func (impl ClusterRestHandlerImpl) UpdateClusterNote(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
decoder := json.NewDecoder(r.Body)
Expand Down
6 changes: 5 additions & 1 deletion api/cluster/ClusterRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (impl ClusterRouterImpl) InitClusterRouter(clusterRouter *mux.Router) {
Methods("PUT").
HandlerFunc(impl.clusterRestHandler.Update)

clusterRouter.Path("/description").
clusterRouter.Path("/note").
Methods("PUT").
HandlerFunc(impl.clusterRestHandler.UpdateClusterNote)

Expand All @@ -89,4 +89,8 @@ func (impl ClusterRouterImpl) InitClusterRouter(clusterRouter *mux.Router) {
clusterRouter.Path("/auth-list").
Methods("GET").
HandlerFunc(impl.clusterRestHandler.FindAllForClusterPermission)

clusterRouter.Path("/description").
Methods("PUT").
HandlerFunc(impl.clusterRestHandler.UpdateClusterDescription)
}
6 changes: 3 additions & 3 deletions api/restHandler/AppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type AppRestHandler interface {
UpdateApp(w http.ResponseWriter, r *http.Request)
UpdateProjectForApps(w http.ResponseWriter, r *http.Request)
GetAppListByTeamIds(w http.ResponseWriter, r *http.Request)
UpdateAppDescription(w http.ResponseWriter, r *http.Request)
UpdateAppNote(w http.ResponseWriter, r *http.Request)
}

type AppRestHandlerImpl struct {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (handler AppRestHandlerImpl) GetAppMetaInfo(w http.ResponseWriter, r *http.
}
//rback implementation ends here

res, err := handler.appService.GetAppMetaInfo(appId)
res, err := handler.appService.GetAppMetaInfo(appId, app.ZERO_INSTALLED_APP_ID, app.ZERO_ENVIRONMENT_ID)
if err != nil {
handler.logger.Errorw("service err, GetAppMetaInfo", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down Expand Up @@ -343,7 +343,7 @@ func (handler AppRestHandlerImpl) GetAppListByTeamIds(w http.ResponseWriter, r *
common.WriteJsonResp(w, err, projectWiseApps, http.StatusOK)
}

func (handler AppRestHandlerImpl) UpdateAppDescription(w http.ResponseWriter, r *http.Request) {
func (handler AppRestHandlerImpl) UpdateAppNote(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
decoder := json.NewDecoder(r.Body)
userId, err := handler.userAuthService.GetLoggedInUser(r)
Expand Down
6 changes: 3 additions & 3 deletions api/restHandler/CoreAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (handler CoreAppRestHandlerImpl) CreateApp(w http.ResponseWriter, r *http.R
func (handler CoreAppRestHandlerImpl) buildAppMetadata(appId int) (*appBean.AppMetadata, error, int) {
handler.logger.Debugw("Getting app detail - meta data", "appId", appId)

appMetaInfo, err := handler.appCrudOperationService.GetAppMetaInfo(appId)
appMetaInfo, err := handler.appCrudOperationService.GetAppMetaInfo(appId, app.ZERO_INSTALLED_APP_ID, app.ZERO_ENVIRONMENT_ID)
if err != nil {
handler.logger.Errorw("service err, GetAppMetaInfo in GetAppAllDetail", "err", err, "appId", appId)
return nil, err, http.StatusInternalServerError
Expand Down Expand Up @@ -2328,7 +2328,7 @@ func (handler CoreAppRestHandlerImpl) GetAppWorkflow(w http.ResponseWriter, r *h
token := r.Header.Get("token")

// get app metadata for appId
appMetaInfo, err := handler.appCrudOperationService.GetAppMetaInfo(appId)
appMetaInfo, err := handler.appCrudOperationService.GetAppMetaInfo(appId, app.ZERO_INSTALLED_APP_ID, app.ZERO_ENVIRONMENT_ID)
if err != nil {
handler.logger.Errorw("service err, GetAppMetaInfo in GetAppWorkflow", "appId", appId, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down Expand Up @@ -2379,7 +2379,7 @@ func (handler CoreAppRestHandlerImpl) GetAppWorkflowAndOverridesSample(w http.Re
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
app, err := handler.appCrudOperationService.GetAppMetaInfo(appId)
app, err := handler.appCrudOperationService.GetAppMetaInfo(appId, app.ZERO_INSTALLED_APP_ID, app.ZERO_ENVIRONMENT_ID)
if err != nil {
handler.logger.Errorw("service err, GetAppMetaInfo in GetAppAllDetail", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
Expand Down
4 changes: 2 additions & 2 deletions api/router/AppRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (router AppRouterImpl) InitAppRouter(appRouter *mux.Router) {

appRouter.Path("/min").HandlerFunc(router.handler.GetAppListByTeamIds).Methods("GET")

appRouter.Path("/description").
appRouter.Path("/note").
Methods("PUT").
HandlerFunc(router.handler.UpdateAppDescription)
HandlerFunc(router.handler.UpdateAppNote)
}
Binary file added assets/ic-plugin-vulnerability-scan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions cmd/external-app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func InitializeApp() (*App, error) {
telemetry.NewPosthogClient,
delete2.NewDeleteServiceImpl,

pipelineConfig.NewMaterialRepositoryImpl,
wire.Bind(new(pipelineConfig.MaterialRepository), new(*pipelineConfig.MaterialRepositoryImpl)),
//appStatus
appStatus.NewAppStatusRepositoryImpl,
wire.Bind(new(appStatus.AppStatusRepository), new(*appStatus.AppStatusRepositoryImpl)),
Expand Down
3 changes: 2 additions & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
* [Host URL](user-guide/global-configurations/host-url.md)
* [GitOps](user-guide/global-configurations/gitops.md)
* [Projects](user-guide/global-configurations/projects.md)
* [Cluster And Environments](user-guide/global-configurations/cluster-and-environments.md)
* [Clusters & Environments](user-guide/global-configurations/cluster-and-environments.md)
* [Git Accounts](user-guide/global-configurations/git-accounts.md)
* [Container Registries](user-guide/global-configurations/container-registries.md)
* [Container/OCI Registry](user-guide/global-configurations/container-registries.md)
* [Chart Repositories](user-guide/global-configurations/chart-repo.md)
* [Custom charts](user-guide/global-configurations/custom-charts.md)
* [Custom Charts](user-guide/global-configurations/custom-charts.md)
* [SSO Login Services](user-guide/global-configurations/sso-login.md)
* [Example - Okta SSO](user-guide/global-configurations/okta.md)
* [Authorization](user-guide/global-configurations/authorization/README.md)
* [User Permissions](user-guide/global-configurations/authorization/user-access.md)
* [Permission Groups](user-guide/global-configurations/authorization/permission-groups.md)
* [API Tokens](user-guide/global-configurations/authorization/api-tokens.md)
* [Manage Notification](user-guide/global-configurations/manage-notification.md)
* [External links](user-guide/global-configurations/external-links.md)
* [Notifications](user-guide/global-configurations/manage-notification.md)
* [External Links](user-guide/global-configurations/external-links.md)
* [Scoped Variables](user-guide/global-configurations/scoped-variables.md)
* [Tags Policy](user-guide/global-configurations/tags-policy.md)
* [Devtron Upgrade](setup/upgrade/README.md)
* [Update Devtron from Devtron UI](setup/upgrade/upgrade-devtron-ui.md)
Expand Down
16 changes: 10 additions & 6 deletions docs/user-guide/app-details/ephemeral-containers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Using Ephemeral Containers on Devtron
# Using Ephemeral Containers in Devtron

## Introduction

Expand Down Expand Up @@ -33,22 +33,26 @@ Wherever you can access pod resources in Devtron, you can launch an ephemeral co
![Figure 2: Launching an Ephemeral Container](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/debugging-deployment-and-monitoring/launch-ec-new.jpg)

7. You get 2 tabs:
* **Basic** - It provides the bare minimum configurations required to launch an ephemeral container.
1. **Basic** - It provides the bare minimum configurations required to launch an ephemeral container.

![Figure 3: Basic View](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/debugging-deployment-and-monitoring/basic.jpg)

It contains 3 mandatory fields:
* **Container name prefix** - Type a prefix to give to your ephemeral container, for e.g., *debug*. Your container name would look like `debug-jndvs`.
* **Image** - Choose an image to run from the dropdown. Ephemeral containers need an image to run and provide the capability to debug, such as `curl`. You can use a custom image too.
* **Target Container name** - Since a pod can have one or more containers, choose a target container you wish to debug, from the dropdown.

* **Advanced** - It is particularly useful for advanced users that wish to use labels or annotations since it provides additional key-value options. Refer [Ephemeral Container Spec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#ephemeralcontainer-v1-core) to view the supported options.
* **Container name prefix** - Type a prefix to give to your ephemeral container, for e.g., *debug*. Your container name would look like `debug-jndvs`.

* **Image** - Choose an image to run from the dropdown. Ephemeral containers need an image to run and provide the capability to debug, such as `curl`. You can use a custom image too.

* **Target Container name** - Since a pod can have one or more containers, choose a target container you wish to debug, from the dropdown.

2. **Advanced** - It is particularly useful for advanced users that wish to use labels or annotations since it provides additional key-value options. Refer [Ephemeral Container Spec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#ephemeralcontainer-v1-core) to view the supported options.

![Figure 4: Advanced View](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/debugging-deployment-and-monitoring/advanced.jpg)

{% hint style="info" %}
Devtron ignores the `command` field while launching an ephemeral container
{% endhint %}

8. Click **Launch Container**.

### From Devtron (Resource Browser)
Expand Down
15 changes: 10 additions & 5 deletions docs/user-guide/global-configurations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ Before you start creating an application, we recommend to provide basic informat

[Projects](projects.md)

[Cluster And Environments](cluster-and-environments.md)
[Clusters & Environments](cluster-and-environments.md)

[Git Accounts](git-accounts.md)

[Container Registries](docker-registries.md)
[Container/OCI Registry](container-registries.md)

[Chart Repositories](chart-repo.md)

[Custom Charts](custom-charts.md)

[SSO Login Services](sso-login.md)

[Authorization](https://docs.devtron.ai/global-configurations/authorization)
[Authorization](authorization.md)

[Manage Notification](manage-notification.md)
[Notifications](manage-notification.md)

[External Links](external-links.md)

[Scoped Variables](scoped-variables.md)

[Tags Policy](tags-policy.md)

You can also refer our youtube video provided here.
You can also refer our YouTube video provided here.

{% embed url="https://www.youtube.com/watch?v=4VFjrjtieMI" caption="" %}

Expand Down
Loading

0 comments on commit fa09e81

Please sign in to comment.