Skip to content

Commit

Permalink
Merge pull request #100 from layer5io/kumarabd/feature/broker
Browse files Browse the repository at this point in the history
client fixes
  • Loading branch information
kumarabd authored Jan 4, 2021
2 parents 2c45f40 + 3bce533 commit 924ddc2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 36 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ var (
)

func init() {
// +kubebuilder:scaffold:scheme
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(mesheryv1alpha1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

func main() {
Expand Down
28 changes: 26 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package client

import (
apiv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
v1alpha1 "github.com/layer5io/meshery-operator/pkg/client/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
)

v1alpha1 "github.com/layer5io/meshery-operator/pkg/client/v1alpha1"
var (
Scheme = runtime.NewScheme()
SchemeGroupVersion = apiv1alpha1.GroupVersion
)

type Interface interface {
Expand All @@ -20,12 +32,24 @@ func (c *Clientset) CoreV1Alpha1() v1alpha1.CoreInterface {
}

func New(config *rest.Config) (Interface, error) {
config.GroupVersion = &SchemeGroupVersion
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
config.NegotiatedSerializer = serializer.NewCodecFactory(Scheme).WithoutConversion()

client, err := rest.RESTClientFor(config)
if err != nil {
return nil, err
}

return &Clientset{
corev1alpha1: v1alpha1.New(client),
corev1alpha1: v1alpha1.New(client, runtime.NewParameterCodec(Scheme)),
}, nil
}

func init() {
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
// +kubebuilder:scaffold:scheme
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
utilruntime.Must(apiv1alpha1.AddToScheme(Scheme))
}
29 changes: 14 additions & 15 deletions pkg/client/v1alpha1/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
scheme "k8s.io/client-go/kubernetes/scheme"
rest "k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -44,13 +43,13 @@ func newBrokers(c *CoreClient, namespace string) *broker {
}

// Get takes name of the broker, and returns the corresponding broker object, and an error if there is any.
func (c *broker) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1alpha1.Broker, err error) {
func (c *broker) Get(ctx context.Context, name string, opts metav1.GetOptions) (result *v1alpha1.Broker, err error) {
result = &v1alpha1.Broker{}
err = c.client.Get().
Namespace(c.ns).
Resource("broker").
Resource("brokers").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Do(ctx).
Into(result)
return
Expand All @@ -65,8 +64,8 @@ func (c *broker) List(ctx context.Context, opts metav1.ListOptions) (result *v1a
result = &v1alpha1.BrokerList{}
err = c.client.Get().
Namespace(c.ns).
Resource("broker").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("brokers").
VersionedParams(&opts, ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
Expand All @@ -82,8 +81,8 @@ func (c *broker) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Inte
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("broker").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("brokers").
VersionedParams(&opts, ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
Expand All @@ -93,8 +92,8 @@ func (c *broker) Create(ctx context.Context, broker *v1alpha1.Broker, opts metav
result = &v1alpha1.Broker{}
err = c.client.Post().
Namespace(c.ns).
Resource("broker").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("brokers").
VersionedParams(&opts, ParameterCodec).
Body(broker).
Do(ctx).
Into(result)
Expand All @@ -106,9 +105,9 @@ func (c *broker) Update(ctx context.Context, broker *v1alpha1.Broker, opts metav
result = &v1alpha1.Broker{}
err = c.client.Put().
Namespace(c.ns).
Resource("broker").
Resource("brokers").
Name(broker.Name).
VersionedParams(&opts, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Body(broker).
Do(ctx).
Into(result)
Expand All @@ -119,7 +118,7 @@ func (c *broker) Update(ctx context.Context, broker *v1alpha1.Broker, opts metav
func (c *broker) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("broker").
Resource("brokers").
Name(name).
Body(&opts).
Do(ctx).
Expand All @@ -131,10 +130,10 @@ func (c *broker) Patch(ctx context.Context, name string, pt types.PatchType, dat
result = &v1alpha1.Broker{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("broker").
Resource("brokers").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Body(data).
Do(ctx).
Into(result)
Expand Down
29 changes: 14 additions & 15 deletions pkg/client/v1alpha1/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
scheme "k8s.io/client-go/kubernetes/scheme"
rest "k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -44,13 +43,13 @@ func newMeshSyncs(c *CoreClient, namespace string) *meshsync {
}

// Get takes name of the meshsync, and returns the corresponding meshsync object, and an error if there is any.
func (c *meshsync) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1alpha1.MeshSync, err error) {
func (c *meshsync) Get(ctx context.Context, name string, opts metav1.GetOptions) (result *v1alpha1.MeshSync, err error) {
result = &v1alpha1.MeshSync{}
err = c.client.Get().
Namespace(c.ns).
Resource("meshsync").
Resource("meshsyncs").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Do(ctx).
Into(result)
return
Expand All @@ -65,8 +64,8 @@ func (c *meshsync) List(ctx context.Context, opts metav1.ListOptions) (result *v
result = &v1alpha1.MeshSyncList{}
err = c.client.Get().
Namespace(c.ns).
Resource("meshsync").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("meshsyncs").
VersionedParams(&opts, ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
Expand All @@ -82,8 +81,8 @@ func (c *meshsync) Watch(ctx context.Context, opts metav1.ListOptions) (watch.In
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("meshsync").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("meshsyncs").
VersionedParams(&opts, ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
Expand All @@ -93,8 +92,8 @@ func (c *meshsync) Create(ctx context.Context, meshsync *v1alpha1.MeshSync, opts
result = &v1alpha1.MeshSync{}
err = c.client.Post().
Namespace(c.ns).
Resource("meshsync").
VersionedParams(&opts, scheme.ParameterCodec).
Resource("meshsyncs").
VersionedParams(&opts, ParameterCodec).
Body(meshsync).
Do(ctx).
Into(result)
Expand All @@ -106,9 +105,9 @@ func (c *meshsync) Update(ctx context.Context, meshsync *v1alpha1.MeshSync, opts
result = &v1alpha1.MeshSync{}
err = c.client.Put().
Namespace(c.ns).
Resource("meshsync").
Resource("meshsyncs").
Name(meshsync.Name).
VersionedParams(&opts, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Body(meshsync).
Do(ctx).
Into(result)
Expand All @@ -119,7 +118,7 @@ func (c *meshsync) Update(ctx context.Context, meshsync *v1alpha1.MeshSync, opts
func (c *meshsync) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("meshsync").
Resource("meshsyncs").
Name(name).
Body(&opts).
Do(ctx).
Expand All @@ -131,10 +130,10 @@ func (c *meshsync) Patch(ctx context.Context, name string, pt types.PatchType, d
result = &v1alpha1.MeshSync{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("meshsync").
Resource("meshsyncs").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
VersionedParams(&opts, ParameterCodec).
Body(data).
Do(ctx).
Into(result)
Expand Down
12 changes: 10 additions & 2 deletions pkg/client/v1alpha1/v1apha1.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
)

var (
ParameterCodec runtime.ParameterCodec
)

type CoreInterface interface {
RESTClient() rest.Interface
BrokersGetter
Expand All @@ -14,8 +19,11 @@ type CoreClient struct {
restClient rest.Interface
}

func New(c rest.Interface) *CoreClient {
return &CoreClient{c}
func New(c rest.Interface, codec runtime.ParameterCodec) *CoreClient {
ParameterCodec = codec
return &CoreClient{
restClient: c,
}
}

func (c *CoreClient) Brokers(namespace string) BrokerInterface {
Expand Down

0 comments on commit 924ddc2

Please sign in to comment.