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
54243e19
Unverified
Commit
54243e19
authored
Nov 13, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69344 from zegl/improve-kubectl-apply-prune-output
Fix dry-run output in kubectl apply --prune
parents
cc4d38c7
37c253ab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
26 deletions
+50
-26
apply.go
pkg/kubectl/cmd/apply/apply.go
+12
-12
apply_test.go
pkg/kubectl/cmd/apply/apply_test.go
+36
-12
cm.yaml
test/fixtures/pkg/kubectl/cmd/apply/cm.yaml
+2
-2
No files found.
pkg/kubectl/cmd/apply/apply.go
View file @
54243e19
...
@@ -389,13 +389,14 @@ func (o *ApplyOptions) Run() error {
...
@@ -389,13 +389,14 @@ func (o *ApplyOptions) Run() error {
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
}
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
metadata
,
err
:=
meta
.
Accessor
(
info
.
Object
)
if
err
!=
nil
{
return
err
}
visitedUids
.
Insert
(
string
(
metadata
.
GetUID
()))
}
}
metadata
,
err
:=
meta
.
Accessor
(
info
.
Object
)
if
err
!=
nil
{
return
err
}
visitedUids
.
Insert
(
string
(
metadata
.
GetUID
()))
count
++
count
++
if
printObject
{
if
printObject
{
...
@@ -410,12 +411,13 @@ func (o *ApplyOptions) Run() error {
...
@@ -410,12 +411,13 @@ func (o *ApplyOptions) Run() error {
return
printer
.
PrintObj
(
info
.
Object
,
o
.
Out
)
return
printer
.
PrintObj
(
info
.
Object
,
o
.
Out
)
}
}
if
!
o
.
DryRun
{
metadata
,
err
:=
meta
.
Accessor
(
info
.
Object
)
metadata
,
err
:=
meta
.
Accessor
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
visitedUids
.
Insert
(
string
(
metadata
.
GetUID
()))
if
!
o
.
DryRun
{
annotationMap
:=
metadata
.
GetAnnotations
()
annotationMap
:=
metadata
.
GetAnnotations
()
if
_
,
ok
:=
annotationMap
[
corev1
.
LastAppliedConfigAnnotation
];
!
ok
{
if
_
,
ok
:=
annotationMap
[
corev1
.
LastAppliedConfigAnnotation
];
!
ok
{
fmt
.
Fprintf
(
o
.
ErrOut
,
warningNoLastAppliedConfigAnnotation
,
o
.
cmdBaseName
)
fmt
.
Fprintf
(
o
.
ErrOut
,
warningNoLastAppliedConfigAnnotation
,
o
.
cmdBaseName
)
...
@@ -443,8 +445,6 @@ func (o *ApplyOptions) Run() error {
...
@@ -443,8 +445,6 @@ func (o *ApplyOptions) Run() error {
info
.
Refresh
(
patchedObject
,
true
)
info
.
Refresh
(
patchedObject
,
true
)
visitedUids
.
Insert
(
string
(
metadata
.
GetUID
()))
if
string
(
patchBytes
)
==
"{}"
&&
!
printObject
{
if
string
(
patchBytes
)
==
"{}"
&&
!
printObject
{
count
++
count
++
...
...
pkg/kubectl/cmd/apply/apply_test.go
View file @
54243e19
...
@@ -103,19 +103,24 @@ const (
...
@@ -103,19 +103,24 @@ const (
filenameWidgetServerside
=
"../../../../test/fixtures/pkg/kubectl/cmd/apply/widget-serverside.yaml"
filenameWidgetServerside
=
"../../../../test/fixtures/pkg/kubectl/cmd/apply/widget-serverside.yaml"
)
)
func
readConfigMapList
(
t
*
testing
.
T
,
filename
string
)
[]
byte
{
func
readConfigMapList
(
t
*
testing
.
T
,
filename
string
)
[]
[]
byte
{
data
:=
readBytesFromFile
(
t
,
filename
)
data
:=
readBytesFromFile
(
t
,
filename
)
cmList
:=
corev1
.
ConfigMapList
{}
cmList
:=
corev1
.
ConfigMapList
{}
if
err
:=
runtime
.
DecodeInto
(
codec
,
data
,
&
cmList
);
err
!=
nil
{
if
err
:=
runtime
.
DecodeInto
(
codec
,
data
,
&
cmList
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
cmListBytes
,
err
:=
runtime
.
Encode
(
codec
,
&
cmList
)
var
listCmBytes
[][]
byte
if
err
!=
nil
{
t
.
Fatal
(
err
)
for
_
,
cm
:=
range
cmList
.
Items
{
cmBytes
,
err
:=
runtime
.
Encode
(
codec
,
&
cm
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
listCmBytes
=
append
(
listCmBytes
,
cmBytes
)
}
}
return
cmList
Bytes
return
listCm
Bytes
}
}
func
readBytesFromFile
(
t
*
testing
.
T
,
filename
string
)
[]
byte
{
func
readBytesFromFile
(
t
*
testing
.
T
,
filename
string
)
[]
byte
{
...
@@ -270,7 +275,7 @@ func walkMapPath(t *testing.T, start map[string]interface{}, path []string) map[
...
@@ -270,7 +275,7 @@ func walkMapPath(t *testing.T, start map[string]interface{}, path []string) map[
func
TestRunApplyPrintsValidObjectList
(
t
*
testing
.
T
)
{
func
TestRunApplyPrintsValidObjectList
(
t
*
testing
.
T
)
{
cmdtesting
.
InitTestErrorHandler
(
t
)
cmdtesting
.
InitTestErrorHandler
(
t
)
c
mBytes
:=
readConfigMapList
(
t
,
filenameCM
)
c
onfigMapList
:=
readConfigMapList
(
t
,
filenameCM
)
pathCM
:=
"/namespaces/test/configmaps"
pathCM
:=
"/namespaces/test/configmaps"
tf
:=
cmdtesting
.
NewTestFactory
()
.
WithNamespace
(
"test"
)
tf
:=
cmdtesting
.
NewTestFactory
()
.
WithNamespace
(
"test"
)
...
@@ -280,12 +285,21 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
...
@@ -280,12 +285,21 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
NegotiatedSerializer
:
resource
.
UnstructuredPlusDefaultContentConfig
()
.
NegotiatedSerializer
,
NegotiatedSerializer
:
resource
.
UnstructuredPlusDefaultContentConfig
()
.
NegotiatedSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
strings
.
HasPrefix
(
p
,
pathCM
)
&&
m
!=
"GET"
:
case
strings
.
HasPrefix
(
p
,
pathCM
)
&&
m
==
"GET"
:
pod
:=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
cmBytes
))
fallthrough
return
&
http
.
Response
{
StatusCode
:
200
,
Header
:
cmdtesting
.
DefaultHeader
(),
Body
:
pod
},
nil
case
strings
.
HasPrefix
(
p
,
pathCM
)
&&
m
==
"PATCH"
:
case
strings
.
HasPrefix
(
p
,
pathCM
)
&&
m
!=
"PATCH"
:
var
body
io
.
ReadCloser
pod
:=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
cmBytes
))
return
&
http
.
Response
{
StatusCode
:
200
,
Header
:
cmdtesting
.
DefaultHeader
(),
Body
:
pod
},
nil
switch
p
{
case
pathCM
+
"/test0"
:
body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
configMapList
[
0
]))
case
pathCM
+
"/test1"
:
body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
configMapList
[
1
]))
default
:
t
.
Errorf
(
"unexpected request to %s"
,
p
)
}
return
&
http
.
Response
{
StatusCode
:
200
,
Header
:
cmdtesting
.
DefaultHeader
(),
Body
:
body
},
nil
default
:
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
return
nil
,
nil
...
@@ -306,6 +320,16 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
...
@@ -306,6 +320,16 @@ func TestRunApplyPrintsValidObjectList(t *testing.T) {
if
err
:=
runtime
.
DecodeInto
(
codec
,
buf
.
Bytes
(),
&
cmList
);
err
!=
nil
{
if
err
:=
runtime
.
DecodeInto
(
codec
,
buf
.
Bytes
(),
&
cmList
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
len
(
cmList
.
Items
)
!=
2
{
t
.
Fatalf
(
"Expected 2 items in the result; got %d"
,
len
(
cmList
.
Items
))
}
if
!
strings
.
Contains
(
string
(
cmList
.
Items
[
0
]
.
Raw
),
"key1"
)
{
t
.
Fatalf
(
"Did not get first ConfigMap at the first position"
)
}
if
!
strings
.
Contains
(
string
(
cmList
.
Items
[
1
]
.
Raw
),
"key2"
)
{
t
.
Fatalf
(
"Did not get second ConfigMap at the second position"
)
}
}
}
func
TestRunApplyViewLastApplied
(
t
*
testing
.
T
)
{
func
TestRunApplyViewLastApplied
(
t
*
testing
.
T
)
{
...
...
test/fixtures/pkg/kubectl/cmd/apply/cm.yaml
View file @
54243e19
...
@@ -3,13 +3,13 @@ items:
...
@@ -3,13 +3,13 @@ items:
-
kind
:
ConfigMap
-
kind
:
ConfigMap
apiVersion
:
v1
apiVersion
:
v1
metadata
:
metadata
:
name
:
test
name
:
test
0
data
:
data
:
key1
:
apple
key1
:
apple
-
kind
:
ConfigMap
-
kind
:
ConfigMap
apiVersion
:
v1
apiVersion
:
v1
metadata
:
metadata
:
name
:
test
2
name
:
test
1
data
:
data
:
key2
:
apple
key2
:
apple
kind
:
ConfigMapList
kind
:
ConfigMapList
...
...
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