Merge pull request #88599 from julianvmodesto/scale-ctx-opts
Add context and options to scale client Kubernetes-commit: 179fe40d06bc07b0e6602b203a8fb8e722c4e2a4
This commit is contained in:
commit
ef860b531e
|
@ -568,11 +568,11 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "573bfcf8bde3"
|
||||
"Rev": "0a52b7486422"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "003f3e63f669"
|
||||
"Rev": "ac276fc34867"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/cli-runtime",
|
||||
|
@ -580,7 +580,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"Rev": "d319f3c8b1b5"
|
||||
"Rev": "7b31ec144ad8"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/code-generator",
|
||||
|
|
12
go.mod
12
go.mod
|
@ -37,10 +37,10 @@ require (
|
|||
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
k8s.io/api v0.0.0-20200306082256-573bfcf8bde3
|
||||
k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669
|
||||
k8s.io/api v0.0.0-20200306151724-0a52b7486422
|
||||
k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867
|
||||
k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34
|
||||
k8s.io/client-go v0.0.0-20200306082531-d319f3c8b1b5
|
||||
k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8
|
||||
k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1
|
||||
k8s.io/klog v1.0.0
|
||||
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
|
||||
|
@ -54,10 +54,10 @@ require (
|
|||
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-20200306082256-573bfcf8bde3
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669
|
||||
k8s.io/api => k8s.io/api v0.0.0-20200306151724-0a52b7486422
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20200306082531-d319f3c8b1b5
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200306081859-6a048a382944
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1
|
||||
k8s.io/metrics => k8s.io/metrics v0.0.0-20200304084343-4cf3f455bf52
|
||||
|
|
6
go.sum
6
go.sum
|
@ -306,10 +306,10 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
|||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
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-20200306082256-573bfcf8bde3/go.mod h1:4bHpvwcObcdIFmIlnwDdJznMrytQbQCBpJvQgh+FnrA=
|
||||
k8s.io/apimachinery v0.0.0-20200306042133-003f3e63f669/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4=
|
||||
k8s.io/api v0.0.0-20200306151724-0a52b7486422/go.mod h1:4bHpvwcObcdIFmIlnwDdJznMrytQbQCBpJvQgh+FnrA=
|
||||
k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4=
|
||||
k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34/go.mod h1:1K5QYF8MW308AOVMg+33nPuGTXZadAOYUrG0HCZQoHM=
|
||||
k8s.io/client-go v0.0.0-20200306082531-d319f3c8b1b5/go.mod h1:pEke98/4daCxrhca+uHU2Gy77VmMObHzJPhKl6iO2NI=
|
||||
k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8/go.mod h1:9W6NBDAP22mJEhrKYXmPsL6dTQqczIp6+4GZcpWDlKs=
|
||||
k8s.io/code-generator v0.0.0-20200306081859-6a048a382944/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
|
||||
k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1/go.mod h1:3RwNWXDYjUOPPeNNQE+7cPPoWAnnL/938q4q+jnBTNk=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
|
|
@ -17,12 +17,14 @@ limitations under the License.
|
|||
package scale
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
@ -115,7 +117,7 @@ var _ Scaler = &genericScaler{}
|
|||
// ScaleSimple updates a scale of a given resource. It returns the resourceVersion of the scale if the update was successful.
|
||||
func (s *genericScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint, gvr schema.GroupVersionResource) (updatedResourceVersion string, err error) {
|
||||
if preconditions != nil {
|
||||
scale, err := s.scaleNamespacer.Scales(namespace).Get(gvr.GroupResource(), name)
|
||||
scale, err := s.scaleNamespacer.Scales(namespace).Get(context.TODO(), gvr.GroupResource(), name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -123,7 +125,7 @@ func (s *genericScaler) ScaleSimple(namespace, name string, preconditions *Scale
|
|||
return "", err
|
||||
}
|
||||
scale.Spec.Replicas = int32(newSize)
|
||||
updatedScale, err := s.scaleNamespacer.Scales(namespace).Update(gvr.GroupResource(), scale)
|
||||
updatedScale, err := s.scaleNamespacer.Scales(namespace).Update(context.TODO(), gvr.GroupResource(), scale, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -131,7 +133,7 @@ func (s *genericScaler) ScaleSimple(namespace, name string, preconditions *Scale
|
|||
}
|
||||
|
||||
patch := []byte(fmt.Sprintf(`{"spec":{"replicas":%d}}`, newSize))
|
||||
updatedScale, err := s.scaleNamespacer.Scales(namespace).Patch(gvr, name, types.MergePatchType, patch)
|
||||
updatedScale, err := s.scaleNamespacer.Scales(namespace).Patch(context.TODO(), gvr, name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -159,7 +161,7 @@ func (s *genericScaler) Scale(namespace, resourceName string, newSize uint, prec
|
|||
// count for a scale (Spec) equals its updated replicas count (Status)
|
||||
func scaleHasDesiredReplicas(sClient scaleclient.ScalesGetter, gr schema.GroupResource, resourceName string, namespace string, desiredReplicas int32) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
actualScale, err := sClient.Scales(namespace).Get(gr, resourceName)
|
||||
actualScale, err := sClient.Scales(namespace).Get(context.TODO(), gr, resourceName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue