-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.go
65 lines (51 loc) · 1.58 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gloo
import (
"context"
"github.com/argoproj-labs/rollouts-plugin-trafficrouter-glooplatform/pkg/util"
networkv2 "github.com/solo-io/solo-apis/client-go/networking.gloo.solo.io/v2"
"k8s.io/apimachinery/pkg/runtime"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
)
type networkV2Client struct {
routeTableClient *routeTableClient
}
type NetworkV2ClientSet interface {
RouteTables() RouteTableClient
}
type RouteTableClient interface {
RouteTableReader
RouteTableWriter
}
type RouteTableReader interface {
// Get retrieves a RouteTable for the given object key
GetRouteTable(ctx context.Context, name string, namespace string) (*networkv2.RouteTable, error)
// List retrieves list of RouteTables for a given namespace and list options.
ListRouteTable(ctx context.Context, opts ...k8sclient.ListOption) ([]*networkv2.RouteTable, error)
}
type RouteTableWriter interface {
// Patch patches the given RouteTable object.
PatchRouteTable(ctx context.Context, obj *networkv2.RouteTable, patch k8sclient.Patch, opts ...k8sclient.PatchOption) error
}
type routeTableClient struct {
client k8sclient.Client
}
func NewNetworkV2ClientSet() (NetworkV2ClientSet, error) {
cfg, err := util.GetKubeConfig()
if err != nil {
return nil, err
}
scheme := runtime.NewScheme()
networkv2.AddToScheme(scheme)
c, err := k8sclient.New(cfg, k8sclient.Options{
Scheme: scheme,
})
if err != nil {
return nil, err
}
return networkV2Client{
routeTableClient: &routeTableClient{client: c},
}, nil
}
func (c networkV2Client) RouteTables() RouteTableClient {
return c.routeTableClient
}