Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f8cd676f
Unverified
Commit
f8cd676f
authored
Mar 29, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 29, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75210 from deads2k/scale-toleration
make kubectl scale work without a GET if a precodition isn't requested
parents
733f2478
838721b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
scale.go
pkg/kubectl/cmd/scale/scale.go
+6
-1
scale.go
pkg/kubectl/scale.go
+10
-9
No files found.
pkg/kubectl/cmd/scale/scale.go
View file @
f8cd676f
...
...
@@ -209,7 +209,12 @@ func (o *ScaleOptions) RunScale() error {
return
fmt
.
Errorf
(
"cannot use --resource-version with multiple resources"
)
}
precondition
:=
&
kubectl
.
ScalePrecondition
{
Size
:
o
.
CurrentReplicas
,
ResourceVersion
:
o
.
ResourceVersion
}
// only set a precondition if the user has requested one. A nil precondition means we can do a blind update, so
// we avoid a Scale GET that may or may not succeed
var
precondition
*
kubectl
.
ScalePrecondition
if
o
.
CurrentReplicas
!=
-
1
||
len
(
o
.
ResourceVersion
)
>
0
{
precondition
=
&
kubectl
.
ScalePrecondition
{
Size
:
o
.
CurrentReplicas
,
ResourceVersion
:
o
.
ResourceVersion
}
}
retry
:=
kubectl
.
NewRetryParams
(
1
*
time
.
Second
,
5
*
time
.
Minute
)
var
waitForReplicas
*
kubectl
.
RetryParams
...
...
pkg/kubectl/scale.go
View file @
f8cd676f
...
...
@@ -21,11 +21,11 @@ import (
"strconv"
"time"
autoscaling
api
"k8s.io/api/autoscaling/v1"
autoscaling
v1
"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/util/wait"
scaleclient
"k8s.io/client-go/scale"
)
...
...
@@ -95,7 +95,7 @@ func ScaleCondition(r Scaler, precondition *ScalePrecondition, namespace, name s
}
// validateGeneric ensures that the preconditions match. Returns nil if they are valid, otherwise an error
func
(
precondition
*
ScalePrecondition
)
validate
(
scale
*
autoscaling
api
.
Scale
)
error
{
func
(
precondition
*
ScalePrecondition
)
validate
(
scale
*
autoscaling
v1
.
Scale
)
error
{
if
precondition
.
Size
!=
-
1
&&
int
(
scale
.
Spec
.
Replicas
)
!=
precondition
.
Size
{
return
PreconditionError
{
"replicas"
,
strconv
.
Itoa
(
precondition
.
Size
),
strconv
.
Itoa
(
int
(
scale
.
Spec
.
Replicas
))}
}
...
...
@@ -114,11 +114,15 @@ 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
,
gr
schema
.
GroupResource
)
(
updatedResourceVersion
string
,
err
error
)
{
scale
,
err
:=
s
.
scaleNamespacer
.
Scales
(
namespace
)
.
Get
(
gr
,
name
)
if
err
!=
nil
{
return
""
,
err
scale
:=
&
autoscalingv1
.
Scale
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
namespace
,
Name
:
name
},
}
if
preconditions
!=
nil
{
var
err
error
scale
,
err
=
s
.
scaleNamespacer
.
Scales
(
namespace
)
.
Get
(
gr
,
name
)
if
err
!=
nil
{
return
""
,
err
}
if
err
:=
preconditions
.
validate
(
scale
);
err
!=
nil
{
return
""
,
err
}
...
...
@@ -135,9 +139,6 @@ func (s *genericScaler) ScaleSimple(namespace, name string, preconditions *Scale
// Scale updates a scale of a given resource to a new size, with optional precondition check (if preconditions is not nil),
// optional retries (if retry is not nil), and then optionally waits for the status to reach desired count.
func
(
s
*
genericScaler
)
Scale
(
namespace
,
resourceName
string
,
newSize
uint
,
preconditions
*
ScalePrecondition
,
retry
,
waitForReplicas
*
RetryParams
,
gr
schema
.
GroupResource
)
error
{
if
preconditions
==
nil
{
preconditions
=
&
ScalePrecondition
{
-
1
,
""
}
}
if
retry
==
nil
{
// make it try only once, immediately
retry
=
&
RetryParams
{
Interval
:
time
.
Millisecond
,
Timeout
:
time
.
Millisecond
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment