Skip to content

Commit

Permalink
Move resource consts to api pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Jul 13, 2017
1 parent ace063e commit 8f479b3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
6 changes: 6 additions & 0 deletions api/restic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
apiv1 "k8s.io/client-go/pkg/api/v1"
)

const (
ResourceKindRestic = "Restic"
ResourceNameRestic = "restic"
ResourceTypeRestic = "restics"
)

type Restic struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
38 changes: 19 additions & 19 deletions client/clientset/fake/restic.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fake

import (
sapi "github.com/appscode/stash/api"
tapi "github.com/appscode/stash/api"
"github.com/appscode/stash/client/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -14,25 +14,25 @@ type FakeStash struct {
ns string
}

var stashResource = sapi.V1alpha1SchemeGroupVersion.WithResource("restics")
var stashResource = tapi.V1alpha1SchemeGroupVersion.WithResource(tapi.ResourceTypeRestic)

var _ clientset.ResticInterface = &FakeStash{}

// Get returns the Stashs by name.
func (mock *FakeStash) Get(name string) (*sapi.Restic, error) {
func (mock *FakeStash) Get(name string) (*tapi.Restic, error) {
obj, err := mock.Fake.
Invokes(testing.NewGetAction(stashResource, mock.ns, name), &sapi.Restic{})
Invokes(testing.NewGetAction(stashResource, mock.ns, name), &tapi.Restic{})

if obj == nil {
return nil, err
}
return obj.(*sapi.Restic), err
return obj.(*tapi.Restic), err
}

// List returns the a of Stashs.
func (mock *FakeStash) List(opts metav1.ListOptions) (*sapi.ResticList, error) {
func (mock *FakeStash) List(opts metav1.ListOptions) (*tapi.ResticList, error) {
obj, err := mock.Fake.
Invokes(testing.NewListAction(stashResource, mock.ns, opts), &sapi.Restic{})
Invokes(testing.NewListAction(stashResource, mock.ns, opts), &tapi.Restic{})

if obj == nil {
return nil, err
Expand All @@ -42,8 +42,8 @@ func (mock *FakeStash) List(opts metav1.ListOptions) (*sapi.ResticList, error) {
if label == nil {
label = labels.Everything()
}
list := &sapi.ResticList{}
for _, item := range obj.(*sapi.ResticList).Items {
list := &tapi.ResticList{}
for _, item := range obj.(*tapi.ResticList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
Expand All @@ -52,43 +52,43 @@ func (mock *FakeStash) List(opts metav1.ListOptions) (*sapi.ResticList, error) {
}

// Create creates a new Stash.
func (mock *FakeStash) Create(svc *sapi.Restic) (*sapi.Restic, error) {
func (mock *FakeStash) Create(svc *tapi.Restic) (*tapi.Restic, error) {
obj, err := mock.Fake.
Invokes(testing.NewCreateAction(stashResource, mock.ns, svc), &sapi.Restic{})
Invokes(testing.NewCreateAction(stashResource, mock.ns, svc), &tapi.Restic{})

if obj == nil {
return nil, err
}
return obj.(*sapi.Restic), err
return obj.(*tapi.Restic), err
}

// Update updates a Stash.
func (mock *FakeStash) Update(svc *sapi.Restic) (*sapi.Restic, error) {
func (mock *FakeStash) Update(svc *tapi.Restic) (*tapi.Restic, error) {
obj, err := mock.Fake.
Invokes(testing.NewUpdateAction(stashResource, mock.ns, svc), &sapi.Restic{})
Invokes(testing.NewUpdateAction(stashResource, mock.ns, svc), &tapi.Restic{})

if obj == nil {
return nil, err
}
return obj.(*sapi.Restic), err
return obj.(*tapi.Restic), err
}

// Delete deletes a Stash by name.
func (mock *FakeStash) Delete(name string, _ *metav1.DeleteOptions) error {
_, err := mock.Fake.
Invokes(testing.NewDeleteAction(stashResource, mock.ns, name), &sapi.Restic{})
Invokes(testing.NewDeleteAction(stashResource, mock.ns, name), &tapi.Restic{})

return err
}

func (mock *FakeStash) UpdateStatus(srv *sapi.Restic) (*sapi.Restic, error) {
func (mock *FakeStash) UpdateStatus(srv *tapi.Restic) (*tapi.Restic, error) {
obj, err := mock.Fake.
Invokes(testing.NewUpdateSubresourceAction(stashResource, "status", mock.ns, srv), &sapi.Restic{})
Invokes(testing.NewUpdateSubresourceAction(stashResource, "status", mock.ns, srv), &tapi.Restic{})

if obj == nil {
return nil, err
}
return obj.(*sapi.Restic), err
return obj.(*tapi.Restic), err
}

func (mock *FakeStash) Watch(opts metav1.ListOptions) (watch.Interface, error) {
Expand Down
52 changes: 23 additions & 29 deletions client/clientset/restic.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package clientset

import (
sapi "github.com/appscode/stash/api"
tapi "github.com/appscode/stash/api"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/rest"
Expand All @@ -11,20 +11,14 @@ type ResticGetter interface {
Restics(namespace string) ResticInterface
}

const (
ResourceKindRestic = "Restic"
ResourceNameRestic = "restic"
ResourceTypeRestic = "restics"
)

type ResticInterface interface {
List(opts metav1.ListOptions) (*sapi.ResticList, error)
Get(name string) (*sapi.Restic, error)
Create(stash *sapi.Restic) (*sapi.Restic, error)
Update(stash *sapi.Restic) (*sapi.Restic, error)
List(opts metav1.ListOptions) (*tapi.ResticList, error)
Get(name string) (*tapi.Restic, error)
Create(stash *tapi.Restic) (*tapi.Restic, error)
Update(stash *tapi.Restic) (*tapi.Restic, error)
Delete(name string, options *metav1.DeleteOptions) error
Watch(opts metav1.ListOptions) (watch.Interface, error)
UpdateStatus(stash *sapi.Restic) (*sapi.Restic, error)
UpdateStatus(stash *tapi.Restic) (*tapi.Restic, error)
}

type ResticImpl struct {
Expand All @@ -38,44 +32,44 @@ func newRestic(c *ExtensionClient, namespace string) *ResticImpl {
return &ResticImpl{c.restClient, namespace}
}

func (c *ResticImpl) List(opts metav1.ListOptions) (result *sapi.ResticList, err error) {
result = &sapi.ResticList{}
func (c *ResticImpl) List(opts metav1.ListOptions) (result *tapi.ResticList, err error) {
result = &tapi.ResticList{}
err = c.r.Get().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
VersionedParams(&opts, ExtendedCodec).
Do().
Into(result)
return
}

func (c *ResticImpl) Get(name string) (result *sapi.Restic, err error) {
result = &sapi.Restic{}
func (c *ResticImpl) Get(name string) (result *tapi.Restic, err error) {
result = &tapi.Restic{}
err = c.r.Get().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
Name(name).
Do().
Into(result)
return
}

func (c *ResticImpl) Create(stash *sapi.Restic) (result *sapi.Restic, err error) {
result = &sapi.Restic{}
func (c *ResticImpl) Create(stash *tapi.Restic) (result *tapi.Restic, err error) {
result = &tapi.Restic{}
err = c.r.Post().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
Body(stash).
Do().
Into(result)
return
}

func (c *ResticImpl) Update(stash *sapi.Restic) (result *sapi.Restic, err error) {
result = &sapi.Restic{}
func (c *ResticImpl) Update(stash *tapi.Restic) (result *tapi.Restic, err error) {
result = &tapi.Restic{}
err = c.r.Put().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
Name(stash.Name).
Body(stash).
Do().
Expand All @@ -86,7 +80,7 @@ func (c *ResticImpl) Update(stash *sapi.Restic) (result *sapi.Restic, err error)
func (c *ResticImpl) Delete(name string, options *metav1.DeleteOptions) (err error) {
return c.r.Delete().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
Name(name).
Body(options).
Do().
Expand All @@ -97,16 +91,16 @@ func (c *ResticImpl) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
VersionedParams(&opts, ExtendedCodec).
Watch()
}

func (c *ResticImpl) UpdateStatus(stash *sapi.Restic) (result *sapi.Restic, err error) {
result = &sapi.Restic{}
func (c *ResticImpl) UpdateStatus(stash *tapi.Restic) (result *tapi.Restic, err error) {
result = &tapi.Restic{}
err = c.r.Put().
Namespace(c.ns).
Resource(ResourceTypeRestic).
Resource(tapi.ResourceTypeRestic).
Name(stash.Name).
SubResource("status").
Body(stash).
Expand Down

0 comments on commit 8f479b3

Please sign in to comment.