ScheduledJob client

This commit is contained in:
Maciej Szulik 2016-05-11 13:40:07 +02:00
parent adc890a57e
commit 6510eb54d8
11 changed files with 482 additions and 7 deletions

View File

@ -165,6 +165,8 @@ type JobCondition struct {
Message string `json:"message,omitempty"`
}
// +genclient=true
// ScheduledJob represents the configuration of a single scheduled job.
type ScheduledJob struct {
unversioned.TypeMeta `json:",inline"`

View File

@ -25,6 +25,7 @@ import (
type BatchInterface interface {
GetRESTClient() *restclient.RESTClient
JobsGetter
ScheduledJobsGetter
}
// BatchClient is used to interact with features provided by the Batch group.
@ -36,6 +37,10 @@ func (c *BatchClient) Jobs(namespace string) JobInterface {
return newJobs(c, namespace)
}
func (c *BatchClient) ScheduledJobs(namespace string) ScheduledJobInterface {
return newScheduledJobs(c, namespace)
}
// NewForConfig creates a new BatchClient for the given config.
func NewForConfig(c *restclient.Config) (*BatchClient, error) {
config := *c

View File

@ -30,6 +30,10 @@ func (c *FakeBatch) Jobs(namespace string) unversioned.JobInterface {
return &FakeJobs{c, namespace}
}
func (c *FakeBatch) ScheduledJobs(namespace string) unversioned.ScheduledJobInterface {
return &FakeScheduledJobs{c, namespace}
}
// GetRESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *FakeBatch) GetRESTClient() *restclient.RESTClient {

View File

@ -0,0 +1,116 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 fake
import (
api "k8s.io/kubernetes/pkg/api"
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
batch "k8s.io/kubernetes/pkg/apis/batch"
core "k8s.io/kubernetes/pkg/client/testing/core"
labels "k8s.io/kubernetes/pkg/labels"
watch "k8s.io/kubernetes/pkg/watch"
)
// FakeScheduledJobs implements ScheduledJobInterface
type FakeScheduledJobs struct {
Fake *FakeBatch
ns string
}
var scheduledjobsResource = unversioned.GroupVersionResource{Group: "batch", Version: "", Resource: "scheduledjobs"}
func (c *FakeScheduledJobs) Create(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.
Invokes(core.NewCreateAction(scheduledjobsResource, c.ns, scheduledJob), &batch.ScheduledJob{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) Update(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.
Invokes(core.NewUpdateAction(scheduledjobsResource, c.ns, scheduledJob), &batch.ScheduledJob{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) UpdateStatus(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error) {
obj, err := c.Fake.
Invokes(core.NewUpdateSubresourceAction(scheduledjobsResource, "status", c.ns, scheduledJob), &batch.ScheduledJob{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.
Invokes(core.NewDeleteAction(scheduledjobsResource, c.ns, name), &batch.ScheduledJob{})
return err
}
func (c *FakeScheduledJobs) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
action := core.NewDeleteCollectionAction(scheduledjobsResource, c.ns, listOptions)
_, err := c.Fake.Invokes(action, &batch.ScheduledJobList{})
return err
}
func (c *FakeScheduledJobs) Get(name string) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.
Invokes(core.NewGetAction(scheduledjobsResource, c.ns, name), &batch.ScheduledJob{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) List(opts api.ListOptions) (result *batch.ScheduledJobList, err error) {
obj, err := c.Fake.
Invokes(core.NewListAction(scheduledjobsResource, c.ns, opts), &batch.ScheduledJobList{})
if obj == nil {
return nil, err
}
label := opts.LabelSelector
if label == nil {
label = labels.Everything()
}
list := &batch.ScheduledJobList{}
for _, item := range obj.(*batch.ScheduledJobList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested scheduledJobs.
func (c *FakeScheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(core.NewWatchAction(scheduledjobsResource, c.ns, opts))
}

View File

@ -17,3 +17,5 @@ limitations under the License.
package unversioned
type JobExpansion interface{}
type ScheduledJobExpansion interface{}

View File

@ -0,0 +1,150 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned
import (
api "k8s.io/kubernetes/pkg/api"
batch "k8s.io/kubernetes/pkg/apis/batch"
watch "k8s.io/kubernetes/pkg/watch"
)
// ScheduledJobsGetter has a method to return a ScheduledJobInterface.
// A group's client should implement this interface.
type ScheduledJobsGetter interface {
ScheduledJobs(namespace string) ScheduledJobInterface
}
// ScheduledJobInterface has methods to work with ScheduledJob resources.
type ScheduledJobInterface interface {
Create(*batch.ScheduledJob) (*batch.ScheduledJob, error)
Update(*batch.ScheduledJob) (*batch.ScheduledJob, error)
UpdateStatus(*batch.ScheduledJob) (*batch.ScheduledJob, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*batch.ScheduledJob, error)
List(opts api.ListOptions) (*batch.ScheduledJobList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
ScheduledJobExpansion
}
// scheduledJobs implements ScheduledJobInterface
type scheduledJobs struct {
client *BatchClient
ns string
}
// newScheduledJobs returns a ScheduledJobs
func newScheduledJobs(c *BatchClient, namespace string) *scheduledJobs {
return &scheduledJobs{
client: c,
ns: namespace,
}
}
// Create takes the representation of a scheduledJob and creates it. Returns the server's representation of the scheduledJob, and an error, if there is any.
func (c *scheduledJobs) Create(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.client.Post().
Namespace(c.ns).
Resource("scheduledjobs").
Body(scheduledJob).
Do().
Into(result)
return
}
// Update takes the representation of a scheduledJob and updates it. Returns the server's representation of the scheduledJob, and an error, if there is any.
func (c *scheduledJobs) Update(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.client.Put().
Namespace(c.ns).
Resource("scheduledjobs").
Name(scheduledJob.Name).
Body(scheduledJob).
Do().
Into(result)
return
}
func (c *scheduledJobs) UpdateStatus(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.client.Put().
Namespace(c.ns).
Resource("scheduledjobs").
Name(scheduledJob.Name).
SubResource("status").
Body(scheduledJob).
Do().
Into(result)
return
}
// Delete takes name of the scheduledJob and deletes it. Returns an error if one occurs.
func (c *scheduledJobs) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("scheduledjobs").
Name(name).
Body(options).
Do().
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *scheduledJobs) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("scheduledjobs").
VersionedParams(&listOptions, api.ParameterCodec).
Body(options).
Do().
Error()
}
// Get takes name of the scheduledJob, and returns the corresponding scheduledJob object, and an error if there is any.
func (c *scheduledJobs) Get(name string) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.client.Get().
Namespace(c.ns).
Resource("scheduledjobs").
Name(name).
Do().
Into(result)
return
}
// List takes label and field selectors, and returns the list of ScheduledJobs that match those selectors.
func (c *scheduledJobs) List(opts api.ListOptions) (result *batch.ScheduledJobList, err error) {
result = &batch.ScheduledJobList{}
err = c.client.Get().
Namespace(c.ns).
Resource("scheduledjobs").
VersionedParams(&opts, api.ParameterCodec).
Do().
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested scheduledJobs.
func (c *scheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.client.Get().
Prefix("watch").
Namespace(c.ns).
Resource("scheduledjobs").
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

View File

@ -27,6 +27,7 @@ import (
type BatchInterface interface {
JobsNamespacer
ScheduledJobsNamespacer
}
// BatchClient is used to interact with Kubernetes batch features.
@ -38,6 +39,10 @@ func (c *BatchClient) Jobs(namespace string) JobInterface {
return newJobsV1(c, namespace)
}
func (c *BatchClient) ScheduledJobs(namespace string) ScheduledJobInterface {
return newScheduledJobs(c, namespace)
}
func NewBatch(c *restclient.Config) (*BatchClient, error) {
config := *c
if err := setBatchDefaults(&config, nil); err != nil {

View File

@ -0,0 +1,103 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 unversioned
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/watch"
)
// ScheduledJobsNamespacer has methods to work with ScheduledJob resources in a namespace
type ScheduledJobsNamespacer interface {
ScheduledJobs(namespace string) ScheduledJobInterface
}
// ScheduledJobInterface exposes methods to work on ScheduledJob resources.
type ScheduledJobInterface interface {
List(opts api.ListOptions) (*batch.ScheduledJobList, error)
Get(name string) (*batch.ScheduledJob, error)
Create(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error)
Update(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error)
Delete(name string, options *api.DeleteOptions) error
Watch(opts api.ListOptions) (watch.Interface, error)
UpdateStatus(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error)
}
// scheduledJobs implements ScheduledJobsNamespacer interface
type scheduledJobs struct {
r *BatchClient
ns string
}
// newScheduledJobs returns a scheduledJobs
func newScheduledJobs(c *BatchClient, namespace string) *scheduledJobs {
return &scheduledJobs{c, namespace}
}
// Ensure statically that scheduledJobs implements ScheduledJobInterface.
var _ ScheduledJobInterface = &scheduledJobs{}
// List returns a list of scheduled jobs that match the label and field selectors.
func (c *scheduledJobs) List(opts api.ListOptions) (result *batch.ScheduledJobList, err error) {
result = &batch.ScheduledJobList{}
err = c.r.Get().Namespace(c.ns).Resource("scheduledJobs").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
return
}
// Get returns information about a particular scheduled job.
func (c *scheduledJobs) Get(name string) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.r.Get().Namespace(c.ns).Resource("scheduledJobs").Name(name).Do().Into(result)
return
}
// Create creates a new scheduled job.
func (c *scheduledJobs) Create(job *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.r.Post().Namespace(c.ns).Resource("scheduledJobs").Body(job).Do().Into(result)
return
}
// Update updates an existing scheduled job.
func (c *scheduledJobs) Update(job *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.r.Put().Namespace(c.ns).Resource("scheduledJobs").Name(job.Name).Body(job).Do().Into(result)
return
}
// Delete deletes a scheduled job, returns error if one occurs.
func (c *scheduledJobs) Delete(name string, options *api.DeleteOptions) (err error) {
return c.r.Delete().Namespace(c.ns).Resource("scheduledJobs").Name(name).Body(options).Do().Error()
}
// Watch returns a watch.Interface that watches the requested scheduled jobs.
func (c *scheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(c.ns).
Resource("scheduledJobs").
VersionedParams(&opts, api.ParameterCodec).
Watch()
}
// UpdateStatus takes the name of the scheduled job and the new status. Returns the server's representation of the scheduled job, and an error, if it occurs.
func (c *scheduledJobs) UpdateStatus(job *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.r.Put().Namespace(c.ns).Resource("scheduledJobs").Name(job.Name).SubResource("status").Body(job).Do().Into(result)
return
}

View File

@ -0,0 +1,84 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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 testclient
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/watch"
)
// FakeScheduledJobs implements ScheduledJobInterface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the methods you want to test easier.
type FakeScheduledJobs struct {
Fake *FakeBatch
Namespace string
}
func (c *FakeScheduledJobs) Get(name string) (*batch.ScheduledJob, error) {
obj, err := c.Fake.Invokes(NewGetAction("scheduledjobs", c.Namespace, name), &batch.ScheduledJob{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) List(opts api.ListOptions) (*batch.ScheduledJobList, error) {
obj, err := c.Fake.Invokes(NewListAction("scheduledjobs", c.Namespace, opts), &batch.ScheduledJobList{})
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJobList), err
}
func (c *FakeScheduledJobs) Create(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error) {
obj, err := c.Fake.Invokes(NewCreateAction("scheduledjobs", c.Namespace, scheduledJob), scheduledJob)
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) Update(scheduledJob *batch.ScheduledJob) (*batch.ScheduledJob, error) {
obj, err := c.Fake.Invokes(NewUpdateAction("scheduledjobs", c.Namespace, scheduledJob), scheduledJob)
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
func (c *FakeScheduledJobs) Delete(name string, options *api.DeleteOptions) error {
_, err := c.Fake.Invokes(NewDeleteAction("scheduledjobs", c.Namespace, name), &batch.ScheduledJob{})
return err
}
func (c *FakeScheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.Fake.InvokesWatch(NewWatchAction("scheduledjobs", c.Namespace, opts))
}
func (c *FakeScheduledJobs) UpdateStatus(scheduledJob *batch.ScheduledJob) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.Invokes(NewUpdateSubresourceAction("scheduledjobs", "status", c.Namespace, scheduledJob), scheduledJob)
if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}

View File

@ -341,6 +341,10 @@ func (c *FakeBatch) Jobs(namespace string) client.JobInterface {
return &FakeJobsV1{Fake: c, Namespace: namespace}
}
func (c *FakeBatch) ScheduledJobs(namespace string) client.ScheduledJobInterface {
return &FakeScheduledJobs{Fake: c, Namespace: namespace}
}
// NewSimpleFakeExp returns a client that will respond with the provided objects
func NewSimpleFakeExp(objects ...runtime.Object) *FakeExperimental {
return &FakeExperimental{Fake: NewSimpleFake(objects...)}

View File

@ -249,7 +249,7 @@ func TestValidateReplicationController(t *testing.T) {
}
type ErrorJobs struct {
testclient.FakeJobs
testclient.FakeJobsV1
invalid bool
}
@ -270,16 +270,16 @@ func (c *ErrorJobs) Get(name string) (*batch.Job, error) {
}
type ErrorJobClient struct {
testclient.FakeExperimental
testclient.FakeBatch
invalid bool
}
func (c *ErrorJobClient) Jobs(namespace string) client.JobInterface {
return &ErrorJobs{testclient.FakeJobs{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
return &ErrorJobs{testclient.FakeJobsV1{Fake: &c.FakeBatch, Namespace: namespace}, c.invalid}
}
func TestJobScaleRetry(t *testing.T) {
fake := &ErrorJobClient{FakeExperimental: testclient.FakeExperimental{}, invalid: false}
fake := &ErrorJobClient{FakeBatch: testclient.FakeBatch{}, invalid: false}
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
@ -303,7 +303,7 @@ func TestJobScaleRetry(t *testing.T) {
}
func TestJobScale(t *testing.T) {
fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
fake := &testclient.FakeBatch{Fake: &testclient.Fake{}}
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
@ -323,7 +323,7 @@ func TestJobScale(t *testing.T) {
}
func TestJobScaleInvalid(t *testing.T) {
fake := &ErrorJobClient{FakeExperimental: testclient.FakeExperimental{}, invalid: true}
fake := &ErrorJobClient{FakeBatch: testclient.FakeBatch{}, invalid: true}
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
@ -348,7 +348,7 @@ func TestJobScaleFailsPreconditions(t *testing.T) {
Parallelism: &ten,
},
})
scaler := JobScaler{&testclient.FakeExperimental{Fake: fake}}
scaler := JobScaler{&testclient.FakeBatch{Fake: fake}}
preconditions := ScalePrecondition{2, ""}
count := uint(3)
name := "foo"