mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Remove kubectl reapers
This commit is contained in:
@@ -21,10 +21,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/scale"
|
||||
fakescale "k8s.io/client-go/scale/fake"
|
||||
testcore "k8s.io/client-go/testing"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
)
|
||||
|
||||
@@ -626,3 +630,54 @@ func TestGenericScale(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func createFakeScaleClient(resource string, resourceName string, replicas int, errorsOnVerb map[string]*kerrors.StatusError) *fakescale.FakeScaleClient {
|
||||
shouldReturnAnError := func(verb string) (*kerrors.StatusError, bool) {
|
||||
if anError, anErrorExists := errorsOnVerb[verb]; anErrorExists {
|
||||
return anError, true
|
||||
}
|
||||
return &kerrors.StatusError{}, false
|
||||
}
|
||||
newReplicas := int32(replicas)
|
||||
scaleClient := &fakescale.FakeScaleClient{}
|
||||
scaleClient.AddReactor("get", resource, func(rawAction testcore.Action) (handled bool, ret runtime.Object, err error) {
|
||||
action := rawAction.(testcore.GetAction)
|
||||
if action.GetName() != resourceName {
|
||||
return true, nil, fmt.Errorf("expected = %s, got = %s", resourceName, action.GetName())
|
||||
}
|
||||
if anError, should := shouldReturnAnError("get"); should {
|
||||
return true, nil, anError
|
||||
}
|
||||
obj := &autoscalingv1.Scale{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: action.GetName(),
|
||||
Namespace: action.GetNamespace(),
|
||||
},
|
||||
Spec: autoscalingv1.ScaleSpec{
|
||||
Replicas: newReplicas,
|
||||
},
|
||||
}
|
||||
return true, obj, nil
|
||||
})
|
||||
scaleClient.AddReactor("update", resource, func(rawAction testcore.Action) (handled bool, ret runtime.Object, err error) {
|
||||
action := rawAction.(testcore.UpdateAction)
|
||||
obj := action.GetObject().(*autoscalingv1.Scale)
|
||||
if obj.Name != resourceName {
|
||||
return true, nil, fmt.Errorf("expected = %s, got = %s", resourceName, obj.Name)
|
||||
}
|
||||
if anError, should := shouldReturnAnError("update"); should {
|
||||
return true, nil, anError
|
||||
}
|
||||
newReplicas = obj.Spec.Replicas
|
||||
return true, &autoscalingv1.Scale{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: obj.Name,
|
||||
Namespace: action.GetNamespace(),
|
||||
},
|
||||
Spec: autoscalingv1.ScaleSpec{
|
||||
Replicas: newReplicas,
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
return scaleClient
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user