mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-02-01 01:12:52 +08:00
Merge pull request #87952 from mikedanese/opts
add *Options to Create, Update, and Patch in generated clientsets Kubernetes-commit: abe6321296123aaba8e83978f7d17951ab1b64fd
This commit is contained in:
commit
05e054c7a4
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -356,11 +356,11 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"Rev": "c44f517f891f"
|
||||
"Rev": "af50d22222d3"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/code-generator",
|
||||
"Rev": "dd255cc51571"
|
||||
"Rev": "396603da40fa"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo",
|
||||
|
@ -274,7 +274,7 @@ func (c *Controller) syncHandler(key string) error {
|
||||
deployment, err := c.deploymentsLister.Deployments(foo.Namespace).Get(deploymentName)
|
||||
// If the resource doesn't exist, we'll create it
|
||||
if errors.IsNotFound(err) {
|
||||
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Create(context.TODO(), newDeployment(foo))
|
||||
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Create(context.TODO(), newDeployment(foo), metav1.CreateOptions{})
|
||||
}
|
||||
|
||||
// If an error occurs during Get/Create, we'll requeue the item so we can
|
||||
@ -297,7 +297,7 @@ func (c *Controller) syncHandler(key string) error {
|
||||
// should update the Deployment resource.
|
||||
if foo.Spec.Replicas != nil && *foo.Spec.Replicas != *deployment.Spec.Replicas {
|
||||
klog.V(4).Infof("Foo %s replicas: %d, deployment replicas: %d", name, *foo.Spec.Replicas, *deployment.Spec.Replicas)
|
||||
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(context.TODO(), newDeployment(foo))
|
||||
deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(context.TODO(), newDeployment(foo), metav1.UpdateOptions{})
|
||||
}
|
||||
|
||||
// If an error occurs during Update, we'll requeue the item so we can
|
||||
@ -328,7 +328,7 @@ func (c *Controller) updateFooStatus(foo *samplev1alpha1.Foo, deployment *appsv1
|
||||
// we must use Update instead of UpdateStatus to update the Status block of the Foo resource.
|
||||
// UpdateStatus will not allow changes to the Spec of the resource,
|
||||
// which is ideal for ensuring nothing other than resource status has been updated.
|
||||
_, err := c.sampleclientset.SamplecontrollerV1alpha1().Foos(foo.Namespace).Update(context.TODO(), fooCopy)
|
||||
_, err := c.sampleclientset.SamplecontrollerV1alpha1().Foos(foo.Namespace).Update(context.TODO(), fooCopy, metav1.UpdateOptions{})
|
||||
return err
|
||||
}
|
||||
|
||||
|
8
go.mod
8
go.mod
@ -7,8 +7,8 @@ go 1.13
|
||||
require (
|
||||
k8s.io/api v0.0.0-20200209065837-d5ab0ddd8b73
|
||||
k8s.io/apimachinery v0.0.0-20200209065656-fb45917aae8b
|
||||
k8s.io/client-go v0.0.0-20200209070100-c44f517f891f
|
||||
k8s.io/code-generator v0.0.0-20200208144352-dd255cc51571
|
||||
k8s.io/client-go v0.0.0-20200209070101-af50d22222d3
|
||||
k8s.io/code-generator v0.0.0-20200209044353-396603da40fa
|
||||
k8s.io/klog v1.0.0
|
||||
)
|
||||
|
||||
@ -17,6 +17,6 @@ replace (
|
||||
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
|
||||
k8s.io/api => k8s.io/api v0.0.0-20200209065837-d5ab0ddd8b73
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200209065656-fb45917aae8b
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20200209070100-c44f517f891f
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200208144352-dd255cc51571
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20200209070101-af50d22222d3
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200209044353-396603da40fa
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -207,8 +207,8 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20200209065837-d5ab0ddd8b73/go.mod h1:p/XFTiuxjo+0OlHcql2jDLBO6mxwx4J9xy7Sq9vRtnY=
|
||||
k8s.io/apimachinery v0.0.0-20200209065656-fb45917aae8b/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4=
|
||||
k8s.io/client-go v0.0.0-20200209070100-c44f517f891f/go.mod h1:lrXl4vvqm+n6jlzJDxwcfMx2obCLSV1hYD1HuaL7WEc=
|
||||
k8s.io/code-generator v0.0.0-20200208144352-dd255cc51571/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
|
||||
k8s.io/client-go v0.0.0-20200209070101-af50d22222d3/go.mod h1:lrXl4vvqm+n6jlzJDxwcfMx2obCLSV1hYD1HuaL7WEc=
|
||||
k8s.io/code-generator v0.0.0-20200209044353-396603da40fa/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120 h1:RPscN6KhmG54S33L+lr3GS+oD1jmchIU0ll519K6FA4=
|
||||
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
@ -81,7 +81,7 @@ func (c *FakeFoos) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interf
|
||||
}
|
||||
|
||||
// Create takes the representation of a foo and creates it. Returns the server's representation of the foo, and an error, if there is any.
|
||||
func (c *FakeFoos) Create(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) {
|
||||
func (c *FakeFoos) Create(ctx context.Context, foo *v1alpha1.Foo, opts v1.CreateOptions) (result *v1alpha1.Foo, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateAction(foosResource, c.ns, foo), &v1alpha1.Foo{})
|
||||
|
||||
@ -92,7 +92,7 @@ func (c *FakeFoos) Create(ctx context.Context, foo *v1alpha1.Foo) (result *v1alp
|
||||
}
|
||||
|
||||
// Update takes the representation of a foo and updates it. Returns the server's representation of the foo, and an error, if there is any.
|
||||
func (c *FakeFoos) Update(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) {
|
||||
func (c *FakeFoos) Update(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (result *v1alpha1.Foo, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateAction(foosResource, c.ns, foo), &v1alpha1.Foo{})
|
||||
|
||||
@ -104,7 +104,7 @@ func (c *FakeFoos) Update(ctx context.Context, foo *v1alpha1.Foo) (result *v1alp
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *FakeFoos) UpdateStatus(ctx context.Context, foo *v1alpha1.Foo) (*v1alpha1.Foo, error) {
|
||||
func (c *FakeFoos) UpdateStatus(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (*v1alpha1.Foo, error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateSubresourceAction(foosResource, "status", c.ns, foo), &v1alpha1.Foo{})
|
||||
|
||||
@ -131,7 +131,7 @@ func (c *FakeFoos) DeleteCollection(ctx context.Context, options *v1.DeleteOptio
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched foo.
|
||||
func (c *FakeFoos) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error) {
|
||||
func (c *FakeFoos) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Foo, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(foosResource, c.ns, name, pt, data, subresources...), &v1alpha1.Foo{})
|
||||
|
||||
|
@ -38,15 +38,15 @@ type FoosGetter interface {
|
||||
|
||||
// FooInterface has methods to work with Foo resources.
|
||||
type FooInterface interface {
|
||||
Create(context.Context, *v1alpha1.Foo) (*v1alpha1.Foo, error)
|
||||
Update(context.Context, *v1alpha1.Foo) (*v1alpha1.Foo, error)
|
||||
UpdateStatus(context.Context, *v1alpha1.Foo) (*v1alpha1.Foo, error)
|
||||
Delete(ctx context.Context, name string, options *v1.DeleteOptions) error
|
||||
DeleteCollection(ctx context.Context, options *v1.DeleteOptions, listOptions v1.ListOptions) error
|
||||
Get(ctx context.Context, name string, options v1.GetOptions) (*v1alpha1.Foo, error)
|
||||
Create(ctx context.Context, foo *v1alpha1.Foo, opts v1.CreateOptions) (*v1alpha1.Foo, error)
|
||||
Update(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (*v1alpha1.Foo, error)
|
||||
UpdateStatus(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (*v1alpha1.Foo, error)
|
||||
Delete(ctx context.Context, name string, opts *v1.DeleteOptions) error
|
||||
DeleteCollection(ctx context.Context, opts *v1.DeleteOptions, listOpts v1.ListOptions) error
|
||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Foo, error)
|
||||
List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.FooList, error)
|
||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Foo, err error)
|
||||
FooExpansion
|
||||
}
|
||||
|
||||
@ -110,11 +110,12 @@ func (c *foos) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface,
|
||||
}
|
||||
|
||||
// Create takes the representation of a foo and creates it. Returns the server's representation of the foo, and an error, if there is any.
|
||||
func (c *foos) Create(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) {
|
||||
func (c *foos) Create(ctx context.Context, foo *v1alpha1.Foo, opts v1.CreateOptions) (result *v1alpha1.Foo, err error) {
|
||||
result = &v1alpha1.Foo{}
|
||||
err = c.client.Post().
|
||||
Namespace(c.ns).
|
||||
Resource("foos").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(foo).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
@ -122,12 +123,13 @@ func (c *foos) Create(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.
|
||||
}
|
||||
|
||||
// Update takes the representation of a foo and updates it. Returns the server's representation of the foo, and an error, if there is any.
|
||||
func (c *foos) Update(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) {
|
||||
func (c *foos) Update(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (result *v1alpha1.Foo, err error) {
|
||||
result = &v1alpha1.Foo{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("foos").
|
||||
Name(foo.Name).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(foo).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
@ -136,14 +138,14 @@ func (c *foos) Update(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.
|
||||
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
|
||||
func (c *foos) UpdateStatus(ctx context.Context, foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) {
|
||||
func (c *foos) UpdateStatus(ctx context.Context, foo *v1alpha1.Foo, opts v1.UpdateOptions) (result *v1alpha1.Foo, err error) {
|
||||
result = &v1alpha1.Foo{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("foos").
|
||||
Name(foo.Name).
|
||||
SubResource("status").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(foo).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
@ -178,13 +180,14 @@ func (c *foos) DeleteCollection(ctx context.Context, options *v1.DeleteOptions,
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched foo.
|
||||
func (c *foos) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error) {
|
||||
func (c *foos) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Foo, err error) {
|
||||
result = &v1alpha1.Foo{}
|
||||
err = c.client.Patch(pt).
|
||||
Namespace(c.ns).
|
||||
Resource("foos").
|
||||
SubResource(subresources...).
|
||||
Name(name).
|
||||
SubResource(subresources...).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
|
Loading…
Reference in New Issue
Block a user