Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ba36ebc
refactoring and removing unused dependancies in implementation
Shivam-nagar23 Jul 14, 2023
eb31477
Test refactoring
Shivam-nagar23 Jul 14, 2023
d9f4e0d
main-merge
Shivam-nagar23 Jul 14, 2023
4336557
cluster service refactoring
Shivam-nagar23 Jul 14, 2023
617bd5a
capacity Service
Shivam-nagar23 Jul 17, 2023
4aa632a
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 17, 2023
b8a623b
const
Shivam-nagar23 Jul 17, 2023
dbc3ce1
review-refactoring
Shivam-nagar23 Jul 17, 2023
5a078c8
client-service-removal
Shivam-nagar23 Jul 18, 2023
d29a984
merge-main
Shivam-nagar23 Jul 18, 2023
6f696c4
Refactoring pkg k8s and api k8s
Shivam-nagar23 Jul 19, 2023
6926b17
refactoring kubernetes calls
Shivam-nagar23 Jul 19, 2023
7aaf9df
rest config calls
Shivam-nagar23 Jul 19, 2023
f169eb6
refactoring of rest config
Shivam-nagar23 Jul 19, 2023
a7bb1c9
removed unnecessary comments
Shivam-nagar23 Jul 19, 2023
c980291
removing unnecessary changes
Shivam-nagar23 Jul 20, 2023
ca1adf4
self-review-changes
Shivam-nagar23 Jul 20, 2023
b9d4403
main-merge
Shivam-nagar23 Jul 20, 2023
1c50f29
self-review changes
Shivam-nagar23 Jul 21, 2023
0e18bff
review changes
Shivam-nagar23 Jul 24, 2023
f168971
resolving merge-conflicts
Shivam-nagar23 Jul 24, 2023
b1cf991
review-comment
Shivam-nagar23 Jul 24, 2023
b3f62d9
refactoring
kartik-579 Jul 24, 2023
5677f66
name changes refactoring
Shivam-nagar23 Jul 24, 2023
2256563
minor refactoring
kartik-579 Jul 24, 2023
468bb00
resolving config issue
Shivam-nagar23 Jul 25, 2023
940cb88
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 25, 2023
984dd5e
upgraded go version to 1.20
kartik-579 Jul 25, 2023
11ea22c
Merge branch 'kubernetes-api-refactoring' of github.com:devtron-labs/…
kartik-579 Jul 25, 2023
b084fb4
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 25, 2023
76e9307
refactoring recreate resource to application service
Shivam-nagar23 Jul 26, 2023
81b2157
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 26, 2023
a355903
refactored common service to improve abstraction layer
kartik-579 Jul 26, 2023
3366590
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 26, 2023
0ea4a49
Merge branch 'main' into kubernetes-api-refactoring
Shivam-nagar23 Jul 27, 2023
aac0435
wire cmd
Shivam-nagar23 Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 AS build-env
FROM golang:1.20 AS build-env

RUN echo $GOPATH
RUN apt update
Expand Down
2 changes: 1 addition & 1 deletion DockerfileEA
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 AS build-env
FROM golang:1.20 AS build-env

