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
79d8c975
Commit
79d8c975
authored
Aug 25, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scale x->x in kubectl for ReplicationController
parent
bdeeb9db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
17 deletions
+35
-17
scale.go
pkg/kubectl/scale.go
+33
-15
stop_test.go
pkg/kubectl/stop_test.go
+2
-2
No files found.
pkg/kubectl/scale.go
View file @
79d8c975
...
@@ -198,27 +198,45 @@ func (scaler *ReplicationControllerScaler) Scale(namespace, name string, newSize
...
@@ -198,27 +198,45 @@ func (scaler *ReplicationControllerScaler) Scale(namespace, name string, newSize
return
err
return
err
}
}
if
waitForReplicas
!=
nil
{
if
waitForReplicas
!=
nil
{
watchOptions
:=
api
.
ListOptions
{
FieldSelector
:
fields
.
OneTermEqualSelector
(
"metadata.name"
,
name
),
ResourceVersion
:
updatedResourceVersion
}
checkRC
:=
func
(
rc
*
api
.
ReplicationController
)
bool
{
watcher
,
err
:=
scaler
.
c
.
ReplicationControllers
(
namespace
)
.
Watch
(
watchOptions
)
if
uint
(
rc
.
Spec
.
Replicas
)
!=
newSize
{
// the size is changed by other party. Don't need to wait for the new change to complete.
return
true
}
return
rc
.
Status
.
ObservedGeneration
>=
rc
.
Generation
&&
rc
.
Status
.
Replicas
==
rc
.
Spec
.
Replicas
}
// If number of replicas doesn't change, then the update may not event
// be sent to underlying databse (we don't send no-op changes).
// In such case, <updatedResourceVersion> will have value of the most
// recent update (which may be far in the past) so we may get "too old
// RV" error from watch or potentially no ReplicationController events
// will be deliver, since it may already be in the expected state.
// To protect from these two, we first issue Get() to ensure that we
// are not already in the expected state.
currentRC
,
err
:=
scaler
.
c
.
ReplicationControllers
(
namespace
)
.
Get
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
err
=
watch
.
Until
(
waitForReplicas
.
Timeout
,
watcher
,
func
(
event
watch
.
Event
)
(
bool
,
error
)
{
if
!
checkRC
(
currentRC
)
{
if
event
.
Type
!=
watch
.
Added
&&
event
.
Type
!=
watch
.
Modified
{
watchOptions
:=
api
.
ListOptions
{
return
false
,
nil
FieldSelector
:
fields
.
OneTermEqualSelector
(
"metadata.name"
,
name
),
ResourceVersion
:
updatedResourceVersion
,
}
}
watcher
,
err
:=
scaler
.
c
.
ReplicationControllers
(
namespace
)
.
Watch
(
watchOptions
)
rc
:=
event
.
Object
.
(
*
api
.
ReplicationController
)
if
err
!=
nil
{
if
uint
(
rc
.
Spec
.
Replicas
)
!=
newSize
{
return
err
// the size is changed by other party. Don't need to wait for the new change to complete.
return
true
,
nil
}
}
return
rc
.
Status
.
ObservedGeneration
>=
rc
.
Generation
&&
rc
.
Status
.
Replicas
==
rc
.
Spec
.
Replicas
,
nil
_
,
err
=
watch
.
Until
(
waitForReplicas
.
Timeout
,
watcher
,
func
(
event
watch
.
Event
)
(
bool
,
error
)
{
})
if
event
.
Type
!=
watch
.
Added
&&
event
.
Type
!=
watch
.
Modified
{
if
err
==
wait
.
ErrWaitTimeout
{
return
false
,
nil
return
fmt
.
Errorf
(
"timed out waiting for %q to be synced"
,
name
)
}
return
checkRC
(
event
.
Object
.
(
*
api
.
ReplicationController
)),
nil
})
if
err
==
wait
.
ErrWaitTimeout
{
return
fmt
.
Errorf
(
"timed out waiting for %q to be synced"
,
name
)
}
return
err
}
}
return
err
}
}
return
nil
return
nil
}
}
...
...
pkg/kubectl/stop_test.go
View file @
79d8c975
...
@@ -70,7 +70,7 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -70,7 +70,7 @@ func TestReplicationControllerStop(t *testing.T) {
},
},
},
},
StopError
:
nil
,
StopError
:
nil
,
ExpectedActions
:
[]
string
{
"get"
,
"list"
,
"get"
,
"update"
,
"
watch
"
,
"delete"
},
ExpectedActions
:
[]
string
{
"get"
,
"list"
,
"get"
,
"update"
,
"
get
"
,
"delete"
},
},
},
{
{
Name
:
"NoOverlapping"
,
Name
:
"NoOverlapping"
,
...
@@ -108,7 +108,7 @@ func TestReplicationControllerStop(t *testing.T) {
...
@@ -108,7 +108,7 @@ func TestReplicationControllerStop(t *testing.T) {
},
},
},
},
StopError
:
nil
,
StopError
:
nil
,
ExpectedActions
:
[]
string
{
"get"
,
"list"
,
"get"
,
"update"
,
"
watch
"
,
"delete"
},
ExpectedActions
:
[]
string
{
"get"
,
"list"
,
"get"
,
"update"
,
"
get
"
,
"delete"
},
},
},
{
{
Name
:
"OverlappingError"
,
Name
:
"OverlappingError"
,
...
...
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