diff --git a/pisa-controller/cmd/pisa-controller/main.go b/pisa-controller/cmd/pisa-controller/main.go index 8b5aa2e5..ffb731c6 100644 --- a/pisa-controller/cmd/pisa-controller/main.go +++ b/pisa-controller/cmd/pisa-controller/main.go @@ -17,10 +17,10 @@ package main import ( "flag" + "github.com/database-mesh/golang-sdk/client" "github.com/database-mesh/pisanix/pisa-controller/cmd/pisa-controller/proxy" "github.com/database-mesh/pisanix/pisa-controller/cmd/pisa-controller/task" "github.com/database-mesh/pisanix/pisa-controller/cmd/pisa-controller/webhook" - "github.com/database-mesh/pisanix/pisa-controller/pkg/kubernetes" log "github.com/sirupsen/logrus" ) @@ -35,7 +35,7 @@ func init() { setVersion() log.Infof("version: %s, gitcommit: %s, branch: %s", version, gitcommit, branch) flag.Parse() - kubernetes.GetClient() + client.GetClient() } func main() { diff --git a/pisa-controller/go.mod b/pisa-controller/go.mod index 5fd5b765..3a80684e 100644 --- a/pisa-controller/go.mod +++ b/pisa-controller/go.mod @@ -3,13 +3,14 @@ module github.com/database-mesh/pisanix/pisa-controller go 1.18 require ( + github.com/database-mesh/golang-sdk v0.0.0-20220810081359-a6b298908fe8 github.com/gin-gonic/gin v1.7.7 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 - k8s.io/api v0.24.1 - k8s.io/apimachinery v0.24.1 - k8s.io/client-go v0.24.1 + k8s.io/api v0.24.3 + k8s.io/apimachinery v0.24.3 + k8s.io/client-go v0.24.3 ) require ( diff --git a/pisa-controller/go.sum b/pisa-controller/go.sum index a8261a07..d985c5f9 100644 --- a/pisa-controller/go.sum +++ b/pisa-controller/go.sum @@ -61,6 +61,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/database-mesh/golang-sdk v0.0.0-20220810081359-a6b298908fe8 h1:wUklErSiDemF6/D9chsSMT+gAyO9NEW+7WfxCoxTFkA= +github.com/database-mesh/golang-sdk v0.0.0-20220810081359-a6b298908fe8/go.mod h1:TFXAOuaEZzslEa6JJN2yviqOw90bkyQdQNZfHDaMTGM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -632,12 +634,12 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.24.1 h1:BjCMRDcyEYz03joa3K1+rbshwh1Ay6oB53+iUx2H8UY= -k8s.io/api v0.24.1/go.mod h1:JhoOvNiLXKTPQ60zh2g0ewpA+bnEYf5q44Flhquh4vQ= -k8s.io/apimachinery v0.24.1 h1:ShD4aDxTQKN5zNf8K1RQ2u98ELLdIW7jEnlO9uAMX/I= -k8s.io/apimachinery v0.24.1/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= -k8s.io/client-go v0.24.1 h1:w1hNdI9PFrzu3OlovVeTnf4oHDt+FJLd9Ndluvnb42E= -k8s.io/client-go v0.24.1/go.mod h1:f1kIDqcEYmwXS/vTbbhopMUbhKp2JhOeVTfxgaCIlF8= +k8s.io/api v0.24.3 h1:tt55QEmKd6L2k5DP6G/ZzdMQKvG5ro4H4teClqm0sTY= +k8s.io/api v0.24.3/go.mod h1:elGR/XSZrS7z7cSZPzVWaycpJuGIw57j9b95/1PdJNI= +k8s.io/apimachinery v0.24.3 h1:hrFiNSA2cBZqllakVYyH/VyEh4B581bQRmqATJSeQTg= +k8s.io/apimachinery v0.24.3/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= +k8s.io/client-go v0.24.3 h1:Nl1840+6p4JqkFWEW2LnMKU667BUxw03REfLAVhuKQY= +k8s.io/client-go v0.24.3/go.mod h1:AAovolf5Z9bY1wIg2FZ8LPQlEdKHjLI7ZD4rw920BJw= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/pisa-controller/pkg/kubernetes/client.go b/pisa-controller/pkg/kubernetes/client.go deleted file mode 100644 index f87a9d35..00000000 --- a/pisa-controller/pkg/kubernetes/client.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2022 SphereEx Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package kubernetes - -import ( - "flag" - "log" - "os" - "path/filepath" - "strings" - "sync" - - "k8s.io/client-go/dynamic" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" -) - -var client *KClient -var once sync.Once -var kubeConfigPath *string - -func init() { - kubeConfigPath = flag.String("kubeconfig", "", "(optional) absolute path to the kubeconfig file") -} - -type ConfigBuilder struct { - path string -} - -func NewConfigBuilder() *ConfigBuilder { - return &ConfigBuilder{ - path: "", - } -} - -func (b *ConfigBuilder) WithPath(path string) *ConfigBuilder { - b.path = path - return b -} - -func (b *ConfigBuilder) Build() (*rest.Config, error) { - if strings.EqualFold(b.path, "") { - config, err := rest.InClusterConfig() - if err != nil { - return nil, err - } - return config, nil - } else { - config, err := clientcmd.BuildConfigFromFlags("", b.path) - if err != nil { - return nil, err - } - return config, nil - } -} - -type ClientBuilder struct { - config *rest.Config -} - -func NewClientBuilder() *ClientBuilder { - return &ClientBuilder{ - config: &rest.Config{}, - } -} - -func (b *ClientBuilder) WithKubeConfig(config *rest.Config) *ClientBuilder { - b.config = config - return b -} - -func (b *ClientBuilder) Build() (dynamic.Interface, error) { - clientset, err := dynamic.NewForConfig(b.config) - if err != nil { - return nil, err - } - return clientset, nil -} - -func GetClient() *KClient { - once.Do(func() { - log.Println("kubeconfig", *kubeConfigPath) - if *kubeConfigPath != "" { - if _, err := os.Stat(*kubeConfigPath); os.IsNotExist(err) { - if home := homedir.HomeDir(); home != "" { - *kubeConfigPath = filepath.Join(home, ".kube", "config") - } - } - } - - config, err := NewConfigBuilder().WithPath(*kubeConfigPath).Build() - if err != nil { - log.Fatal(err) - } - clientset, err := NewClientBuilder().WithKubeConfig(config).Build() - if err != nil { - log.Fatal(err) - } - client = &KClient{} - client.Client = clientset - }) - - return client -} diff --git a/pisa-controller/pkg/kubernetes/resources.go b/pisa-controller/pkg/kubernetes/resources.go index 3b890b92..ff2829d2 100644 --- a/pisa-controller/pkg/kubernetes/resources.go +++ b/pisa-controller/pkg/kubernetes/resources.go @@ -17,6 +17,7 @@ package kubernetes import ( "context" + "github.com/database-mesh/golang-sdk/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/json" @@ -43,13 +44,13 @@ var ( } ) -func GetVirtualDatabaseWithContext(ctx context.Context, client dynamic.Interface, namespace, name string) (*VirtualDatabase, error) { - raw, err := client.Resource(VirtualDatabaseSchema).Namespace(namespace).Get(ctx, name, metav1.GetOptions{}) +func GetVirtualDatabaseWithContext(ctx context.Context, c dynamic.Interface, namespace, name string) (*client.VirtualDatabase, error) { + raw, err := c.Resource(VirtualDatabaseSchema).Namespace(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { return nil, err } - vdb := &VirtualDatabase{} + vdb := &client.VirtualDatabase{} data, err := json.Marshal(raw) if err != nil { return nil, err @@ -63,9 +64,9 @@ func GetVirtualDatabaseWithContext(ctx context.Context, client dynamic.Interface return vdb, nil } -func GetTrafficStrategyListWithContext(ctx context.Context, client dynamic.Interface, namespace string) (*TrafficStrategyList, error) { - tslist := &TrafficStrategyList{} - raw, err := client.Resource(TrafficStrategySchema).Namespace(namespace).List(ctx, metav1.ListOptions{}) +func GetTrafficStrategyListWithContext(ctx context.Context, c dynamic.Interface, namespace string) (*client.TrafficStrategyList, error) { + tslist := &client.TrafficStrategyList{} + raw, err := c.Resource(TrafficStrategySchema).Namespace(namespace).List(ctx, metav1.ListOptions{}) if err != nil { return nil, err } @@ -83,9 +84,9 @@ func GetTrafficStrategyListWithContext(ctx context.Context, client dynamic.Inter return tslist, nil } -func GetDatabaseEndpointListWithContext(ctx context.Context, client dynamic.Interface, namespace string) (*DatabaseEndpointList, error) { - dbeplist := &DatabaseEndpointList{} - raw, err := client.Resource(DatabaseEndpointSchema).Namespace(namespace).List(ctx, metav1.ListOptions{}) +func GetDatabaseEndpointListWithContext(ctx context.Context, c dynamic.Interface, namespace string) (*client.DatabaseEndpointList, error) { + dbeplist := &client.DatabaseEndpointList{} + raw, err := c.Resource(DatabaseEndpointSchema).Namespace(namespace).List(ctx, metav1.ListOptions{}) if err != nil { return nil, err } diff --git a/pisa-controller/pkg/kubernetes/types.go b/pisa-controller/pkg/kubernetes/types.go deleted file mode 100644 index d1c3e06c..00000000 --- a/pisa-controller/pkg/kubernetes/types.go +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2022 SphereEx Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package kubernetes - -import ( - "time" - - "k8s.io/client-go/dynamic" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type VirtualDatabase struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec VirtualDatabaseSpec `json:"spec,omitempty"` - Status VirtualDatabaseStatus `json:"status,omitempty"` -} - -// VirtualDatabaseSpec defines the desired state of VirtualDatabase -type VirtualDatabaseSpec struct { - Services []VirtualDatabaseService `json:"services"` -} - -// Service Defines the content of a VirtualDatabase -type VirtualDatabaseService struct { - DatabaseService `json:",inline"` - - Name string `json:"name"` - TrafficStrategy string `json:"trafficStrategy"` -} - -// DatabaseService The type of VirtualDatabase that needs to be applied for. -// Current support: databaseMySQL -type DatabaseService struct { - DatabaseMySQL *DatabaseMySQL `json:"databaseMySQL"` -} - -// DatabaseMySQL The type one of VirtualDatabase.Represents a virtual MySQL type -type DatabaseMySQL struct { - Host string `json:"host,omitempty"` - Port uint32 `json:"port,omitempty"` - User string `json:"user,omitempty"` - Password string `json:"password,omitempty"` - DB string `json:"db,omitempty"` - PoolSize uint32 `json:"poolSize,omitempty"` - ServerVersion string `json:"serverVersion,omitempty"` -} - -// VirtualDatabaseStatus defines the observed state of VirtualDatabase -// Endpoints display the name of the associated DatabaseEndpoint -// TODO: Implement dynamic updates -type VirtualDatabaseStatus struct { - Endpoints []string `json:"endpoints"` -} - -type TrafficStrategyList struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Items []TrafficStrategy `json:"items"` -} - -type TrafficStrategy struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec TrafficStrategySpec `json:"spec,omitempty"` -} - -// TrafficStrategySpec defines the desired state of TrafficStrategy -type TrafficStrategySpec struct { - Selector *metav1.LabelSelector `json:"selector"` - LoadBalance *LoadBalance `json:"loadBalance,omitempty"` - CircuitBreaks []CircuitBreak `json:"circuitBreaks,omitempty"` - ConcurrencyControls []ConcurrencyControl `json:"concurrencyControls,omitempty"` -} - -// LoadBalance The choice of load balancing strategy, currently supported: SimpleLoadBalance -type LoadBalance struct { - ReadWriteSplitting *ReadWriteSplitting `json:"readWriteSplitting,omitempty"` - SimpleLoadBalance *SimpleLoadBalance `json:"simpleLoadBalance,omitempty"` -} - -// ReadWriteSplitting support static and dynamic read-write splitting algorithm -type ReadWriteSplitting struct { - Static *ReadWriteSplittingStatic `json:"static"` - Dynamic *ReadWriteSplittingDynamic `json:"dynamic"` -} - -// ReadWriteSplittingStatic defines static rules based read-write splitting algorithm -type ReadWriteSplittingStatic struct { - DefaultTarget string `json:"defaultTarget,omitempty"` - Rules []ReadWriteSplittingRule `json:"rules,omitempty"` -} - -// ReadWriteSplittingStaticRule defines static rules -type ReadWriteSplittingRule struct { - Name string `json:"name"` - Type RuleType `json:"type"` - Regex []string `json:"regex"` - Target string `json:"target"` - AlgorithmName LoadBalanceAlgorithm `json:"algorithmName"` -} - -type ReadWriteSplittingDynamic struct { - DefaultTarget string `json:"defaultTarget,omitempty"` - Rules []ReadWriteSplittingRule `json:"rules,omitempty"` - Discovery ReadWriteDiscovery `json:"discovery"` -} - -type ReadWriteDiscovery struct { - MasterHighAvailability *MasterHighAvailability `json:"masterHighAvailability,omitempty"` -} - -type MasterHighAvailability struct { - User string `json:"user"` - Password string `json:"password"` - MonitorInterval uint64 `json:"monitorInterval"` - ConnectionProbe *ConnectionProbe `json:"connectionProbe"` - PingProbe *PingProbe `json:"pingProbe"` - ReplicationLagProbe *ReplicationLagProbe `json:"replicationLagProbe"` - ReadOnlyProbe *ReadOnlyProbe `json:"readOnlyProbe"` -} - -type ReadOnlyProbe struct { - *Probe -} - -type ReplicationLagProbe struct { - *Probe - MaxReplicationLag uint64 `json:"maxReplicationLag"` -} - -type PingProbe struct { - *Probe -} - -type ConnectionProbe struct { - *Probe -} - -type Probe struct { - PeriodMilliseconds uint64 `json:"periodMilliseconds"` - TimeoutMilliseconds uint64 `json:"timeoutMilliseconds"` - FailureThreshold uint64 `json:"failureThreshold"` - SuccessThreshold uint64 `json:"successThreshold"` -} - -// RuleType defines the type of static rule -type RuleType string - -const ( - RuleTypeRegex = "regex" -) - -// LoadBalanceAlgorithm defines the name of managed loadbalance algorithm -type LoadBalanceAlgorithm string - -const ( - LoadBalanceAlgorithmRandom = "random" - LoadBalanceAlgorithmRoundRobin = "roundrobin" -) - -// SimpleLoadBalance support load balancing type: 1. random 2. roundrobin -type SimpleLoadBalance struct { - Kind LoadBalanceAlgorithm `json:"kind"` -} - -// CircuitBreak works with regular expressions. -// SQL statements that conform to regular expressions will be denied. -type CircuitBreak struct { - Regex []string `json:"regex"` -} - -// ConcurrencyControl works according to regular expressions. -// SQL statements that meet the regular conditions will be blown after the maximum concurrency limit is exceeded. -type ConcurrencyControl struct { - Regex []string `json:"regex"` - Duration time.Duration `json:"duration"` // Issue: Duration:1ns in fmt.Print - MaxConcurrency int `json:"maxConcurrency"` -} - -type DatabaseEndpointList struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Items []DatabaseEndpoint `json:"items"` -} - -type DatabaseEndpoint struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec DatabaseEndpointSpec `json:"spec,omitempty"` -} - -// DatabaseEndpointSpec defines the desired state of DatabaseEndpoint -type DatabaseEndpointSpec struct { - Database Database `json:"database"` -} - -// Database Backend data source type -type Database struct { - MySQL *MySQL `json:"MySQL"` -} - -// MySQL Configuration Definition -type MySQL struct { - Host string `json:"host"` - Port uint32 `json:"port"` - User string `json:"user"` - Password string `json:"password"` - DB string `json:"db"` -} - -// KClient client for kubernetes -type KClient struct { - Client dynamic.Interface -} diff --git a/pisa-controller/pkg/proxy/builder.go b/pisa-controller/pkg/proxy/builder.go index 7f16faab..ef8d6851 100644 --- a/pisa-controller/pkg/proxy/builder.go +++ b/pisa-controller/pkg/proxy/builder.go @@ -16,7 +16,7 @@ package proxy import ( "fmt" - "github.com/database-mesh/pisanix/pisa-controller/pkg/kubernetes" + "github.com/database-mesh/golang-sdk/client" ) type PisaProxyConfig struct { @@ -144,26 +144,26 @@ func (b *ProxyConfigBuilder) Build() *ProxyConfig { } type ProxyBuilder struct { - VirtualDatabaseService kubernetes.VirtualDatabaseService - TrafficStrategy kubernetes.TrafficStrategy - DatabaseEndpoints []kubernetes.DatabaseEndpoint + VirtualDatabaseService client.VirtualDatabaseService + TrafficStrategy client.TrafficStrategy + DatabaseEndpoints []client.DatabaseEndpoint } func NewProxyBuilder() *ProxyBuilder { return &ProxyBuilder{} } -func (b *ProxyBuilder) SetVirtualDatabaseService(svc kubernetes.VirtualDatabaseService) *ProxyBuilder { +func (b *ProxyBuilder) SetVirtualDatabaseService(svc client.VirtualDatabaseService) *ProxyBuilder { b.VirtualDatabaseService = svc return b } -func (b *ProxyBuilder) SetTrafficStrategy(ts kubernetes.TrafficStrategy) *ProxyBuilder { +func (b *ProxyBuilder) SetTrafficStrategy(ts client.TrafficStrategy) *ProxyBuilder { b.TrafficStrategy = ts return b } -func (b *ProxyBuilder) SetDatabaseEndpoints(dbeps []kubernetes.DatabaseEndpoint) *ProxyBuilder { +func (b *ProxyBuilder) SetDatabaseEndpoints(dbeps []client.DatabaseEndpoint) *ProxyBuilder { b.DatabaseEndpoints = dbeps return b } @@ -283,7 +283,7 @@ func (b *ProxyBuilder) Build() *Proxy { return proxy } -func BuildMySQLNodesFromDatabaseEndpoints(dbeps []kubernetes.DatabaseEndpoint) []MySQLNode { +func BuildMySQLNodesFromDatabaseEndpoints(dbeps []client.DatabaseEndpoint) []MySQLNode { nodes := []MySQLNode{} for _, dbep := range dbeps { if dbep.Spec.Database.MySQL != nil { @@ -321,16 +321,16 @@ func getDbEpRole(annotations map[string]string) (role string) { } type MySQLConfigBuilder struct { - VirtualDatabaseService kubernetes.VirtualDatabaseService - TrafficStrategy kubernetes.TrafficStrategy - DatabaseEndpoints []kubernetes.DatabaseEndpoint + VirtualDatabaseService client.VirtualDatabaseService + TrafficStrategy client.TrafficStrategy + DatabaseEndpoints []client.DatabaseEndpoint } func NewMySQLConfigBuilder() *MySQLConfigBuilder { return &MySQLConfigBuilder{} } -func (b *MySQLConfigBuilder) SetDatabaseEndpoints(dbeps []kubernetes.DatabaseEndpoint) *MySQLConfigBuilder { +func (b *MySQLConfigBuilder) SetDatabaseEndpoints(dbeps []client.DatabaseEndpoint) *MySQLConfigBuilder { b.DatabaseEndpoints = dbeps return b } diff --git a/pisa-controller/pkg/proxy/http.go b/pisa-controller/pkg/proxy/http.go index f99c1111..a6c6b90a 100644 --- a/pisa-controller/pkg/proxy/http.go +++ b/pisa-controller/pkg/proxy/http.go @@ -19,6 +19,7 @@ import ( "net/http" "reflect" + "github.com/database-mesh/golang-sdk/client" "github.com/database-mesh/pisanix/pisa-controller/pkg/kubernetes" "github.com/gin-gonic/gin" @@ -28,8 +29,8 @@ import ( func GetConfig(ctx *gin.Context) { namespace := ctx.Param("namespace") appname := ctx.Param("appname") - client := kubernetes.GetClient() - proxyConfig, err := getConfig(ctx, client.Client, namespace, appname) + c := client.GetClient() + proxyConfig, err := getConfig(ctx, c.Client, namespace, appname) if err != nil { ctx.JSON(http.StatusBadRequest, err) return @@ -38,18 +39,18 @@ func GetConfig(ctx *gin.Context) { ctx.JSON(http.StatusOK, proxyConfig) } -func getConfig(ctx context.Context, client dynamic.Interface, namespace, appname string) (interface{}, error) { - vdb, err := kubernetes.GetVirtualDatabaseWithContext(ctx, client, namespace, appname) +func getConfig(ctx context.Context, c dynamic.Interface, namespace, appname string) (interface{}, error) { + vdb, err := kubernetes.GetVirtualDatabaseWithContext(ctx, c, namespace, appname) if err != nil { return nil, err } - tslist, err := kubernetes.GetTrafficStrategyListWithContext(ctx, client, namespace) + tslist, err := kubernetes.GetTrafficStrategyListWithContext(ctx, c, namespace) if err != nil { return nil, err } - dbeplist, err := kubernetes.GetDatabaseEndpointListWithContext(ctx, client, namespace) + dbeplist, err := kubernetes.GetDatabaseEndpointListWithContext(ctx, c, namespace) if err != nil { return nil, err } @@ -58,13 +59,13 @@ func getConfig(ctx context.Context, client dynamic.Interface, namespace, appname } -func build(vdb *kubernetes.VirtualDatabase, tslist *kubernetes.TrafficStrategyList, dbeplist *kubernetes.DatabaseEndpointList) (*PisaProxyConfig, error) { +func build(vdb *client.VirtualDatabase, tslist *client.TrafficStrategyList, dbeplist *client.DatabaseEndpointList) (*PisaProxyConfig, error) { builder := NewPisaProxyConfigBuilder() builders := []*ProxyBuilder{} for _, service := range vdb.Spec.Services { builder := NewProxyBuilder().SetVirtualDatabaseService(service) - var tsobj kubernetes.TrafficStrategy + var tsobj client.TrafficStrategy for _, ts := range tslist.Items { if ts.Name == service.TrafficStrategy { tsobj = ts @@ -72,7 +73,7 @@ func build(vdb *kubernetes.VirtualDatabase, tslist *kubernetes.TrafficStrategyLi } } - dbeps := &kubernetes.DatabaseEndpointList{Items: []kubernetes.DatabaseEndpoint{}} + dbeps := &client.DatabaseEndpointList{Items: []client.DatabaseEndpoint{}} for _, dbep := range dbeplist.Items { if reflect.DeepEqual(dbep.Labels, tsobj.Spec.Selector.MatchLabels) { dbeps.Items = append(dbeps.Items, dbep)