RUN echo $GOPATH
RUN apt update
Expand Down
5 changes: 3 additions & 2 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/devtron-labs/devtron/api/deployment"
"github.com/devtron-labs/devtron/api/externalLink"
client "github.com/devtron-labs/devtron/api/helm-app"
"github.com/devtron-labs/devtron/api/k8s"
"github.com/devtron-labs/devtron/api/module"
"github.com/devtron-labs/devtron/api/restHandler"
pipeline2 "github.com/devtron-labs/devtron/api/restHandler/app"
Expand Down Expand Up @@ -112,7 +113,7 @@ import (
util3 "github.com/devtron-labs/devtron/pkg/util"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/devtron-labs/devtron/util/k8s"
util4 "github.com/devtron-labs/devtron/util/k8s"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/google/wire"
)
Expand All @@ -126,6 +127,7 @@ func InitializeApp() (*App, error) {
externalLink.ExternalLinkWireSet,
team.TeamsWireSet,
AuthWireSet,
util4.NewK8sUtil,
user.UserWireSet,
sso.SsoConfigWireSet,
cluster.ClusterWireSet,
Expand Down Expand Up @@ -358,7 +360,6 @@ func InitializeApp() (*App, error) {
wire.Bind(new(repository8.ImageTaggingRepository), new(*repository8.ImageTaggingRepositoryImpl)),
pipeline.NewImageTaggingServiceImpl,
wire.Bind(new(pipeline.ImageTaggingService), new(*pipeline.ImageTaggingServiceImpl)),
util.NewK8sUtil,
argocdServer.NewVersionServiceImpl,
wire.Bind(new(argocdServer.VersionService), new(*argocdServer.VersionServiceImpl)),

Expand Down
32 changes: 13 additions & 19 deletions api/cluster/EnvironmentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ package cluster
import (
"context"
"encoding/json"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/util/k8s"
"k8s.io/client-go/kubernetes"
"github.com/devtron-labs/devtron/pkg/k8s"
k8s2 "github.com/devtron-labs/devtron/util/k8s"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -60,12 +59,13 @@ type EnvironmentRestHandler interface {

type EnvironmentRestHandlerImpl struct {
environmentClusterMappingsService request.EnvironmentService
k8sApplicationService k8s.K8sApplicationService
k8sCommonService k8s.K8sCommonService
logger *zap.SugaredLogger
userService user.UserService
validator *validator.Validate
enforcer casbin.Enforcer
deleteService delete2.DeleteService
k8sUtil *k8s2.K8sUtil
cfg *bean.Config
}

Expand All @@ -74,10 +74,7 @@ type ClusterReachableResponse struct {
ClusterName string `json:"clusterName"`
}

func NewEnvironmentRestHandlerImpl(svc request.EnvironmentService, k8sApplicationService k8s.K8sApplicationService, logger *zap.SugaredLogger, userService user.UserService,
validator *validator.Validate, enforcer casbin.Enforcer,
deleteService delete2.DeleteService,
) *EnvironmentRestHandlerImpl {
func NewEnvironmentRestHandlerImpl(svc request.EnvironmentService, logger *zap.SugaredLogger, userService user.UserService, validator *validator.Validate, enforcer casbin.Enforcer, deleteService delete2.DeleteService, k8sUtil *k8s2.K8sUtil, k8sCommonService k8s.K8sCommonService) *EnvironmentRestHandlerImpl {
cfg := &bean.Config{}
err := env.Parse(cfg)
if err != nil {
Expand All @@ -87,13 +84,14 @@ func NewEnvironmentRestHandlerImpl(svc request.EnvironmentService, k8sApplicatio
logger.Infow("evironment rest handler initialized", "ignoreAuthCheckValue", cfg.IgnoreAuthCheck)
return &EnvironmentRestHandlerImpl{
environmentClusterMappingsService: svc,
k8sApplicationService: k8sApplicationService,
logger: logger,
userService: userService,
validator: validator,
enforcer: enforcer,
deleteService: deleteService,
cfg: cfg,
k8sUtil: k8sUtil,
k8sCommonService: k8sCommonService,
}
}

Expand Down Expand Up @@ -514,30 +512,26 @@ func (impl EnvironmentRestHandlerImpl) GetEnvironmentConnection(w http.ResponseW
}
//RBAC enforcer Ends
// getting restConfig and clientSet outside the goroutine because we don't want to call goroutine func with receiver function
restConfig, err := impl.k8sApplicationService.GetRestConfigByClusterId(context.Background(), clusterBean.Id)
restConfig, err, _ := impl.k8sCommonService.GetRestConfigByClusterId(context.Background(), clusterBean.Id)
if err != nil {
impl.logger.Errorw("error in getting restConfig by cluster", "err", err, "clusterId", clusterBean.Id)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
k8sHttpClient, err := util.OverrideK8sHttpClientWithTracer(restConfig)
k8sClientSet, err := impl.k8sUtil.CreateK8sClientSet(restConfig)
if err != nil {
impl.logger.Errorw("service err, OverrideK8sHttpClientWithTracer", "err", err, "restConfig", restConfig)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
k8sClientSet, err := kubernetes.NewForConfigAndClient(restConfig, k8sHttpClient)
if err != nil {
impl.logger.Errorw("error in getting client set by rest config", "err", err, "restConfig", restConfig)
impl.logger.Errorw("error in creating k8s clientSet", "err", err, "clusterId", clusterBean.Id)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

responseObj := &ClusterReachableResponse{
ClusterReachable: true,
ClusterName: clusterBean.ClusterName,
}
err = impl.k8sApplicationService.FetchConnectionStatusForCluster(k8sClientSet, clusterBean.Id)
err = impl.k8sUtil.FetchConnectionStatusForCluster(k8sClientSet)
if err != nil {
impl.logger.Errorw("error in fetching connection status fo cluster", "err", err, "clusterId", clusterBean.Id)
responseObj.ClusterReachable = false
}
//updating the cluster connection error to db
Expand Down
15 changes: 5 additions & 10 deletions api/helm-app/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/devtron-labs/devtron/util/k8s"
"net/http"
"reflect"
"strconv"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/devtron-labs/devtron/api/connector"
openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"
openapi2 "github.com/devtron-labs/devtron/api/openapi/openapiClient"
"github.com/devtron-labs/devtron/client/k8s/application"
"github.com/devtron-labs/devtron/internal/middleware"
"github.com/devtron-labs/devtron/internal/sql/repository/app"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
Expand Down Expand Up @@ -78,7 +78,7 @@ type HelmAppServiceImpl struct {
installedAppRepository repository.InstalledAppRepository
appRepository app.AppRepository
clusterRepository clusterRepository.ClusterRepository
K8sUtil *util.K8sUtil
K8sUtil *k8s.K8sUtil
helmReleaseConfig *HelmReleaseConfig
}

Expand All @@ -88,7 +88,7 @@ func NewHelmAppServiceImpl(Logger *zap.SugaredLogger, clusterService cluster.Clu
appStoreApplicationVersionRepository appStoreDiscoverRepository.AppStoreApplicationVersionRepository,
environmentService cluster.EnvironmentService, pipelineRepository pipelineConfig.PipelineRepository,
installedAppRepository repository.InstalledAppRepository, appRepository app.AppRepository,
clusterRepository clusterRepository.ClusterRepository, K8sUtil *util.K8sUtil,
clusterRepository clusterRepository.ClusterRepository, K8sUtil *k8s.K8sUtil,
helmReleaseConfig *HelmReleaseConfig) *HelmAppServiceImpl {
return &HelmAppServiceImpl{
logger: Logger,
Expand Down Expand Up @@ -121,11 +121,6 @@ func GetHelmReleaseConfig() (*HelmReleaseConfig, error) {
return cfg, err
}

type ResourceRequestBean struct {
AppId string `json:"appId"`
K8sRequest application.K8sRequestBean `json:"k8sRequest"`
}

func (impl *HelmAppServiceImpl) listApplications(ctx context.Context, clusterIds []int) (ApplicationService_ListApplicationsClient, error) {
if len(clusterIds) == 0 {
return nil, nil
Expand All @@ -141,7 +136,7 @@ func (impl *HelmAppServiceImpl) listApplications(ctx context.Context, clusterIds
for _, clusterDetail := range clusters {
config := &ClusterConfig{
ApiServerUrl: clusterDetail.ServerUrl,
Token: clusterDetail.Config[util.BearerToken],
Token: clusterDetail.Config[k8s.BearerToken],
ClusterId: int32(clusterDetail.Id),
ClusterName: clusterDetail.ClusterName,
}
Expand Down Expand Up @@ -266,7 +261,7 @@ func (impl *HelmAppServiceImpl) GetClusterConf(clusterId int) (*ClusterConfig, e
}
config := &ClusterConfig{
ApiServerUrl: cluster.ServerUrl,
Token: cluster.Config[util.BearerToken],
Token: cluster.Config[k8s.BearerToken],
ClusterId: int32(cluster.Id),
ClusterName: cluster.ClusterName,
}
Expand Down
1 change: 0 additions & 1 deletion api/helm-app/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import openapi "github.com/devtron-labs/devtron/api/helm-app/openapiClient"

const (
DEFAULT_CLUSTER = "default_cluster"
DEFAULT_CLUSTER_ID = 1
SOURCE_DEVTRON_APP SourceAppType = "devtron-app"
SOURCE_HELM_APP SourceAppType = "helm-app"
Expand Down
Loading