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
0faa27e6
Commit
0faa27e6
authored
Oct 27, 2016
by
Michal Fojtik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use PATCH when pausing/resuming objects and CalculatePatches to get the patch
parent
e4b41dd2
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
61 deletions
+82
-61
test-cmd.sh
hack/make-rules/test-cmd.sh
+4
-4
BUILD
pkg/kubectl/cmd/rollout/BUILD
+2
-0
rollout_pause.go
pkg/kubectl/cmd/rollout/rollout_pause.go
+23
-7
rollout_resume.go
pkg/kubectl/cmd/rollout/rollout_resume.go
+24
-7
helper.go
pkg/kubectl/cmd/set/helper.go
+9
-3
fake.go
pkg/kubectl/cmd/testing/fake.go
+2
-2
factory.go
pkg/kubectl/cmd/util/factory.go
+18
-38
No files found.
hack/make-rules/test-cmd.sh
View file @
0faa27e6
...
@@ -1580,15 +1580,15 @@ __EOF__
...
@@ -1580,15 +1580,15 @@ __EOF__
## Attempt to pause the replication controllers recursively
## Attempt to pause the replication controllers recursively
output_message
=
$(
!
kubectl rollout pause
-f
hack/testdata/recursive/rc
--recursive
2>&1
"
${
kube_flags
[@]
}
"
)
output_message
=
$(
!
kubectl rollout pause
-f
hack/testdata/recursive/rc
--recursive
2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: busybox0 & busybox1 should error as they are RC's, and since busybox2 is malformed, it should error
# Post-condition: busybox0 & busybox1 should error as they are RC's, and since busybox2 is malformed, it should error
kube::test::if_has_string
"
${
output_message
}
"
'error when pausing "hack/testdata/recursive/rc/busybox.yaml'
kube::test::if_has_string
"
${
output_message
}
"
'error when pausing "hack/testdata/recursive/rc/rc/busybox.yaml'
kube::test::if_has_string
"
${
output_message
}
"
"Object 'Kind' is missing"
kube::test::if_has_string
"
${
output_message
}
"
"Object 'Kind' is missing"
kube::test::if_has_string
"
${
output_message
}
"
'replicationcontrollers "busybox0" pausing is not supported'
kube::test::if_has_string
"
${
output_message
}
"
'replicationcontrollers "busybox1" pausing is not supported'
## Attempt to resume the replication controllers recursively
## Attempt to resume the replication controllers recursively
output_message
=
$(
!
kubectl rollout resume
-f
hack/testdata/recursive/rc
--recursive
2>&1
"
${
kube_flags
[@]
}
"
)
output_message
=
$(
!
kubectl rollout resume
-f
hack/testdata/recursive/rc
--recursive
2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: busybox0 & busybox1 should error as they are RC's, and since busybox2 is malformed, it should error
# Post-condition: busybox0 & busybox1 should error as they are RC's, and since busybox2 is malformed, it should error
kube::test::if_has_string
"
${
output_message
}
"
'error when resuming "hack/testdata/recursive/rc/busybox.yaml'
kube::test::if_has_string
"
${
output_message
}
"
'error when resuming "hack/testdata/recursive/rc/rc/busybox.yaml'
kube::test::if_has_string
"
${
output_message
}
"
"Object 'Kind' is missing"
kube::test::if_has_string
"
${
output_message
}
"
"Object 'Kind' is missing"
kube::test::if_has_string
"
${
output_message
}
"
'replicationcontrollers "busybox0" resuming is not supported'
kube::test::if_has_string
"
${
output_message
}
"
'replicationcontrollers "busybox0" resuming is not supported'
# Clean up
# Clean up
!
kubectl delete
-f
hack/testdata/recursive/rc
--recursive
"
${
kube_flags
[@]
}
"
--grace-period
=
0
!
kubectl delete
-f
hack/testdata/recursive/rc
--recursive
"
${
kube_flags
[@]
}
"
--grace-period
=
0
sleep
1
sleep
1
...
...
pkg/kubectl/cmd/rollout/BUILD
View file @
0faa27e6
...
@@ -22,8 +22,10 @@ go_library(
...
@@ -22,8 +22,10 @@ go_library(
],
],
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//pkg/api:go_default_library",
"//pkg/api/meta:go_default_library",
"//pkg/api/meta:go_default_library",
"//pkg/kubectl:go_default_library",
"//pkg/kubectl:go_default_library",
"//pkg/kubectl/cmd/set:go_default_library",
"//pkg/kubectl/cmd/templates:go_default_library",
"//pkg/kubectl/cmd/templates:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/kubectl/resource:go_default_library",
"//pkg/kubectl/resource:go_default_library",
...
...
pkg/kubectl/cmd/rollout/rollout_pause.go
View file @
0faa27e6
...
@@ -17,12 +17,15 @@ limitations under the License.
...
@@ -17,12 +17,15 @@ limitations under the License.
package
rollout
package
rollout
import
(
import
(
"fmt"
"io"
"io"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
...
@@ -35,9 +38,10 @@ import (
...
@@ -35,9 +38,10 @@ import (
type
PauseConfig
struct
{
type
PauseConfig
struct
{
resource
.
FilenameOptions
resource
.
FilenameOptions
Pause
Object
func
(
object
runtime
.
Object
)
(
bool
,
error
)
Pause
r
func
(
info
*
resource
.
Info
)
(
bool
,
error
)
Mapper
meta
.
RESTMapper
Mapper
meta
.
RESTMapper
Typer
runtime
.
ObjectTyper
Typer
runtime
.
ObjectTyper
Encoder
runtime
.
Encoder
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Out
io
.
Writer
Out
io
.
Writer
...
@@ -96,7 +100,9 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
...
@@ -96,7 +100,9 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
}
}
o
.
Mapper
,
o
.
Typer
=
f
.
Object
()
o
.
Mapper
,
o
.
Typer
=
f
.
Object
()
o
.
PauseObject
=
f
.
PauseObject
o
.
Encoder
=
f
.
JSONEncoder
()
o
.
Pauser
=
f
.
Pauser
o
.
Out
=
out
o
.
Out
=
out
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
...
@@ -126,17 +132,27 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
...
@@ -126,17 +132,27 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
func
(
o
PauseConfig
)
RunPause
()
error
{
func
(
o
PauseConfig
)
RunPause
()
error
{
allErrs
:=
[]
error
{}
allErrs
:=
[]
error
{}
for
_
,
info
:=
range
o
.
Infos
{
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
Infos
,
o
.
Encoder
,
o
.
Pauser
)
{
i
sAlreadyPaused
,
err
:=
o
.
PauseObject
(
info
.
Object
)
i
nfo
:=
patch
.
Info
if
e
rr
!=
nil
{
if
patch
.
E
rr
!=
nil
{
allErrs
=
append
(
allErrs
,
cmdutil
.
AddSourceToErr
(
"pausing"
,
info
.
Source
,
e
rr
))
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"error: %s %q %v"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
patch
.
E
rr
))
continue
continue
}
}
if
isAlreadyPaused
{
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"already paused"
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"already paused"
)
continue
continue
}
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
.
Patch
)
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"failed to patch: %v"
,
err
))
continue
}
info
.
Refresh
(
obj
,
true
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"paused"
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"paused"
)
}
}
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
}
pkg/kubectl/cmd/rollout/rollout_resume.go
View file @
0faa27e6
...
@@ -17,12 +17,15 @@ limitations under the License.
...
@@ -17,12 +17,15 @@ limitations under the License.
package
rollout
package
rollout
import
(
import
(
"fmt"
"io"
"io"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
...
@@ -35,9 +38,10 @@ import (
...
@@ -35,9 +38,10 @@ import (
type
ResumeConfig
struct
{
type
ResumeConfig
struct
{
resource
.
FilenameOptions
resource
.
FilenameOptions
Resume
Object
func
(
object
runtime
.
Object
)
(
bool
,
error
)
Resume
r
func
(
object
*
resource
.
Info
)
(
bool
,
error
)
Mapper
meta
.
RESTMapper
Mapper
meta
.
RESTMapper
Typer
runtime
.
ObjectTyper
Typer
runtime
.
ObjectTyper
Encoder
runtime
.
Encoder
Infos
[]
*
resource
.
Info
Infos
[]
*
resource
.
Info
Out
io
.
Writer
Out
io
.
Writer
...
@@ -94,7 +98,9 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
...
@@ -94,7 +98,9 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
}
}
o
.
Mapper
,
o
.
Typer
=
f
.
Object
()
o
.
Mapper
,
o
.
Typer
=
f
.
Object
()
o
.
ResumeObject
=
f
.
ResumeObject
o
.
Encoder
=
f
.
JSONEncoder
()
o
.
Resumer
=
f
.
Resumer
o
.
Out
=
out
o
.
Out
=
out
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
cmdNamespace
,
enforceNamespace
,
err
:=
f
.
DefaultNamespace
()
...
@@ -130,17 +136,28 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
...
@@ -130,17 +136,28 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
func
(
o
ResumeConfig
)
RunResume
()
error
{
func
(
o
ResumeConfig
)
RunResume
()
error
{
allErrs
:=
[]
error
{}
allErrs
:=
[]
error
{}
for
_
,
info
:=
range
o
.
Infos
{
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
Infos
,
o
.
Encoder
,
o
.
Resumer
)
{
isAlreadyResumed
,
err
:=
o
.
ResumeObject
(
info
.
Object
)
info
:=
patch
.
Info
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
cmdutil
.
AddSourceToErr
(
"resuming"
,
info
.
Source
,
err
))
if
patch
.
Err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"error: %s %q %v"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
patch
.
Err
))
continue
continue
}
}
if
isAlreadyResumed
{
if
string
(
patch
.
Patch
)
==
"{}"
||
len
(
patch
.
Patch
)
==
0
{
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"already resumed"
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"already resumed"
)
continue
continue
}
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
.
Patch
)
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"failed to patch: %v"
,
err
))
continue
}
info
.
Refresh
(
obj
,
true
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"resumed"
)
cmdutil
.
PrintSuccess
(
o
.
Mapper
,
false
,
o
.
Out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"resumed"
)
}
}
return
utilerrors
.
NewAggregate
(
allErrs
)
return
utilerrors
.
NewAggregate
(
allErrs
)
}
}
pkg/kubectl/cmd/set/helper.go
View file @
0faa27e6
...
@@ -125,13 +125,19 @@ func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn
...
@@ -125,13 +125,19 @@ func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn
for
_
,
info
:=
range
infos
{
for
_
,
info
:=
range
infos
{
patch
:=
&
Patch
{
Info
:
info
}
patch
:=
&
Patch
{
Info
:
info
}
patch
.
Before
,
patch
.
Err
=
runtime
.
Encode
(
encoder
,
info
.
Object
)
patch
.
Before
,
patch
.
Err
=
runtime
.
Encode
(
encoder
,
info
.
Object
)
if
patch
.
Err
!=
nil
{
ok
,
err
:=
mutateFn
(
info
)
patches
=
append
(
patches
,
patch
)
if
!
ok
{
continue
continue
}
}
ok
,
err
:=
mutateFn
(
info
)
if
err
!=
nil
{
if
err
!=
nil
{
patch
.
Err
=
err
patch
.
Err
=
err
patches
=
append
(
patches
,
patch
)
continue
}
if
!
ok
{
continue
}
}
patches
=
append
(
patches
,
patch
)
patches
=
append
(
patches
,
patch
)
if
patch
.
Err
!=
nil
{
if
patch
.
Err
!=
nil
{
...
...
pkg/kubectl/cmd/testing/fake.go
View file @
0faa27e6
...
@@ -261,11 +261,11 @@ func (f *FakeFactory) LogsForObject(object, options runtime.Object) (*restclient
...
@@ -261,11 +261,11 @@ func (f *FakeFactory) LogsForObject(object, options runtime.Object) (*restclient
return
nil
,
nil
return
nil
,
nil
}
}
func
(
f
*
FakeFactory
)
Pause
Object
(
runtime
.
Object
)
(
bool
,
error
)
{
func
(
f
*
FakeFactory
)
Pause
r
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
return
false
,
nil
return
false
,
nil
}
}
func
(
f
*
FakeFactory
)
Resume
Object
(
runtime
.
Object
)
(
bool
,
error
)
{
func
(
f
*
FakeFactory
)
Resume
r
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
return
false
,
nil
return
false
,
nil
}
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
0faa27e6
...
@@ -129,10 +129,10 @@ type Factory interface {
...
@@ -129,10 +129,10 @@ type Factory interface {
LabelsForObject
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
LabelsForObject
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
// LogsForObject returns a request for the logs associated with the provided object
// LogsForObject returns a request for the logs associated with the provided object
LogsForObject
(
object
,
options
runtime
.
Object
)
(
*
restclient
.
Request
,
error
)
LogsForObject
(
object
,
options
runtime
.
Object
)
(
*
restclient
.
Request
,
error
)
// Pause
Object marks the provided object
as paused ie. it will not be reconciled by its controller.
// Pause
r marks the object in the info
as paused ie. it will not be reconciled by its controller.
Pause
Object
(
object
runtime
.
Object
)
(
bool
,
error
)
Pause
r
(
info
*
resource
.
Info
)
(
bool
,
error
)
// Resume
Object resumes a paused object
ie. it will be reconciled by its controller.
// Resume
r resumes a paused object inside the info
ie. it will be reconciled by its controller.
Resume
Object
(
object
runtime
.
Object
)
(
bool
,
error
)
Resume
r
(
info
*
resource
.
Info
)
(
bool
,
error
)
// Returns a schema that can validate objects stored on disk.
// Returns a schema that can validate objects stored on disk.
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
Validator
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
// SwaggerSchema returns the schema declaration for the provided group version kind.
// SwaggerSchema returns the schema declaration for the provided group version kind.
...
@@ -644,49 +644,29 @@ func (f *factory) LogsForObject(object, options runtime.Object) (*restclient.Req
...
@@ -644,49 +644,29 @@ func (f *factory) LogsForObject(object, options runtime.Object) (*restclient.Req
}
}
}
}
func
(
f
*
factory
)
PauseObject
(
object
runtime
.
Object
)
(
bool
,
error
)
{
func
(
f
*
factory
)
Pauser
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
clientset
,
err
:=
f
.
clients
.
ClientSetForVersion
(
nil
)
switch
obj
:=
info
.
Object
.
(
type
)
{
if
err
!=
nil
{
return
false
,
err
}
switch
t
:=
object
.
(
type
)
{
case
*
extensions
.
Deployment
:
case
*
extensions
.
Deployment
:
if
t
.
Spec
.
Paused
{
if
obj
.
Spec
.
Paused
{
return
true
,
nil
return
true
,
errors
.
New
(
"is already paused"
)
}
}
t
.
Spec
.
Paused
=
true
obj
.
Spec
.
Paused
=
true
_
,
err
:=
clientset
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
true
,
nil
return
false
,
err
default
:
default
:
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
return
false
,
fmt
.
Errorf
(
"pausing is not supported"
)
if
err
!=
nil
{
return
false
,
err
}
return
false
,
fmt
.
Errorf
(
"cannot pause %v"
,
gvks
[
0
])
}
}
}
}
func
(
f
*
factory
)
ResumeObject
(
object
runtime
.
Object
)
(
bool
,
error
)
{
func
(
f
*
factory
)
Resumer
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
clientset
,
err
:=
f
.
clients
.
ClientSetForVersion
(
nil
)
switch
obj
:=
info
.
Object
.
(
type
)
{
if
err
!=
nil
{
return
false
,
err
}
switch
t
:=
object
.
(
type
)
{
case
*
extensions
.
Deployment
:
case
*
extensions
.
Deployment
:
if
!
t
.
Spec
.
Paused
{
if
!
obj
.
Spec
.
Paused
{
return
true
,
nil
return
true
,
errors
.
New
(
"is not paused"
)
}
}
t
.
Spec
.
Paused
=
false
obj
.
Spec
.
Paused
=
false
_
,
err
:=
clientset
.
Extensions
()
.
Deployments
(
t
.
Namespace
)
.
Update
(
t
)
return
true
,
nil
return
false
,
err
default
:
default
:
gvks
,
_
,
err
:=
api
.
Scheme
.
ObjectKinds
(
object
)
return
false
,
fmt
.
Errorf
(
"resuming is not supported"
)
if
err
!=
nil
{
return
false
,
err
}
return
false
,
fmt
.
Errorf
(
"cannot resume %v"
,
gvks
[
0
])
}
}
}
}
...
...
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