Skip to content

Commit

Permalink
feat: Kube capacity support (devtron-labs#1601)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* updated argo cd version

* updated k8s/application.go as per k8s library

* updated imports for argo-workflows and argo-cd lib

* cleared sessionManager implementations

* handled changes in gitlab lib update

* handled lib changes in k8sUtil.go

* updated AppListingService.go and AppService.go

* added argoproj/gitops-engine lib

* updated CILogService.go & WorkflowDagExecutor.go

* updated InstalledAppService.go & AppListingRestHandler.go

* updated go version

* fixed go version

* updated argocd image

* Added new argocd manifests

* updated authenticator import

* script-changes

* fixed loginService binding

* updated authenticator

* updated installation script for initial argocd pwd

* updated log for debugging

* updated Dockerfile

* updated Dockerfile

* updated Dockerfile

* removed googleapis/gnostic

* resynced googleapis/gnostic

* updated argo-cd/assets

* updated vendor files and k8sCapacityService.go

* updated deprecated apis - argo cd repository

* updated spec

* updated spec

* wip

* updated spec

* updated k8sApplicationService.go

* changes in spec

* changes in spec

* wip - completed node detail api

* wip - update manifest

* updated bean

* updated orchestrator image

* updated labels data in node listing api

* update err handling for cluster detail

* updated logs for debugigng

* wip

* fix bug - resource list addition panic

* updated response for cluster listing api

* updated group for manifest fetch/update request

* hardcoded cluster list for testing

* added log

* updated node errors field in cluster listing api resp

* updated node gvk for manifest fetch request

* updated logs for debugging

* updated missing field data - part 1

* updated missing field data - part 2

* wip

* fixed taint and nodeError issue

* updated vendor/argoproj/argo-cd/assets

* updated condition filtering in node detail

* update node error condition for testing

* updated devtron image

* updated cron service for getting cluster connection status

* updated cluster name in connected cluster resp

* updated cluster cron service status error

* updated node error for testing

* updated resource value string

* fixed limits and requests logic

* wip - updated allocatable field in node detail api

* updated resource values

* updated server version

* updated resoource string

* removed unneeded network policy

* updated resp for sorting at FE

* updated orchestrator image

* updated rbac

* updated argocd lib version to v2.4.0

* updated argo cd image in manifest

* update manifest

* fixed bug for cluster detail page and rbac

* updated devtron image

* updated logs for debugging

* updated fix for non-default cluster unauthorized issue

* added TODO

* updated handling for clusters without metrics server

* wip

* changes for unavailable resource usage statistics and error handling

* added argoUserService

* wip

* fixed wiring issues, updated argo api calls with new token

* wip - token creation workaround

* wip

* fixed ea build issue

* fixed token no extraction panic

* updated devtron image

* updated script no

* updated app detail health status

* updated devtron image

* updated devtron image

* review change

* review change

* updated devtron image

* updated capability

* updated image

* updated code for cascade delete argo pipeline

* updated authenticator import

* merged argo-update

* updated script no

* restored argocd assets

Co-authored-by: pawan-59 <[email protected]>
Co-authored-by: nishant <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2022
1 parent 3d69545 commit 6a8020e
Show file tree
Hide file tree
Showing 54 changed files with 7,999 additions and 12 deletions.
Empty file added 688
Empty file.
5 changes: 5 additions & 0 deletions api/restHandler/common/apiError.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func WriteJsonResp(w http.ResponseWriter, err error, respBody interface{}, statu
apiErr.InternalMessage = errStatus.Error()
apiErr.UserMessage = errStatus.Error()
response.Errors = []*util.ApiError{apiErr}
} else if unexpectedObjectError, ok := err.(*errors2.UnexpectedObjectError); ok {
apiErr := &util.ApiError{}
apiErr.InternalMessage = unexpectedObjectError.Error()
apiErr.UserMessage = unexpectedObjectError.Error()
response.Errors = []*util.ApiError{apiErr}
} else {
apiErr := &util.ApiError{}
apiErr.Code = "000" // 000=unknown
Expand Down
7 changes: 6 additions & 1 deletion api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type MuxRouter struct {
serverRouter server.ServerRouter
apiTokenRouter apiToken.ApiTokenRouter
helmApplicationStatusUpdateHandler cron.HelmApplicationStatusUpdateHandler
k8sCapacityRouter k8s.K8sCapacityRouter
}

func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConfigRouter PipelineConfigRouter,
Expand All @@ -135,7 +136,7 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConf
commonDeploymentRouter appStoreDeployment.CommonDeploymentRouter, externalLinkRouter externalLink.ExternalLinkRouter,
globalPluginRouter GlobalPluginRouter, selfRegistrationRolesRouter user.SelfRegistrationRolesRouter, moduleRouter module.ModuleRouter,
serverRouter server.ServerRouter, apiTokenRouter apiToken.ApiTokenRouter,
helmApplicationStatusUpdateHandler cron.HelmApplicationStatusUpdateHandler) *MuxRouter {
helmApplicationStatusUpdateHandler cron.HelmApplicationStatusUpdateHandler, k8sCapacityRouter k8s.K8sCapacityRouter) *MuxRouter {
r := &MuxRouter{
Router: mux.NewRouter(),
HelmRouter: HelmRouter,
Expand Down Expand Up @@ -198,6 +199,7 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConf
serverRouter: serverRouter,
apiTokenRouter: apiTokenRouter,
helmApplicationStatusUpdateHandler: helmApplicationStatusUpdateHandler,
k8sCapacityRouter: k8sCapacityRouter,
}
return r
}
Expand Down Expand Up @@ -388,4 +390,7 @@ func (r MuxRouter) Init() {
// api-token router
apiTokenRouter := r.Router.PathPrefix("/orchestrator/api-token").Subrouter()
r.apiTokenRouter.InitApiTokenRouter(apiTokenRouter)

k8sCapacityApp := r.Router.PathPrefix("/orchestrator/k8s/capacity").Subrouter()
r.k8sCapacityRouter.InitK8sCapacityRouter(k8sCapacityApp)
}
6 changes: 6 additions & 0 deletions cmd/external-app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type MuxRouter struct {
moduleRouter module.ModuleRouter
serverRouter server.ServerRouter
apiTokenRouter apiToken.ApiTokenRouter
k8sCapacityRouter k8s.K8sCapacityRouter
}

func NewMuxRouter(
Expand All @@ -69,6 +70,7 @@ func NewMuxRouter(
externalLinkRouter externalLink.ExternalLinkRouter,
moduleRouter module.ModuleRouter,
serverRouter server.ServerRouter, apiTokenRouter apiToken.ApiTokenRouter,
k8sCapacityRouter k8s.K8sCapacityRouter,
) *MuxRouter {
r := &MuxRouter{
Router: mux.NewRouter(),
Expand All @@ -92,6 +94,7 @@ func NewMuxRouter(
moduleRouter: moduleRouter,
serverRouter: serverRouter,
apiTokenRouter: apiTokenRouter,
k8sCapacityRouter: k8sCapacityRouter,
}
return r
}
Expand Down Expand Up @@ -153,6 +156,9 @@ func (r *MuxRouter) Init() {
k8sApp := r.Router.PathPrefix("/orchestrator/k8s").Subrouter()
r.k8sApplicationRouter.InitK8sApplicationRouter(k8sApp)

k8sCapacityApp := r.Router.PathPrefix("/orchestrator/k8s/capacity").Subrouter()
r.k8sCapacityRouter.InitK8sCapacityRouter(k8sCapacityApp)

// chart-repo router starts
chartRepoRouter := r.Router.PathPrefix("/orchestrator/chart-repo").Subrouter()
r.chartRepositoryRouter.Init(chartRepoRouter)
Expand Down
9 changes: 8 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.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ require (
k8s.io/apimachinery v0.23.3
k8s.io/client-go v11.0.1-0.20190820062731-7e43eff7c80a+incompatible
k8s.io/helm v2.12.3+incompatible
k8s.io/kubectl v0.23.1
k8s.io/metrics v0.23.1
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
sigs.k8s.io/yaml v1.3.0
)
Expand Down Expand Up @@ -234,7 +236,6 @@ require (
k8s.io/klog/v2 v2.40.1 // indirect
k8s.io/kube-aggregator v0.23.1 // indirect
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf // indirect
k8s.io/kubectl v0.23.1 // indirect
k8s.io/kubernetes v1.23.1 // indirect
mellium.im/sasl v0.2.1 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,7 @@ k8s.io/kubelet v0.23.1/go.mod h1:WdvMiehtNPhtiW8sSVVvr8YYU00L0u+0HkfMDEB0LKM=
k8s.io/kubernetes v1.23.1 h1:iJfubd03CDap4m69Ue+u2I6quNUYiYlC8+TakEHATjc=
k8s.io/kubernetes v1.23.1/go.mod h1:baMGbPpwwP0kT/+eAPtdqoWNRoXyyTJ2Zf+fw/Y8t04=
k8s.io/legacy-cloud-providers v0.23.1/go.mod h1:HIt+r/ReEfjS6IGaGfpZ7tCna7hbMBXMOaIp/SWABVE=
k8s.io/metrics v0.23.1 h1:ZKrRdjarB/JPl4nPef7SlMjAUUVzU5XdSKgT+cm6bFA=
k8s.io/metrics v0.23.1/go.mod h1:qXvsM1KANrc+ZZeFwj6Phvf0NLiC+d3RwcsLcdGc+xs=
k8s.io/mount-utils v0.23.1/go.mod h1:9pFhzVjxle1osJUo++9MFDat9HPkQUOoHCn+eExZ3Ew=
k8s.io/pod-security-admission v0.23.1/go.mod h1:WDb/vFWf7jKSGe2e07LTEjDZ0MHMDhUIzXNvQ45HytU=
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/ClusterService.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ClusterBean struct {
AgentInstallationStage int `json:"agentInstallationStage,notnull"` // -1=external, 0=not triggered, 1=progressing, 2=success, 3=fails
K8sVersion string `json:"k8sVersion"`
HasConfigOrUrlChanged bool `json:"-"`
ErrorInConnecting string `json:"-"`
}

type PrometheusAuth struct {
Expand Down Expand Up @@ -240,6 +241,8 @@ func (impl *ClusterServiceImpl) FindAll() ([]*ClusterBean, error) {
ServerUrl: m.ServerUrl,
Active: m.Active,
K8sVersion: m.K8sVersion,
ErrorInConnecting: m.ErrorInConnecting,
Config: m.Config,
})
}
return beans, nil
Expand All @@ -261,6 +264,7 @@ func (impl *ClusterServiceImpl) FindAllActive() ([]ClusterBean, error) {
AgentInstallationStage: m.AgentInstallationStage,
Config: m.Config,
K8sVersion: m.K8sVersion,
ErrorInConnecting: m.ErrorInConnecting,
})
}
return beans, nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/repository/ClusterRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Cluster struct {
PTlsClientKey string `sql:"p_tls_client_key"`
AgentInstallationStage int `sql:"agent_installation_stage"`
K8sVersion string `sql:"k8s_version"`
ErrorInConnecting string `sql:"error_in_connecting"`
sql.AuditLog
}

Expand All @@ -53,6 +54,7 @@ type ClusterRepository interface {
Update(model *Cluster) error
Delete(model *Cluster) error
MarkClusterDeleted(model *Cluster) error
UpdateClusterConnectionStatus(clusterId int, errorInConnecting string) error
}

func NewClusterRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *ClusterRepositoryImpl {
Expand Down Expand Up @@ -144,3 +146,11 @@ func (impl ClusterRepositoryImpl) MarkClusterDeleted(model *Cluster) error {
model.Active = false
return impl.dbConnection.Update(model)
}

func (impl ClusterRepositoryImpl) UpdateClusterConnectionStatus(clusterId int, errorInConnecting string) error {
cluster := &Cluster{}
_, err := impl.dbConnection.Model(cluster).
Set("error_in_connecting = ?", errorInConnecting).Where("id = ?", clusterId).
Update()
return err
}
2 changes: 2 additions & 0 deletions scripts/sql/58_alter_cluster.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE cluster
DROP COLUMN error_in_connecting;
2 changes: 2 additions & 0 deletions scripts/sql/58_alter_cluster.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE cluster
ADD COLUMN error_in_connecting TEXT;
Loading

0 comments on commit 6a8020e

Please sign in to comment.