Skip to content

Commit

Permalink
add Patch to clientsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Xu committed Jun 17, 2016
1 parent 60c1ec8 commit a29f6aa
Show file tree
Hide file tree
Showing 127 changed files with 1,547 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
"apiDeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "DeleteOptions"}),
"apiListOptions": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ListOptions"}),
"GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api/unversioned", Name: "GroupVersionResource"}),
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "PatchType"}),
"Everything": c.Universe.Function(types.Name{Package: "k8s.io/kubernetes/pkg/labels", Name: "Everything"}),

"NewRootListAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootListAction"}),
Expand All @@ -133,6 +134,8 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
"NewWatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewWatchAction"}),
"NewUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewUpdateSubresourceAction"}),
"NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootUpdateSubresourceAction"}),
"NewRootPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchAction"}),
"NewPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchAction"}),
}

noMethods := types.ExtractCommentTags("+", t.SecondClosestCommentLines)["noMethods"] == "true"
Expand Down Expand Up @@ -160,7 +163,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
sw.Do(listTemplate, m)
}
sw.Do(watchTemplate, m)

sw.Do(patchTemplate, m)
}

return sw.Error()
Expand Down Expand Up @@ -297,3 +300,16 @@ func (c *Fake$.type|publicPlural$) Watch(opts $.apiListOptions|raw$) ($.watchInt
$else$InvokesWatch($.NewRootWatchAction|raw$($.type|allLowercasePlural$Resource, opts))$end$
}
`

var patchTemplate = `
// Patch applies the patch and returns the patched $.type|private$.
func (c *Fake$.type|publicPlural$) Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error) {
obj, err := c.Fake.
$if .namespaced$Invokes($.NewPatchAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, data), &$.type|raw${})
$else$Invokes($.NewRootPatchAction|raw$($.type|allLowercasePlural$Resource, name, data), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
return obj.(*$.type|raw$), err
}
`
20 changes: 19 additions & 1 deletion cmd/libs/go2idl/client-gen/generators/generator_for_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
"apiDeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "DeleteOptions"}),
"apiListOptions": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ListOptions"}),
"apiParameterCodec": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ParameterCodec"}),
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "PatchType"}),
"namespaced": namespaced,
}

Expand Down Expand Up @@ -118,6 +119,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
sw.Do(getTemplate, m)
sw.Do(listTemplate, m)
sw.Do(watchTemplate, m)
sw.Do(patchTemplate, m)
}

return sw.Error()
Expand Down Expand Up @@ -158,7 +160,8 @@ var interfaceTemplate3 = `
DeleteCollection(options *$.apiDeleteOptions|raw$, listOptions $.apiListOptions|raw$) error
Get(name string) (*$.type|raw$, error)
List(opts $.apiListOptions|raw$) (*$.type|raw$List, error)
Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error)`
Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error)
Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error)`

var interfaceTemplate4 = `
$.type|public$Expansion
Expand Down Expand Up @@ -309,3 +312,18 @@ func (c *$.type|privatePlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterf
Watch()
}
`

