Skip to content

Commit

Permalink
Merge pull request #28820 from caesarxuchao/patch-subresource
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

[client-gen] Allow passing subresources in Patch method

Expand the Patch() method from:
```
Patch(name string, pt api.PatchType, data []byte)
```
to
```
Patch(name string, pt api.PatchType, data []byte, subresources ...string)
```

Continue on #27293. Fixes #26580.

cc @Random-Liu @lavalamp
  • Loading branch information
k8s-merge-robot authored Jul 13, 2016
2 parents f9a45e6 + c2fb391 commit 6b6141f
Show file tree
Hide file tree
Showing 126 changed files with 349 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
"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"}),
"NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchSubresourceAction"}),
"NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchSubresourceAction"}),
}

noMethods := extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true
Expand Down Expand Up @@ -301,10 +303,10 @@ func (c *Fake$.type|publicPlural$) Watch(opts $.apiListOptions|raw$) ($.watchInt

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) {
func (c *Fake$.type|publicPlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (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 .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, data, subresources... ), &$.type|raw${})
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, name, data, subresources...), &$.type|raw${})$end$
if obj == nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/libs/go2idl/client-gen/generators/generator_for_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ var interfaceTemplate3 = `
Get(name string) (*$.type|raw$, error)
List(opts $.apiListOptions|raw$) (*$.type|raw$List, error)
Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error)
Patch(name string, pt $.PatchType|raw$, data []byte) (result *$.type|raw$, err error)`
Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error)`

var interfaceTemplate4 = `
$.type|public$Expansion
Expand Down Expand Up @@ -315,11 +315,12 @@ func (c *$.type|privatePlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterf

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) {
func (c *$.type|privatePlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.type|raw$, err error) {
result = &$.type|raw${}
err = c.client.Patch(pt).
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|allLowercasePlural$").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c *FakeTestTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *FakeTestTypes) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(testtypesResource, c.ns, name, data), &testgroup_k8s_io.TestType{})
Invokes(core.NewPatchSubresourceAction(testtypesResource, c.ns, name, data, subresources...), &testgroup_k8s_io.TestType{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,25 @@ func TestPatchTestType(t *testing.T) {
receivedTestType, err := c.Setup(t).TestTypes(ns).Patch(requestTestType.Name, api.StrategicMergePatchType, []byte{})
c.simpleClient.Validate(t, receivedTestType, err)
}

func TestPatchSubresourcesTestType(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/status"), 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{}, "status")
c.simpleClient.Validate(t, receivedTestType, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +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)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error)
TestTypeExpansion
}

Expand Down Expand Up @@ -151,11 +151,12 @@ func (c *testTypes) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *testTypes) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *testgroup_k8s_io.TestType, err error) {
result = &testgroup_k8s_io.TestType{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("testtypes").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (c *FakeServices) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *FakeServices) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *api.Service, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(servicesResource, c.ns, name, data), &api.Service{})
Invokes(core.NewPatchSubresourceAction(servicesResource, c.ns, name, data, subresources...), &api.Service{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *api.Service, err error)
ServiceExpansion
}

Expand Down Expand Up @@ -150,11 +150,12 @@ func (c *services) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *services) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *api.Service, err error) {
result = &api.Service{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("services").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +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)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *federation.Cluster, err error)
ClusterExpansion
}

Expand Down Expand Up @@ -141,10 +141,11 @@ func (c *clusters) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *clusters) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *federation.Cluster, err error) {
result = &federation.Cluster{}
err = c.client.Patch(pt).
Resource("clusters").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (c *FakeClusters) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *FakeClusters) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *federation.Cluster, err error) {
obj, err := c.Fake.
Invokes(core.NewRootPatchAction(clustersResource, name, data), &federation.Cluster{})
Invokes(core.NewRootPatchSubresourceAction(clustersResource, name, data, subresources...), &federation.Cluster{})
if obj == nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c *FakeServices) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *FakeServices) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *v1.Service, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(servicesResource, c.ns, name, data), &v1.Service{})
Invokes(core.NewPatchSubresourceAction(servicesResource, c.ns, name, data, subresources...), &v1.Service{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +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)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *v1.Service, err error)
ServiceExpansion
}

Expand Down Expand Up @@ -151,11 +151,12 @@ func (c *services) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *services) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *v1.Service, err error) {
result = &v1.Service{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("services").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ClusterInterface interface {
Get(name string) (*v1beta1.Cluster, error)
List(opts api.ListOptions) (*v1beta1.ClusterList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *v1beta1.Cluster, err error)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *v1beta1.Cluster, err error)
ClusterExpansion
}

Expand Down Expand Up @@ -141,10 +141,11 @@ func (c *clusters) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// Patch applies the patch and returns the patched cluster.
func (c *clusters) Patch(name string, pt api.PatchType, data []byte) (result *v1beta1.Cluster, err error) {
func (c *clusters) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *v1beta1.Cluster, err error) {
result = &v1beta1.Cluster{}
err = c.client.Patch(pt).
Resource("clusters").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (c *FakeClusters) Watch(opts api.ListOptions) (watch.Interface, error) {
}

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

// 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) {
func (c *FakeHorizontalPodAutoscalers) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *autoscaling.HorizontalPodAutoscaler, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(horizontalpodautoscalersResource, c.ns, name, data), &autoscaling.HorizontalPodAutoscaler{})
Invokes(core.NewPatchSubresourceAction(horizontalpodautoscalersResource, c.ns, name, data, subresources...), &autoscaling.HorizontalPodAutoscaler{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +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)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *autoscaling.HorizontalPodAutoscaler, err error)
HorizontalPodAutoscalerExpansion
}

