diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7e769c19..f96beecb 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -352,7 +352,7 @@ }, { "ImportPath": "k8s.io/apimachinery", - "Rev": "003f3e63f669" + "Rev": "ac276fc34867" }, { "ImportPath": "k8s.io/gengo", diff --git a/go.mod b/go.mod index fd390235..e5687fb7 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 google.golang.org/appengine v1.5.0 // indirect k8s.io/api v0.0.0-20200306151724-0a52b7486422 - k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669 + k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867 k8s.io/klog v1.0.0 k8s.io/utils v0.0.0-20200229041039-0a110f9eb7ab sigs.k8s.io/yaml v1.2.0 @@ -39,5 +39,5 @@ replace ( golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13 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-20200306151724-0a52b7486422 - k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669 + k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867 ) diff --git a/go.sum b/go.sum index fe4846e1..2d34540c 100644 --- a/go.sum +++ b/go.sum @@ -183,7 +183,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= k8s.io/api v0.0.0-20200306151724-0a52b7486422/go.mod h1:4bHpvwcObcdIFmIlnwDdJznMrytQbQCBpJvQgh+FnrA= -k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4= +k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= diff --git a/scale/client.go b/scale/client.go index 26febcb8..1306b37d 100644 --- a/scale/client.go +++ b/scale/client.go @@ -21,6 +21,7 @@ import ( "fmt" autoscaling "k8s.io/api/autoscaling/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" serializer "k8s.io/apimachinery/pkg/runtime/serializer" @@ -31,6 +32,14 @@ import ( var scaleConverter = NewScaleConverter() var codecs = serializer.NewCodecFactory(scaleConverter.Scheme()) +var parameterScheme = runtime.NewScheme() +var dynamicParameterCodec = runtime.NewParameterCodec(parameterScheme) + +var versionV1 = schema.GroupVersion{Version: "v1"} + +func init() { + metav1.AddToGroupVersion(parameterScheme, versionV1) +} // scaleClient is an implementation of ScalesGetter // which makes use of a RESTMapper and a generic REST @@ -138,7 +147,7 @@ func (c *scaleClient) Scales(namespace string) ScaleInterface { } } -func (c *namespacedScaleClient) Get(resource schema.GroupResource, name string) (*autoscaling.Scale, error) { +func (c *namespacedScaleClient) Get(ctx context.Context, resource schema.GroupResource, name string, opts metav1.GetOptions) (*autoscaling.Scale, error) { // Currently, a /scale endpoint can return different scale types. // Until we have support for the alternative API representations proposal, // we need to deal with accepting different API versions. @@ -155,7 +164,8 @@ func (c *namespacedScaleClient) Get(resource schema.GroupResource, name string) Resource(gvr.Resource). Name(name). SubResource("scale"). - Do(context.TODO()) + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Do(ctx) if err := result.Error(); err != nil { return nil, err } @@ -163,7 +173,7 @@ func (c *namespacedScaleClient) Get(resource schema.GroupResource, name string) return convertToScale(&result) } -func (c *namespacedScaleClient) Update(resource schema.GroupResource, scale *autoscaling.Scale) (*autoscaling.Scale, error) { +func (c *namespacedScaleClient) Update(ctx context.Context, resource schema.GroupResource, scale *autoscaling.Scale, opts metav1.UpdateOptions) (*autoscaling.Scale, error) { path, gvr, err := c.client.pathAndVersionFor(resource) if err != nil { return nil, fmt.Errorf("unable to get client for %s: %v", resource.String(), err) @@ -196,8 +206,9 @@ func (c *namespacedScaleClient) Update(resource schema.GroupResource, scale *aut Resource(gvr.Resource). Name(scale.Name). SubResource("scale"). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). Body(scaleUpdateBytes). - Do(context.TODO()) + Do(ctx) if err := result.Error(); err != nil { // propagate "raw" error from the API // this allows callers to interpret underlying Reason field @@ -208,7 +219,7 @@ func (c *namespacedScaleClient) Update(resource schema.GroupResource, scale *aut return convertToScale(&result) } -func (c *namespacedScaleClient) Patch(gvr schema.GroupVersionResource, name string, pt types.PatchType, data []byte) (*autoscaling.Scale, error) { +func (c *namespacedScaleClient) Patch(ctx context.Context, gvr schema.GroupVersionResource, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*autoscaling.Scale, error) { groupVersion := gvr.GroupVersion() result := c.client.clientBase.Patch(pt). AbsPath(c.client.apiPathFor(groupVersion)). @@ -216,8 +227,9 @@ func (c *namespacedScaleClient) Patch(gvr schema.GroupVersionResource, name stri Resource(gvr.Resource). Name(name). SubResource("scale"). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). Body(data). - Do(context.TODO()) + Do(ctx) if err := result.Error(); err != nil { return nil, err } diff --git a/scale/client_test.go b/scale/client_test.go index 433ff81e..c5386cea 100644 --- a/scale/client_test.go +++ b/scale/client_test.go @@ -18,6 +18,7 @@ package scale import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -273,7 +274,7 @@ func TestGetScale(t *testing.T) { } for _, groupResource := range groupResources { - scale, err := scaleClient.Scales("default").Get(groupResource, "foo") + scale, err := scaleClient.Scales("default").Get(context.TODO(), groupResource, "foo", metav1.GetOptions{}) if !assert.NoError(t, err, "should have been able to fetch a scale for %s", groupResource.String()) { continue } @@ -301,7 +302,7 @@ func TestUpdateScale(t *testing.T) { } for _, groupResource := range groupResources { - scale, err := scaleClient.Scales("default").Update(groupResource, expectedScale) + scale, err := scaleClient.Scales("default").Update(context.TODO(), groupResource, expectedScale, metav1.UpdateOptions{}) if !assert.NoError(t, err, "should have been able to fetch a scale for %s", groupResource.String()) { continue } @@ -344,7 +345,7 @@ func TestPatchScale(t *testing.T) { patch := []byte(`{"spec":{"replicas":5}}`) for _, gvr := range gvrs { - scale, err := scaleClient.Scales("default").Patch(gvr, "foo", types.MergePatchType, patch) + scale, err := scaleClient.Scales("default").Patch(context.TODO(), gvr, "foo", types.MergePatchType, patch, metav1.PatchOptions{}) if !assert.NoError(t, err, "should have been able to fetch a scale for %s", gvr.String()) { continue } @@ -354,7 +355,7 @@ func TestPatchScale(t *testing.T) { patch = []byte(`[{"op":"replace","path":"/spec/replicas","value":5}]`) for _, gvr := range gvrs { - scale, err := scaleClient.Scales("default").Patch(gvr, "foo", types.JSONPatchType, patch) + scale, err := scaleClient.Scales("default").Patch(context.TODO(), gvr, "foo", types.JSONPatchType, patch, metav1.PatchOptions{}) if !assert.NoError(t, err, "should have been able to fetch a scale for %s", gvr.String()) { continue } diff --git a/scale/fake/client.go b/scale/fake/client.go index e3bc57ff..005a4144 100644 --- a/scale/fake/client.go +++ b/scale/fake/client.go @@ -20,7 +20,10 @@ limitations under the License. package fake import ( + "context" + autoscalingapi "k8s.io/api/autoscaling/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/scale" @@ -44,7 +47,7 @@ type fakeNamespacedScaleClient struct { fake *testing.Fake } -func (f *fakeNamespacedScaleClient) Get(resource schema.GroupResource, name string) (*autoscalingapi.Scale, error) { +func (f *fakeNamespacedScaleClient) Get(ctx context.Context, resource schema.GroupResource, name string, opts metav1.GetOptions) (*autoscalingapi.Scale, error) { obj, err := f.fake. Invokes(testing.NewGetSubresourceAction(resource.WithVersion(""), f.namespace, "scale", name), &autoscalingapi.Scale{}) @@ -55,7 +58,7 @@ func (f *fakeNamespacedScaleClient) Get(resource schema.GroupResource, name stri return obj.(*autoscalingapi.Scale), err } -func (f *fakeNamespacedScaleClient) Update(resource schema.GroupResource, scale *autoscalingapi.Scale) (*autoscalingapi.Scale, error) { +func (f *fakeNamespacedScaleClient) Update(ctx context.Context, resource schema.GroupResource, scale *autoscalingapi.Scale, opts metav1.UpdateOptions) (*autoscalingapi.Scale, error) { obj, err := f.fake. Invokes(testing.NewUpdateSubresourceAction(resource.WithVersion(""), f.namespace, "scale", scale), &autoscalingapi.Scale{}) @@ -66,7 +69,7 @@ func (f *fakeNamespacedScaleClient) Update(resource schema.GroupResource, scale return obj.(*autoscalingapi.Scale), err } -func (f *fakeNamespacedScaleClient) Patch(gvr schema.GroupVersionResource, name string, pt types.PatchType, patch []byte) (*autoscalingapi.Scale, error) { +func (f *fakeNamespacedScaleClient) Patch(ctx context.Context, gvr schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions) (*autoscalingapi.Scale, error) { obj, err := f.fake. Invokes(testing.NewPatchSubresourceAction(gvr, f.namespace, name, pt, patch, "scale"), &autoscalingapi.Scale{}) diff --git a/scale/interfaces.go b/scale/interfaces.go index 16c20d79..a7bb3e6c 100644 --- a/scale/interfaces.go +++ b/scale/interfaces.go @@ -17,7 +17,10 @@ limitations under the License. package scale import ( + "context" + autoscalingapi "k8s.io/api/autoscaling/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" ) @@ -34,11 +37,11 @@ type ScalesGetter interface { // the scale subresource. type ScaleInterface interface { // Get fetches the scale of the given scalable resource. - Get(resource schema.GroupResource, name string) (*autoscalingapi.Scale, error) + Get(ctx context.Context, resource schema.GroupResource, name string, opts metav1.GetOptions) (*autoscalingapi.Scale, error) // Update updates the scale of the given scalable resource. - Update(resource schema.GroupResource, scale *autoscalingapi.Scale) (*autoscalingapi.Scale, error) + Update(ctx context.Context, resource schema.GroupResource, scale *autoscalingapi.Scale, opts metav1.UpdateOptions) (*autoscalingapi.Scale, error) // Patch patches the scale of the given scalable resource. - Patch(gvr schema.GroupVersionResource, name string, pt types.PatchType, data []byte) (*autoscalingapi.Scale, error) + Patch(ctx context.Context, gvr schema.GroupVersionResource, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*autoscalingapi.Scale, error) }