var patchTemplate = `
// Patch applies the patch and returns the patched $.type|private$.
func (c *$.type|privatePlural$) Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error) {
result = &$.type|raw${}
err = c.client.Patch(pt).
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|allLowercasePlural$").
Name(name).
Body(data).
Do().
Into(result)
return
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func (c *FakeTestTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
InvokesWatch(core.NewWatchAction(testtypesResource, c.ns, opts))

}

// Patch applies the patch and returns the patched testType.
func (c *FakeTestTypes) Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(testtypesResource, c.ns, name, data), &testgroup_k8s_io.TestType{})

if obj == nil {
return nil, err
}
return obj.(*testgroup_k8s_io.TestType), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,25 @@ func TestExpansionInterface(t *testing.T) {
t.Errorf("expansion failed")
}
}

func TestPatchTestType(t *testing.T) {
ns := api.NamespaceDefault
requestTestType := &testgroup.TestType{
ObjectMeta: api.ObjectMeta{
Name: "foo",
ResourceVersion: "1",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
}
c := DecoratedSimpleClient{
simpleClient: simple.Client{
Request: simple.Request{Method: "PATCH", Path: testHelper.ResourcePath("testtypes", ns, "foo"), Query: simple.BuildQueryValues(nil)},
Response: simple.Response{StatusCode: http.StatusOK, Body: requestTestType},
},
}
receivedTestType, err := c.Setup(t).TestTypes(ns).Patch(requestTestType.Name, api.StrategicMergePatchType, []byte{})
c.simpleClient.Validate(t, receivedTestType, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TestTypeInterface interface {
Get(name string) (*testgroup_k8s_io.TestType, error)
List(opts api.ListOptions) (*testgroup_k8s_io.TestTypeList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error)
TestTypeExpansion
}

Expand Down Expand Up @@ -148,3 +149,16 @@ func (c *testTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched testType.
func (c *testTypes) Patch(name string, pt api.PatchType, data []byte) (result *testgroup_k8s_io.TestType, err error) {
result = &testgroup_k8s_io.TestType{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("testtypes").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ func (c *FakeServices) Watch(opts api.ListOptions) (watch.Interface, error) {
InvokesWatch(core.NewWatchAction(servicesResource, c.ns, opts))

}

// Patch applies the patch and returns the patched service.
func (c *FakeServices) Patch(name string, pt api.PatchType, data []byte) (result *api.Service, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(servicesResource, c.ns, name, data), &api.Service{})

if obj == nil {
return nil, err
}
return obj.(*api.Service), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ServiceInterface interface {
Get(name string) (*api.Service, error)
List(opts api.ListOptions) (*api.ServiceList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *api.Service, err error)
ServiceExpansion
}

Expand Down Expand Up @@ -147,3 +148,16 @@ func (c *services) Watch(opts api.ListOptions) (watch.Interface, error) {
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched service.
func (c *services) Patch(name string, pt api.PatchType, data []byte) (result *api.Service, err error) {
result = &api.Service{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("services").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ClusterInterface interface {
Get(name string) (*federation.Cluster, error)
List(opts api.ListOptions) (*federation.ClusterList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *federation.Cluster, err error)
ClusterExpansion
}

Expand Down Expand Up @@ -138,3 +139,15 @@ func (c *clusters) Watch(opts api.ListOptions) (watch.Interface, error) {
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched cluster.
func (c *clusters) Patch(name string, pt api.PatchType, data []byte) (result *federation.Cluster, err error) {
result = &federation.Cluster{}
err = c.client.Patch(pt).
Resource("clusters").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ func (c *FakeClusters) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(core.NewRootWatchAction(clustersResource, opts))
}

// Patch applies the patch and returns the patched cluster.
func (c *FakeClusters) Patch(name string, pt api.PatchType, data []byte) (result *federation.Cluster, err error) {
obj, err := c.Fake.
Invokes(core.NewRootPatchAction(clustersResource, name, data), &federation.Cluster{})
if obj == nil {
return nil, err
}
return obj.(*federation.Cluster), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func (c *FakeServices) Watch(opts api.ListOptions) (watch.Interface, error) {
InvokesWatch(core.NewWatchAction(servicesResource, c.ns, opts))

}

// Patch applies the patch and returns the patched service.
func (c *FakeServices) Patch(name string, pt api.PatchType, data []byte) (result *v1.Service, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(servicesResource, c.ns, name, data), &v1.Service{})

if obj == nil {
return nil, err
}
return obj.(*v1.Service), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ServiceInterface interface {
Get(name string) (*v1.Service, error)
List(opts api.ListOptions) (*v1.ServiceList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *v1.Service, err error)
ServiceExpansion
}

Expand Down Expand Up @@ -148,3 +149,16 @@ func (c *services) Watch(opts api.ListOptions) (watch.Interface, error) {
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched service.
func (c *services) Patch(name string, pt api.PatchType, data []byte) (result *v1.Service, err error) {
result = &v1.Service{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("services").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ClusterInterface interface {
Get(name string) (*v1alpha1.Cluster, error)
List(opts api.ListOptions) (*v1alpha1.ClusterList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *v1alpha1.Cluster, err error)
ClusterExpansion
}

Expand Down Expand Up @@ -138,3 +139,15 @@ func (c *clusters) Watch(opts api.ListOptions) (watch.Interface, error) {
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched cluster.
func (c *clusters) Patch(name string, pt api.PatchType, data []byte) (result *v1alpha1.Cluster, err error) {
result = &v1alpha1.Cluster{}
err = c.client.Patch(pt).
Resource("clusters").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ func (c *FakeClusters) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(core.NewRootWatchAction(clustersResource, opts))
}

// Patch applies the patch and returns the patched cluster.
func (c *FakeClusters) Patch(name string, pt api.PatchType, data []byte) (result *v1alpha1.Cluster, err error) {
obj, err := c.Fake.
Invokes(core.NewRootPatchAction(clustersResource, name, data), &v1alpha1.Cluster{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Cluster), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func (c *FakeHorizontalPodAutoscalers) Watch(opts api.ListOptions) (watch.Interf
InvokesWatch(core.NewWatchAction(horizontalpodautoscalersResource, c.ns, opts))

}

// Patch applies the patch and returns the patched horizontalPodAutoscaler.
func (c *FakeHorizontalPodAutoscalers) Patch(name string, pt api.PatchType, data []byte) (result *autoscaling.HorizontalPodAutoscaler, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(horizontalpodautoscalersResource, c.ns, name, data), &autoscaling.HorizontalPodAutoscaler{})

if obj == nil {
return nil, err
}
return obj.(*autoscaling.HorizontalPodAutoscaler), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type HorizontalPodAutoscalerInterface interface {
Get(name string) (*autoscaling.HorizontalPodAutoscaler, error)
List(opts api.ListOptions) (*autoscaling.HorizontalPodAutoscalerList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *autoscaling.HorizontalPodAutoscaler, err error)
HorizontalPodAutoscalerExpansion
}

Expand Down Expand Up @@ -148,3 +149,16 @@ func (c *horizontalPodAutoscalers) Watch(opts api.ListOptions) (watch.Interface,
VersionedParams(&opts, api.ParameterCodec).
Watch()
}

// Patch applies the patch and returns the patched horizontalPodAutoscaler.
func (c *horizontalPodAutoscalers) Patch(name string, pt api.PatchType, data []byte) (result *autoscaling.HorizontalPodAutoscaler, err error) {
result = &autoscaling.HorizontalPodAutoscaler{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("horizontalpodautoscalers").
Name(name).
Body(data).
Do().
Into(result)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func (c *FakeJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
InvokesWatch(core.NewWatchAction(jobsResource, c.ns, opts))

}

// Patch applies the patch and returns the patched job.
func (c *FakeJobs) Patch(name string, pt api.PatchType, data []byte) (result *batch.Job, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(jobsResource, c.ns, name, data), &batch.Job{})

if obj == nil {
return nil, err
}
return obj.(*batch.Job), err
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func (c *FakeScheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error)
InvokesWatch(core.NewWatchAction(scheduledjobsResource, c.ns, opts))

}

// Patch applies the patch and returns the patched scheduledJob.
func (c *FakeScheduledJobs) Patch(name string, pt api.PatchType, data []byte) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(scheduledjobsResource, c.ns, name, data), &batch.ScheduledJob{})

if obj == nil {
return nil, err
}
return obj.(*batch.ScheduledJob), err
}
Loading

0 comments on commit a29f6aa

Please sign in to comment.