k8s.io/client-go@v0.31.1/scale/fake/client.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package fake provides a fake client interface to arbitrary Kubernetes 18 // APIs that exposes common high level operations and exposes common 19 // metadata. 20 package fake 21 22 import ( 23 "context" 24 25 autoscalingapi "k8s.io/api/autoscaling/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 "k8s.io/apimachinery/pkg/runtime/schema" 28 "k8s.io/apimachinery/pkg/types" 29 "k8s.io/client-go/scale" 30 "k8s.io/client-go/testing" 31 ) 32 33 // FakeScaleClient provides a fake implementation of scale.ScalesGetter. 34 type FakeScaleClient struct { 35 testing.Fake 36 } 37 38 func (f *FakeScaleClient) Scales(namespace string) scale.ScaleInterface { 39 return &fakeNamespacedScaleClient{ 40 namespace: namespace, 41 fake: &f.Fake, 42 } 43 } 44 45 type fakeNamespacedScaleClient struct { 46 namespace string 47 fake *testing.Fake 48 } 49 50 func (f *fakeNamespacedScaleClient) Get(ctx context.Context, resource schema.GroupResource, name string, opts metav1.GetOptions) (*autoscalingapi.Scale, error) { 51 obj, err := f.fake. 52 Invokes(testing.NewGetSubresourceAction(resource.WithVersion(""), f.namespace, "scale", name), &autoscalingapi.Scale{}) 53 54 if err != nil { 55 return nil, err 56 } 57 58 return obj.(*autoscalingapi.Scale), err 59 } 60 61 func (f *fakeNamespacedScaleClient) Update(ctx context.Context, resource schema.GroupResource, scale *autoscalingapi.Scale, opts metav1.UpdateOptions) (*autoscalingapi.Scale, error) { 62 obj, err := f.fake. 63 Invokes(testing.NewUpdateSubresourceAction(resource.WithVersion(""), "scale", f.namespace, scale), &autoscalingapi.Scale{}) 64 65 if err != nil { 66 return nil, err 67 } 68 69 return obj.(*autoscalingapi.Scale), err 70 } 71 72 func (f *fakeNamespacedScaleClient) Patch(ctx context.Context, gvr schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, opts metav1.PatchOptions) (*autoscalingapi.Scale, error) { 73 obj, err := f.fake. 74 Invokes(testing.NewPatchSubresourceAction(gvr, f.namespace, name, pt, patch, "scale"), &autoscalingapi.Scale{}) 75 76 if err != nil { 77 return nil, err 78 } 79 80 return obj.(*autoscalingapi.Scale), err 81 }