Expand Down Expand Up @@ -151,11 +151,12 @@ func (c *horizontalPodAutoscalers) Watch(opts api.ListOptions) (watch.Interface,
}

// 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) {
func (c *horizontalPodAutoscalers) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *autoscaling.HorizontalPodAutoscaler, err error) {
result = &autoscaling.HorizontalPodAutoscaler{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("horizontalpodautoscalers").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c *FakeJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// 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) {
func (c *FakeJobs) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.Job, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(jobsResource, c.ns, name, data), &batch.Job{})
Invokes(core.NewPatchSubresourceAction(jobsResource, c.ns, name, data, subresources...), &batch.Job{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c *FakeScheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error)
}

// 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) {
func (c *FakeScheduledJobs) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.ScheduledJob, err error) {
obj, err := c.Fake.
Invokes(core.NewPatchAction(scheduledjobsResource, c.ns, name, data), &batch.ScheduledJob{})
Invokes(core.NewPatchSubresourceAction(scheduledjobsResource, c.ns, name, data, subresources...), &batch.ScheduledJob{})

if obj == nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type JobInterface interface {
Get(name string) (*batch.Job, error)
List(opts api.ListOptions) (*batch.JobList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *batch.Job, err error)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.Job, err error)
JobExpansion
}

Expand Down Expand Up @@ -151,11 +151,12 @@ func (c *jobs) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// Patch applies the patch and returns the patched job.
func (c *jobs) Patch(name string, pt api.PatchType, data []byte) (result *batch.Job, err error) {
func (c *jobs) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.Job, err error) {
result = &batch.Job{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("jobs").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ScheduledJobInterface interface {
Get(name string) (*batch.ScheduledJob, error)
List(opts api.ListOptions) (*batch.ScheduledJobList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *batch.ScheduledJob, err error)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.ScheduledJob, err error)
ScheduledJobExpansion
}

Expand Down Expand Up @@ -151,11 +151,12 @@ func (c *scheduledJobs) Watch(opts api.ListOptions) (watch.Interface, error) {
}

// Patch applies the patch and returns the patched scheduledJob.
func (c *scheduledJobs) Patch(name string, pt api.PatchType, data []byte) (result *batch.ScheduledJob, err error) {
func (c *scheduledJobs) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *batch.ScheduledJob, err error) {
result = &batch.ScheduledJob{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("scheduledjobs").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CertificateSigningRequestInterface interface {
Get(name string) (*certificates.CertificateSigningRequest, error)
List(opts api.ListOptions) (*certificates.CertificateSigningRequestList, error)
Watch(opts api.ListOptions) (watch.Interface, error)
Patch(name string, pt api.PatchType, data []byte) (result *certificates.CertificateSigningRequest, err error)
Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *certificates.CertificateSigningRequest, err error)
CertificateSigningRequestExpansion
}

Expand Down Expand Up @@ -141,10 +141,11 @@ func (c *certificateSigningRequests) Watch(opts api.ListOptions) (watch.Interfac
}

// Patch applies the patch and returns the patched certificateSigningRequest.
func (c *certificateSigningRequests) Patch(name string, pt api.PatchType, data []byte) (result *certificates.CertificateSigningRequest, err error) {
func (c *certificateSigningRequests) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *certificates.CertificateSigningRequest, err error) {
result = &certificates.CertificateSigningRequest{}
err = c.client.Patch(pt).
Resource("certificatesigningrequests").
SubResource(subresources...).
Name(name).
Body(data).
Do().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (c *FakeCertificateSigningRequests) Watch(opts api.ListOptions) (watch.Inte
}

// Patch applies the patch and returns the patched certificateSigningRequest.
func (c *FakeCertificateSigningRequests) Patch(name string, pt api.PatchType, data []byte) (result *certificates.CertificateSigningRequest, err error) {
func (c *FakeCertificateSigningRequests) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *certificates.CertificateSigningRequest, err error) {
obj, err := c.Fake.
Invokes(core.NewRootPatchAction(certificatesigningrequestsResource, name, data), &certificates.CertificateSigningRequest{})
Invokes(core.NewRootPatchSubresourceAction(certificatesigningrequestsResource, name, data, subresources...), &certificates.CertificateSigningRequest{})
if obj == nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 6b6141f

Please sign in to comment.