Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
"github.com/devtron-labs/authenticator/client"
"github.com/devtron-labs/common-lib/utils/k8s"
"github.com/devtron-labs/kubelink/api/router"
"github.com/devtron-labs/kubelink/internal/lock"
"github.com/devtron-labs/kubelink/internal/logger"
"github.com/devtron-labs/kubelink/converter"
"github.com/devtron-labs/kubelink/internals/lock"
"github.com/devtron-labs/kubelink/internals/logger"
repository "github.com/devtron-labs/kubelink/pkg/cluster"
"github.com/devtron-labs/kubelink/pkg/k8sInformer"
"github.com/devtron-labs/kubelink/pkg/service"
Expand All @@ -40,9 +41,12 @@ func InitializeApp() (*App, error) {
logger.NewSugaredLogger,
client.GetRuntimeConfig,
k8s.NewK8sUtil,
wire.Bind(new(k8s.K8sUtilIf), new(*k8s.K8sUtil)),
lock.NewChartRepositoryLocker,
service.NewK8sServiceImpl,
wire.Bind(new(service.K8sService), new(*service.K8sServiceImpl)),
converter.NewConverterImpl,
wire.Bind(new(converter.ClusterBeanConverter), new(*converter.ClusterBeanConverterImpl)),
service.NewHelmAppServiceImpl,
wire.Bind(new(service.HelmAppService), new(*service.HelmAppServiceImpl)),
service.NewApplicationServiceServerImpl,
Expand Down
39 changes: 14 additions & 25 deletions bean/Bean.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bean

import (
k8sUtils "github.com/devtron-labs/common-lib/utils/k8s"
client "github.com/devtron-labs/kubelink/grpc"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -193,28 +192,18 @@ type InfoItem struct {
}

type ClusterInfo struct {
ClusterId int `json:"clusterId"`
ClusterName string `json:"clusterName"`
BearerToken string `json:"bearerToken"`
ServerUrl string `json:"serverUrl"`
InsecureSkipTLSVerify bool `json:"insecureSkipTLSVerify"`
KeyData string `json:"-"`
CertData string `json:"-"`
CAData string `json:"-"`
}

func (cluster *ClusterInfo) GetClusterConfig() *k8sUtils.ClusterConfig {
clusterConfig := &k8sUtils.ClusterConfig{}
if cluster != nil {
clusterConfig = &k8sUtils.ClusterConfig{
Host: cluster.ServerUrl,
BearerToken: cluster.BearerToken,
ClusterName: cluster.ClusterName,
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
KeyData: cluster.KeyData,
CertData: cluster.CertData,
CAData: cluster.CAData,
}
}
return clusterConfig
ClusterId int `json:"clusterId"`
ClusterName string `json:"clusterName"`
BearerToken string `json:"bearerToken"`
ServerUrl string `json:"serverUrl"`
InsecureSkipTLSVerify bool `json:"insecureSkipTLSVerify"`
KeyData string `json:"-"`
CertData string `json:"-"`
CAData string `json:"-"`
ProxyUrl string `json:"proxyUrl"`
ToConnectWithSSHTunnel bool `json:"toConnectWithSSHTunnel'"`
SSHTunnelUser string `json:"sshTunnelUser"`
SSHTunnelPassword string `json:"sshTunnelPassword"`
SSHTunnelAuthKey string `json:"sshTunnelAuthKey"`
SSHTunnelServerAddress string `json:"sshTunnelServerAddress"`
}
76 changes: 76 additions & 0 deletions converter/ClusterBeanConverter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package converter

import (
k8sUtils "github.com/devtron-labs/common-lib/utils/k8s"
"github.com/devtron-labs/kubelink/bean"
client "github.com/devtron-labs/kubelink/grpc"
repository "github.com/devtron-labs/kubelink/pkg/cluster"
)

type ClusterBeanConverter interface {
GetClusterConfigFromClientBean(config *client.ClusterConfig) *k8sUtils.ClusterConfig
GetClusterConfig(cluster *bean.ClusterInfo) *k8sUtils.ClusterConfig
GetClusterInfo(c *repository.Cluster) *bean.ClusterInfo
}

type ClusterBeanConverterImpl struct {
}

func NewConverterImpl() *ClusterBeanConverterImpl {
return &ClusterBeanConverterImpl{}
}

func (impl *ClusterBeanConverterImpl) GetClusterConfigFromClientBean(config *client.ClusterConfig) *k8sUtils.ClusterConfig {
clusterConfig := &k8sUtils.ClusterConfig{}
if config != nil {
clusterConfig = &k8sUtils.ClusterConfig{
ClusterName: config.ClusterName,
Host: config.ApiServerUrl,
BearerToken: config.Token,
InsecureSkipTLSVerify: config.InsecureSkipTLSVerify,
}
if config.InsecureSkipTLSVerify == false {
clusterConfig.KeyData = config.GetKeyData()
clusterConfig.CertData = config.GetCertData()
clusterConfig.CAData = config.GetCaData()
}
}
return clusterConfig
}

func (impl *ClusterBeanConverterImpl) GetClusterConfig(cluster *bean.ClusterInfo) *k8sUtils.ClusterConfig {
clusterConfig := &k8sUtils.ClusterConfig{}
if cluster != nil {
clusterConfig = &k8sUtils.ClusterConfig{
Host: cluster.ServerUrl,
BearerToken: cluster.BearerToken,
ClusterName: cluster.ClusterName,
InsecureSkipTLSVerify: cluster.InsecureSkipTLSVerify,
KeyData: cluster.KeyData,
CertData: cluster.CertData,
CAData: cluster.CAData,
}
}
return clusterConfig
}

func (impl *ClusterBeanConverterImpl) GetClusterInfo(c *repository.Cluster) *bean.ClusterInfo {
clusterInfo := &bean.ClusterInfo{}
if c != nil {
config := c.Config
bearerToken := config["bearer_token"]
clusterInfo = &bean.ClusterInfo{
ClusterId: c.Id,
ClusterName: c.ClusterName,
BearerToken: bearerToken,
ServerUrl: c.ServerUrl,
InsecureSkipTLSVerify: c.InsecureSkipTlsVerify,
}
if c.InsecureSkipTlsVerify == false {
clusterInfo.KeyData = config[k8sUtils.TlsKey]
clusterInfo.CertData = config[k8sUtils.CertData]
clusterInfo.CAData = config[k8sUtils.CertificateAuthorityData]
}
}
return clusterInfo
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/aws/aws-sdk-go v1.44.285
github.com/caarlos0/env v3.5.0+incompatible
github.com/devtron-labs/common-lib v0.0.2-beta1
github.com/devtron-labs/common-lib v0.0.6-0.20231102115658-74728a36c209
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/go-pg/pg v6.15.1+incompatible
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/devtron-labs/authenticator v0.4.31 h1:CEMLek3JnMuH9ULsC6BHNJr+NiyGzBd4lgdSxH2IGnc=
github.com/devtron-labs/authenticator v0.4.31/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU=
github.com/devtron-labs/common-lib v0.0.2-beta1 h1:OELgqaWN08dm6vLl4JUD9w6rM0xDXTCTIuinndIP0/E=
github.com/devtron-labs/common-lib v0.0.2-beta1/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM=
github.com/devtron-labs/common-lib v0.0.6-0.20231102060313-8b6fcf14e04b h1:mcVHBw+rDlKn5zLIBIUiMzWBPsTbYBGj7NAj8WptA4s=
github.com/devtron-labs/common-lib v0.0.6-0.20231102060313-8b6fcf14e04b/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM=
github.com/devtron-labs/common-lib v0.0.6-0.20231102113705-37878c811d44 h1:XyyIuGiWsvya1BuNz4xeRCO1pZMgs+CKjtRozyYJ+Xk=
github.com/devtron-labs/common-lib v0.0.6-0.20231102113705-37878c811d44/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM=
github.com/devtron-labs/common-lib v0.0.6-0.20231102115658-74728a36c209 h1:OdkFmvykH6cgtjK2bDiJml27AX2n1LJWNsvoK85tMNY=
github.com/devtron-labs/common-lib v0.0.6-0.20231102115658-74728a36c209/go.mod h1:x6OdUIo2z9kxXtBfz7fJEfD4s8kiAtEmlApozOf7ECM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2 h1:aBfCb7iqHmDEIp6fBvC/hQUddQfg+3qdYjwzaiP9Hnc=
Expand Down
Loading