From d724454d45603e56e0ea7284653aa4552ead3856 Mon Sep 17 00:00:00 2001 From: thandayuthapani Date: Thu, 30 May 2019 17:03:49 +0530 Subject: [PATCH 1/3] Add Fake Package for scheduler in Vendor --- .../versioned/fake/clientset_generated.go | 82 ++++++++++ .../client/clientset/versioned/fake/doc.go | 20 +++ .../clientset/versioned/fake/register.go | 56 +++++++ .../typed/scheduling/v1alpha1/fake/doc.go | 20 +++ .../scheduling/v1alpha1/fake/fake_podgroup.go | 140 ++++++++++++++++++ .../scheduling/v1alpha1/fake/fake_queue.go | 131 ++++++++++++++++ .../v1alpha1/fake/fake_scheduling_client.go | 44 ++++++ 7 files changed, 493 insertions(+) create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/clientset_generated.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/doc.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/register.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/doc.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_podgroup.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_queue.go create mode 100644 vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_scheduling_client.go diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/clientset_generated.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 0000000000..c4da589c2d --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,82 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" + schedulingv1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1" + fakeschedulingv1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// SchedulingV1alpha1 retrieves the SchedulingV1alpha1Client +func (c *Clientset) SchedulingV1alpha1() schedulingv1alpha1.SchedulingV1alpha1Interface { + return &fakeschedulingv1alpha1.FakeSchedulingV1alpha1{Fake: &c.Fake} +} + +// Scheduling retrieves the SchedulingV1alpha1Client +func (c *Clientset) Scheduling() schedulingv1alpha1.SchedulingV1alpha1Interface { + return &fakeschedulingv1alpha1.FakeSchedulingV1alpha1{Fake: &c.Fake} +} diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/doc.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/doc.go new file mode 100644 index 0000000000..9b99e71670 --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/register.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/register.go new file mode 100644 index 0000000000..253431f3fb --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,56 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + schedulingv1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + schedulingv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/doc.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/doc.go new file mode 100644 index 0000000000..16f4439906 --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_podgroup.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_podgroup.go new file mode 100644 index 0000000000..5bc2cd95f3 --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_podgroup.go @@ -0,0 +1,140 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakePodGroups implements PodGroupInterface +type FakePodGroups struct { + Fake *FakeSchedulingV1alpha1 + ns string +} + +var podgroupsResource = schema.GroupVersionResource{Group: "scheduling", Version: "v1alpha1", Resource: "podgroups"} + +var podgroupsKind = schema.GroupVersionKind{Group: "scheduling", Version: "v1alpha1", Kind: "PodGroup"} + +// Get takes name of the podGroup, and returns the corresponding podGroup object, and an error if there is any. +func (c *FakePodGroups) Get(name string, options v1.GetOptions) (result *v1alpha1.PodGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(podgroupsResource, c.ns, name), &v1alpha1.PodGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodGroup), err +} + +// List takes label and field selectors, and returns the list of PodGroups that match those selectors. +func (c *FakePodGroups) List(opts v1.ListOptions) (result *v1alpha1.PodGroupList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(podgroupsResource, podgroupsKind, c.ns, opts), &v1alpha1.PodGroupList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.PodGroupList{ListMeta: obj.(*v1alpha1.PodGroupList).ListMeta} + for _, item := range obj.(*v1alpha1.PodGroupList).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 podGroups. +func (c *FakePodGroups) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(podgroupsResource, c.ns, opts)) + +} + +// Create takes the representation of a podGroup and creates it. Returns the server's representation of the podGroup, and an error, if there is any. +func (c *FakePodGroups) Create(podGroup *v1alpha1.PodGroup) (result *v1alpha1.PodGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(podgroupsResource, c.ns, podGroup), &v1alpha1.PodGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodGroup), err +} + +// Update takes the representation of a podGroup and updates it. Returns the server's representation of the podGroup, and an error, if there is any. +func (c *FakePodGroups) Update(podGroup *v1alpha1.PodGroup) (result *v1alpha1.PodGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(podgroupsResource, c.ns, podGroup), &v1alpha1.PodGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodGroup), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakePodGroups) UpdateStatus(podGroup *v1alpha1.PodGroup) (*v1alpha1.PodGroup, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(podgroupsResource, "status", c.ns, podGroup), &v1alpha1.PodGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodGroup), err +} + +// Delete takes name of the podGroup and deletes it. Returns an error if one occurs. +func (c *FakePodGroups) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(podgroupsResource, c.ns, name), &v1alpha1.PodGroup{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakePodGroups) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(podgroupsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.PodGroupList{}) + return err +} + +// Patch applies the patch and returns the patched podGroup. +func (c *FakePodGroups) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.PodGroup, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(podgroupsResource, c.ns, name, pt, data, subresources...), &v1alpha1.PodGroup{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.PodGroup), err +} diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_queue.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_queue.go new file mode 100644 index 0000000000..0f5932152e --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_queue.go @@ -0,0 +1,131 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeQueues implements QueueInterface +type FakeQueues struct { + Fake *FakeSchedulingV1alpha1 +} + +var queuesResource = schema.GroupVersionResource{Group: "scheduling", Version: "v1alpha1", Resource: "queues"} + +var queuesKind = schema.GroupVersionKind{Group: "scheduling", Version: "v1alpha1", Kind: "Queue"} + +// Get takes name of the queue, and returns the corresponding queue object, and an error if there is any. +func (c *FakeQueues) Get(name string, options v1.GetOptions) (result *v1alpha1.Queue, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(queuesResource, name), &v1alpha1.Queue{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Queue), err +} + +// List takes label and field selectors, and returns the list of Queues that match those selectors. +func (c *FakeQueues) List(opts v1.ListOptions) (result *v1alpha1.QueueList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(queuesResource, queuesKind, opts), &v1alpha1.QueueList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.QueueList{ListMeta: obj.(*v1alpha1.QueueList).ListMeta} + for _, item := range obj.(*v1alpha1.QueueList).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 queues. +func (c *FakeQueues) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(queuesResource, opts)) +} + +// Create takes the representation of a queue and creates it. Returns the server's representation of the queue, and an error, if there is any. +func (c *FakeQueues) Create(queue *v1alpha1.Queue) (result *v1alpha1.Queue, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(queuesResource, queue), &v1alpha1.Queue{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Queue), err +} + +// Update takes the representation of a queue and updates it. Returns the server's representation of the queue, and an error, if there is any. +func (c *FakeQueues) Update(queue *v1alpha1.Queue) (result *v1alpha1.Queue, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(queuesResource, queue), &v1alpha1.Queue{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Queue), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeQueues) UpdateStatus(queue *v1alpha1.Queue) (*v1alpha1.Queue, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(queuesResource, "status", queue), &v1alpha1.Queue{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Queue), err +} + +// Delete takes name of the queue and deletes it. Returns an error if one occurs. +func (c *FakeQueues) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteAction(queuesResource, name), &v1alpha1.Queue{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeQueues) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(queuesResource, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.QueueList{}) + return err +} + +// Patch applies the patch and returns the patched queue. +func (c *FakeQueues) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Queue, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(queuesResource, name, pt, data, subresources...), &v1alpha1.Queue{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Queue), err +} diff --git a/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_scheduling_client.go b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_scheduling_client.go new file mode 100644 index 0000000000..f8c9e918ae --- /dev/null +++ b/vendor/github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake/fake_scheduling_client.go @@ -0,0 +1,44 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/typed/scheduling/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeSchedulingV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSchedulingV1alpha1) PodGroups(namespace string) v1alpha1.PodGroupInterface { + return &FakePodGroups{c, namespace} +} + +func (c *FakeSchedulingV1alpha1) Queues() v1alpha1.QueueInterface { + return &FakeQueues{c} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSchedulingV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} From 9aa1d9a3e1a2f7f5dae8fb287993d9faa811c155 Mon Sep 17 00:00:00 2001 From: thandayuthapani Date: Thu, 30 May 2019 18:30:06 +0530 Subject: [PATCH 2/3] Check Queue exist in admission controller --- Gopkg.lock | 6 +++++- cmd/admission/app/server.go | 9 ++++++++ cmd/admission/main.go | 2 ++ installer/chart/templates/admission.yaml | 3 +++ pkg/admission/admit_job.go | 9 ++++++++ pkg/admission/admit_job_test.go | 26 ++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Gopkg.lock b/Gopkg.lock index 60dff4092a..0fa26df6f3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -204,7 +204,7 @@ [[projects]] branch = "master" - digest = "1:986c933d3d3c05ab20d42462475be937ee26238500e58f5b53b5ae77b60f49ad" + digest = "1:407852f4bc58f1ffb25131dbdce512b3c5a2dd0d880567d3189c60a3eb069f45" name = "github.com/kubernetes-sigs/kube-batch" packages = [ "cmd/kube-batch/app", @@ -212,8 +212,10 @@ "pkg/apis/scheduling/v1alpha1", "pkg/apis/utils", "pkg/client/clientset/versioned", + "pkg/client/clientset/versioned/fake", "pkg/client/clientset/versioned/scheme", "pkg/client/clientset/versioned/typed/scheduling/v1alpha1", + "pkg/client/clientset/versioned/typed/scheduling/v1alpha1/fake", "pkg/client/informers/externalversions", "pkg/client/informers/externalversions/internalinterfaces", "pkg/client/informers/externalversions/scheduling", @@ -1047,6 +1049,7 @@ "github.com/kubernetes-sigs/kube-batch/cmd/kube-batch/app/options", "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1", "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned", + "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake", "github.com/kubernetes-sigs/kube-batch/pkg/client/informers/externalversions", "github.com/kubernetes-sigs/kube-batch/pkg/client/informers/externalversions/scheduling/v1alpha1", "github.com/kubernetes-sigs/kube-batch/pkg/client/listers/scheduling/v1alpha1", @@ -1112,6 +1115,7 @@ "k8s.io/kubernetes/pkg/apis/core", "k8s.io/kubernetes/pkg/apis/core/v1", "k8s.io/kubernetes/pkg/apis/core/validation", + "k8s.io/kubernetes/pkg/controller", "k8s.io/kubernetes/pkg/scheduler/api", ] solver-name = "gps-cdcl" diff --git a/cmd/admission/app/server.go b/cmd/admission/app/server.go index 05e79f7b73..d6fbaeb76e 100644 --- a/cmd/admission/app/server.go +++ b/cmd/admission/app/server.go @@ -22,6 +22,7 @@ import ( "net/http" "github.com/golang/glog" + "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" "k8s.io/api/admission/v1beta1" "k8s.io/apimachinery/pkg/runtime" @@ -46,6 +47,14 @@ func GetClient(restConfig *restclient.Config) *kubernetes.Clientset { return clientset } +func GetKubeBatchClient(restConfig *restclient.Config) *versioned.Clientset { + clientset, err := versioned.NewForConfig(restConfig) + if err != nil { + glog.Fatal(err) + } + return clientset +} + // ConfigTLS is a helper function that generate tls certificates from directly defined tls config or kubeconfig // These are passed in as command line for cluster certification. If tls config is passed in, we use the directly // defined tls config, else use that defined in kubeconfig diff --git a/cmd/admission/main.go b/cmd/admission/main.go index e60a6ef50f..82ab5dcd68 100644 --- a/cmd/admission/main.go +++ b/cmd/admission/main.go @@ -65,6 +65,8 @@ func main() { clientset := app.GetClient(restConfig) + admissioncontroller.KubeBatchClientSet = app.GetKubeBatchClient(restConfig) + caCertPem, err := ioutil.ReadFile(config.CaCertFile) if err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) diff --git a/installer/chart/templates/admission.yaml b/installer/chart/templates/admission.yaml index 9b57314d0e..436b6b34d1 100644 --- a/installer/chart/templates/admission.yaml +++ b/installer/chart/templates/admission.yaml @@ -29,6 +29,9 @@ rules: - apiGroups: [""] resources: ["secrets"] verbs: ["create", "get", "patch"] + - apiGroups: ["scheduling.incubator.k8s.io"] + resources: ["queues"] + verbs: ["get", "list"] --- kind: ClusterRoleBinding diff --git a/pkg/admission/admit_job.go b/pkg/admission/admit_job.go index 586451d3e8..819cebfa95 100644 --- a/pkg/admission/admit_job.go +++ b/pkg/admission/admit_job.go @@ -21,6 +21,7 @@ import ( "strings" "github.com/golang/glog" + "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" "k8s.io/api/admission/v1beta1" "k8s.io/api/core/v1" @@ -35,6 +36,9 @@ import ( "volcano.sh/volcano/pkg/controllers/job/plugins" ) +//KubeBatchClientSet is kube-batch clientset +var KubeBatchClientSet versioned.Interface + // job admit. func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse { @@ -146,6 +150,11 @@ func validateJob(job v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) st msg = msg + validateInfo } + // Check whether Queue already present or not + if _, err := KubeBatchClientSet.SchedulingV1alpha1().Queues().Get(job.Spec.Queue, metav1.GetOptions{}); err != nil { + msg = msg + fmt.Sprintf("Job not created with error: %v", err) + } + if msg != "" { reviewResponse.Allowed = false } diff --git a/pkg/admission/admit_job_test.go b/pkg/admission/admit_job_test.go index b62b1a94a6..43f509c4bb 100644 --- a/pkg/admission/admit_job_test.go +++ b/pkg/admission/admit_job_test.go @@ -20,10 +20,13 @@ import ( "strings" "testing" + kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned/fake" + "k8s.io/api/admission/v1beta1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kbv1aplha1 "github.com/kubernetes-sigs/kube-batch/pkg/apis/scheduling/v1alpha1" v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" ) @@ -48,6 +51,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 1, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "task-1", @@ -83,6 +87,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 1, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "duplicated-task-1", @@ -135,6 +140,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 1, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "task-1", @@ -180,6 +186,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 2, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "task-1", @@ -215,6 +222,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 1, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "task-1", @@ -253,6 +261,7 @@ func TestValidateExecution(t *testing.T) { }, Spec: v1alpha1.JobSpec{ MinAvailable: 1, + Queue: "default", Tasks: []v1alpha1.TaskSpec{ { Name: "task-1", @@ -283,6 +292,23 @@ func TestValidateExecution(t *testing.T) { for _, testCase := range testCases { + defaultqueue := kbv1aplha1.Queue{ + ObjectMeta: metav1.ObjectMeta{ + Name: "default", + }, + Spec: kbv1aplha1.QueueSpec{ + Weight: 1, + }, + } + // create fake kube-batch clientset + KubeBatchClientSet = kubebatchclient.NewSimpleClientset() + + //create default queue + _, err := KubeBatchClientSet.SchedulingV1alpha1().Queues().Create(&defaultqueue) + if err != nil { + t.Error("Queue Creation Failed") + } + ret := validateJob(testCase.Job, &testCase.reviewResponse) //fmt.Printf("test-case name:%s, ret:%v testCase.reviewResponse:%v \n", testCase.Name, ret,testCase.reviewResponse) if testCase.ExpectErr == true && ret == "" { From 332ff82d0dcee5f9edb8331d31df426c1062fa94 Mon Sep 17 00:00:00 2001 From: SrinivasChilveri Date: Tue, 21 May 2019 14:45:01 +0530 Subject: [PATCH 3/3] Added UT for options in controller --- cmd/controllers/app/options/options_test.go | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 cmd/controllers/app/options/options_test.go diff --git a/cmd/controllers/app/options/options_test.go b/cmd/controllers/app/options/options_test.go new file mode 100644 index 0000000000..df6d5b7f22 --- /dev/null +++ b/cmd/controllers/app/options/options_test.go @@ -0,0 +1,53 @@ +/* +Copyright 2019 The Volcano Authors. + +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 options + +import ( + "github.com/spf13/pflag" + "reflect" + "testing" +) + +func TestAddFlags(t *testing.T) { + fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError) + s := NewServerOption() + s.AddFlags(fs) + + args := []string{ + "--master=127.0.0.1", + "--kube-api-burst=200", + } + fs.Parse(args) + + // This is a snapshot of expected options parsed by args. + expected := &ServerOption{ + Master: "127.0.0.1", + KubeAPIQPS: defaultQPS, + KubeAPIBurst: 200, + PrintVersion: false, + } + + if !reflect.DeepEqual(expected, s) { + t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected) + } + + err := s.CheckOptionOrDie() + if err != nil { + t.Errorf("expected nil but got %v\n", err) + } + +}