Commit ec78f3d5 authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #19349 from caesarxuchao/generate-updatestatus

Auto commit by PR queue bot
parents c059dfdb 5addb86f
......@@ -19,6 +19,7 @@ package generators
import (
"io"
"path/filepath"
"strings"
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
......@@ -49,6 +50,18 @@ func (g *genClientForType) Imports(c *generator.Context) (imports []string) {
return g.imports.ImportLines()
}
// Ideally, we'd like hasStatus to return true if there is a subresource path
// registered for "status" in the API server, but we do not have that
// information, so hasStatus returns true if the type has a status field.
func hasStatus(t *types.Type) bool {
for _, m := range t.Members {
if m.Name == "Status" && strings.Contains(m.Tags, `json:"status`) {
return true
}
}
return false
}
// GenerateType makes the body of a file implementing a set for type t.
func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
......@@ -63,11 +76,20 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
"apiListOptions": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ListOptions"}),
}
sw.Do(namespacerTemplate, m)
sw.Do(interfaceTemplate, m)
sw.Do(interfaceTemplate1, m)
// Include the UpdateStatus method if the type has a status
if hasStatus(t) {
sw.Do(interfaceUpdateStatusTemplate, m)
}
sw.Do(interfaceTemplate2, m)
sw.Do(structTemplate, m)
sw.Do(newStructTemplate, m)
sw.Do(createTemplate, m)
sw.Do(updateTemplate, m)
// Generate the UpdateStatus method if the type has a status
if hasStatus(t) {
sw.Do(updateStatusTemplate, m)
}
sw.Do(deleteTemplate, m)
sw.Do(deleteCollectionTemplate, m)
sw.Do(getTemplate, m)
......@@ -86,11 +108,17 @@ type $.type|public$Namespacer interface {
`
// template for the Interface
var interfaceTemplate = `
var interfaceTemplate1 = `
// $.type|public$Interface has methods to work with $.type|public$ resources.
type $.type|public$Interface interface {
Create(*$.type|raw$) (*$.type|raw$, error)
Update(*$.type|raw$) (*$.type|raw$, error)
Update(*$.type|raw$) (*$.type|raw$, error)`
var interfaceUpdateStatusTemplate = `
UpdateStatus(*$.type|raw$) (*$.type|raw$, error)`
// template for the Interface
var interfaceTemplate2 = `
Delete(name string, options *$.apiDeleteOptions|raw$) error
DeleteCollection(options *$.apiDeleteOptions|raw$, listOptions $.apiListOptions|raw$) error
Get(name string) (*$.type|raw$, error)
......@@ -199,6 +227,14 @@ func (c *$.type|privatePlural$) Update($.type|private$ *$.type|raw$) (result *$.
}
`
var updateStatusTemplate = `
func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (*$.type|raw$, error) {
result := &$.type|raw${}
err := c.client.Put().Resource("$.type|privatePlural$").Name($.type|private$.Name).SubResource("status").Body($.type|private$).Do().Into(result)
return result, err
}
`
var watchTemplate = `
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
func (c *$.type|privatePlural$) Watch(opts $.apiListOptions|raw$) ($.watchInterface|raw$, error) {
......
......@@ -26,6 +26,7 @@ import (
type TestType struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata,omitempty"`
Status TestTypeStatus `json:"status,omitempty"`
}
type TestTypeList struct {
......@@ -34,3 +35,7 @@ type TestTypeList struct {
Items []TestType `json:"items"`
}
type TestTypeStatus struct {
Blah string
}
......@@ -26,6 +26,7 @@ import (
type TestType struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata,omitempty"`
Status TestTypeStatus `json:"status,omitempty"`
}
type TestTypeList struct {
......@@ -34,3 +35,7 @@ type TestTypeList struct {
Items []TestType `json:"items"`
}
type TestTypeStatus struct {
Blah string
}
......@@ -97,6 +97,29 @@ func TestUpdateTestType(t *testing.T) {
c.simpleClient.Validate(t, receivedTestType, err)
}
func TestUpdateStatusTestType(t *testing.T) {
ns := api.NamespaceDefault
requestTestType := &testgroup.TestType{
ObjectMeta: api.ObjectMeta{
Name: "foo",
ResourceVersion: "1",
Labels: map[string]string{
"foo": "bar",
"name": "baz",
},
},
Status: testgroup.TestTypeStatus{"I'm in good status"},
}
c := DecoratedSimpleClient{
simpleClient: simple.Client{
Request: simple.Request{Method: "PUT", 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).Update(requestTestType)
c.simpleClient.Validate(t, receivedTestType, err)
}
func TestDeleteTestType(t *testing.T) {
ns := api.NamespaceDefault
c := DecoratedSimpleClient{
......
......@@ -31,6 +31,7 @@ type TestTypeNamespacer interface {
type TestTypeInterface interface {
Create(*testgroup.TestType) (*testgroup.TestType, error)
Update(*testgroup.TestType) (*testgroup.TestType, error)
UpdateStatus(*testgroup.TestType) (*testgroup.TestType, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*testgroup.TestType, error)
......@@ -78,6 +79,12 @@ func (c *testTypes) Update(testType *testgroup.TestType) (result *testgroup.Test
return
}
func (c *testTypes) UpdateStatus(testType *testgroup.TestType) (*testgroup.TestType, error) {
result := &testgroup.TestType{}
err := c.client.Put().Resource("testTypes").Name(testType.Name).SubResource("status").Body(testType).Do().Into(result)
return result, err
}
// Delete takes name of the testType and deletes it. Returns an error if one occurs.
func (c *testTypes) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -31,6 +31,7 @@ type DaemonSetNamespacer interface {
type DaemonSetInterface interface {
Create(*extensions.DaemonSet) (*extensions.DaemonSet, error)
Update(*extensions.DaemonSet) (*extensions.DaemonSet, error)
UpdateStatus(*extensions.DaemonSet) (*extensions.DaemonSet, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*extensions.DaemonSet, error)
......@@ -78,6 +79,12 @@ func (c *daemonSets) Update(daemonSet *extensions.DaemonSet) (result *extensions
return
}
func (c *daemonSets) UpdateStatus(daemonSet *extensions.DaemonSet) (*extensions.DaemonSet, error) {
result := &extensions.DaemonSet{}
err := c.client.Put().Resource("daemonSets").Name(daemonSet.Name).SubResource("status").Body(daemonSet).Do().Into(result)
return result, err
}
// Delete takes name of the daemonSet and deletes it. Returns an error if one occurs.
func (c *daemonSets) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -31,6 +31,7 @@ type DeploymentNamespacer interface {
type DeploymentInterface interface {
Create(*extensions.Deployment) (*extensions.Deployment, error)
Update(*extensions.Deployment) (*extensions.Deployment, error)
UpdateStatus(*extensions.Deployment) (*extensions.Deployment, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*extensions.Deployment, error)
......@@ -78,6 +79,12 @@ func (c *deployments) Update(deployment *extensions.Deployment) (result *extensi
return
}
func (c *deployments) UpdateStatus(deployment *extensions.Deployment) (*extensions.Deployment, error) {
result := &extensions.Deployment{}
err := c.client.Put().Resource("deployments").Name(deployment.Name).SubResource("status").Body(deployment).Do().Into(result)
return result, err
}
// Delete takes name of the deployment and deletes it. Returns an error if one occurs.
func (c *deployments) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -31,6 +31,7 @@ type HorizontalPodAutoscalerNamespacer interface {
type HorizontalPodAutoscalerInterface interface {
Create(*extensions.HorizontalPodAutoscaler) (*extensions.HorizontalPodAutoscaler, error)
Update(*extensions.HorizontalPodAutoscaler) (*extensions.HorizontalPodAutoscaler, error)
UpdateStatus(*extensions.HorizontalPodAutoscaler) (*extensions.HorizontalPodAutoscaler, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*extensions.HorizontalPodAutoscaler, error)
......@@ -78,6 +79,12 @@ func (c *horizontalPodAutoscalers) Update(horizontalPodAutoscaler *extensions.Ho
return
}
func (c *horizontalPodAutoscalers) UpdateStatus(horizontalPodAutoscaler *extensions.HorizontalPodAutoscaler) (*extensions.HorizontalPodAutoscaler, error) {
result := &extensions.HorizontalPodAutoscaler{}
err := c.client.Put().Resource("horizontalPodAutoscalers").Name(horizontalPodAutoscaler.Name).SubResource("status").Body(horizontalPodAutoscaler).Do().Into(result)
return result, err
}
// Delete takes name of the horizontalPodAutoscaler and deletes it. Returns an error if one occurs.
func (c *horizontalPodAutoscalers) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -31,6 +31,7 @@ type IngressNamespacer interface {
type IngressInterface interface {
Create(*extensions.Ingress) (*extensions.Ingress, error)
Update(*extensions.Ingress) (*extensions.Ingress, error)
UpdateStatus(*extensions.Ingress) (*extensions.Ingress, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*extensions.Ingress, error)
......@@ -78,6 +79,12 @@ func (c *ingresses) Update(ingress *extensions.Ingress) (result *extensions.Ingr
return
}
func (c *ingresses) UpdateStatus(ingress *extensions.Ingress) (*extensions.Ingress, error) {
result := &extensions.Ingress{}
err := c.client.Put().Resource("ingresses").Name(ingress.Name).SubResource("status").Body(ingress).Do().Into(result)
return result, err
}
// Delete takes name of the ingress and deletes it. Returns an error if one occurs.
func (c *ingresses) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -31,6 +31,7 @@ type JobNamespacer interface {
type JobInterface interface {
Create(*extensions.Job) (*extensions.Job, error)
Update(*extensions.Job) (*extensions.Job, error)
UpdateStatus(*extensions.Job) (*extensions.Job, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*extensions.Job, error)
......@@ -78,6 +79,12 @@ func (c *jobs) Update(job *extensions.Job) (result *extensions.Job, err error) {
return
}
func (c *jobs) UpdateStatus(job *extensions.Job) (*extensions.Job, error) {
result := &extensions.Job{}
err := c.client.Put().Resource("jobs").Name(job.Name).SubResource("status").Body(job).Do().Into(result)
return result, err
}
// Delete takes name of the job and deletes it. Returns an error if one occurs.
func (c *jobs) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type NamespaceNamespacer interface {
type NamespaceInterface interface {
Create(*api.Namespace) (*api.Namespace, error)
Update(*api.Namespace) (*api.Namespace, error)
UpdateStatus(*api.Namespace) (*api.Namespace, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.Namespace, error)
......@@ -77,6 +78,12 @@ func (c *namespaces) Update(namespace *api.Namespace) (result *api.Namespace, er
return
}
func (c *namespaces) UpdateStatus(namespace *api.Namespace) (*api.Namespace, error) {
result := &api.Namespace{}
err := c.client.Put().Resource("namespaces").Name(namespace.Name).SubResource("status").Body(namespace).Do().Into(result)
return result, err
}
// Delete takes name of the namespace and deletes it. Returns an error if one occurs.
func (c *namespaces) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type NodeNamespacer interface {
type NodeInterface interface {
Create(*api.Node) (*api.Node, error)
Update(*api.Node) (*api.Node, error)
UpdateStatus(*api.Node) (*api.Node, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.Node, error)
......@@ -77,6 +78,12 @@ func (c *nodes) Update(node *api.Node) (result *api.Node, err error) {
return
}
func (c *nodes) UpdateStatus(node *api.Node) (*api.Node, error) {
result := &api.Node{}
err := c.client.Put().Resource("nodes").Name(node.Name).SubResource("status").Body(node).Do().Into(result)
return result, err
}
// Delete takes name of the node and deletes it. Returns an error if one occurs.
func (c *nodes) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type PersistentVolumeNamespacer interface {
type PersistentVolumeInterface interface {
Create(*api.PersistentVolume) (*api.PersistentVolume, error)
Update(*api.PersistentVolume) (*api.PersistentVolume, error)
UpdateStatus(*api.PersistentVolume) (*api.PersistentVolume, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.PersistentVolume, error)
......@@ -77,6 +78,12 @@ func (c *persistentVolumes) Update(persistentVolume *api.PersistentVolume) (resu
return
}
func (c *persistentVolumes) UpdateStatus(persistentVolume *api.PersistentVolume) (*api.PersistentVolume, error) {
result := &api.PersistentVolume{}
err := c.client.Put().Resource("persistentVolumes").Name(persistentVolume.Name).SubResource("status").Body(persistentVolume).Do().Into(result)
return result, err
}
// Delete takes name of the persistentVolume and deletes it. Returns an error if one occurs.
func (c *persistentVolumes) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type PersistentVolumeClaimNamespacer interface {
type PersistentVolumeClaimInterface interface {
Create(*api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error)
Update(*api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error)
UpdateStatus(*api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.PersistentVolumeClaim, error)
......@@ -77,6 +78,12 @@ func (c *persistentVolumeClaims) Update(persistentVolumeClaim *api.PersistentVol
return
}
func (c *persistentVolumeClaims) UpdateStatus(persistentVolumeClaim *api.PersistentVolumeClaim) (*api.PersistentVolumeClaim, error) {
result := &api.PersistentVolumeClaim{}
err := c.client.Put().Resource("persistentVolumeClaims").Name(persistentVolumeClaim.Name).SubResource("status").Body(persistentVolumeClaim).Do().Into(result)
return result, err
}
// Delete takes name of the persistentVolumeClaim and deletes it. Returns an error if one occurs.
func (c *persistentVolumeClaims) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type PodNamespacer interface {
type PodInterface interface {
Create(*api.Pod) (*api.Pod, error)
Update(*api.Pod) (*api.Pod, error)
UpdateStatus(*api.Pod) (*api.Pod, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.Pod, error)
......@@ -77,6 +78,12 @@ func (c *pods) Update(pod *api.Pod) (result *api.Pod, err error) {
return
}
func (c *pods) UpdateStatus(pod *api.Pod) (*api.Pod, error) {
result := &api.Pod{}
err := c.client.Put().Resource("pods").Name(pod.Name).SubResource("status").Body(pod).Do().Into(result)
return result, err
}
// Delete takes name of the pod and deletes it. Returns an error if one occurs.
func (c *pods) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type ReplicationControllerNamespacer interface {
type ReplicationControllerInterface interface {
Create(*api.ReplicationController) (*api.ReplicationController, error)
Update(*api.ReplicationController) (*api.ReplicationController, error)
UpdateStatus(*api.ReplicationController) (*api.ReplicationController, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.ReplicationController, error)
......@@ -77,6 +78,12 @@ func (c *replicationControllers) Update(replicationController *api.ReplicationCo
return
}
func (c *replicationControllers) UpdateStatus(replicationController *api.ReplicationController) (*api.ReplicationController, error) {
result := &api.ReplicationController{}
err := c.client.Put().Resource("replicationControllers").Name(replicationController.Name).SubResource("status").Body(replicationController).Do().Into(result)
return result, err
}
// Delete takes name of the replicationController and deletes it. Returns an error if one occurs.
func (c *replicationControllers) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type ResourceQuotaNamespacer interface {
type ResourceQuotaInterface interface {
Create(*api.ResourceQuota) (*api.ResourceQuota, error)
Update(*api.ResourceQuota) (*api.ResourceQuota, error)
UpdateStatus(*api.ResourceQuota) (*api.ResourceQuota, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.ResourceQuota, error)
......@@ -77,6 +78,12 @@ func (c *resourceQuotas) Update(resourceQuota *api.ResourceQuota) (result *api.R
return
}
func (c *resourceQuotas) UpdateStatus(resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
result := &api.ResourceQuota{}
err := c.client.Put().Resource("resourceQuotas").Name(resourceQuota.Name).SubResource("status").Body(resourceQuota).Do().Into(result)
return result, err
}
// Delete takes name of the resourceQuota and deletes it. Returns an error if one occurs.
func (c *resourceQuotas) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
......@@ -30,6 +30,7 @@ type ServiceNamespacer interface {
type ServiceInterface interface {
Create(*api.Service) (*api.Service, error)
Update(*api.Service) (*api.Service, error)
UpdateStatus(*api.Service) (*api.Service, error)
Delete(name string, options *api.DeleteOptions) error
DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
Get(name string) (*api.Service, error)
......@@ -77,6 +78,12 @@ func (c *services) Update(service *api.Service) (result *api.Service, err error)
return
}
func (c *services) UpdateStatus(service *api.Service) (*api.Service, error) {
result := &api.Service{}
err := c.client.Put().Resource("services").Name(service.Name).SubResource("status").Body(service).Do().Into(result)
return result, err
}
// Delete takes name of the service and deletes it. Returns an error if one occurs.
func (c *services) Delete(name string, options *api.DeleteOptions) error {
return c.client.Delete().
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment