Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(controller): using golang-sdk instead of in tree kubernetes types #247

Merged
merged 2 commits into from
Aug 10, 2022
Merged
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
4 changes: 2 additions & 2 deletions pisa-controller/cmd/pisa-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions pisa-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
14 changes: 8 additions & 6 deletions pisa-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
117 changes: 0 additions & 117 deletions pisa-controller/pkg/kubernetes/client.go

This file was deleted.

19 changes: 10 additions & 9 deletions pisa-controller/pkg/kubernetes/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Loading