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
c12d8a56
Commit
c12d8a56
authored
Jan 11, 2019
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find current resourceVersion for waiting for deletion/conditions
parent
3d9c6eb9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
8 deletions
+26
-8
BUILD
pkg/kubectl/cmd/wait/BUILD
+1
-0
wait.go
pkg/kubectl/cmd/wait/wait.go
+24
-8
wait_test.go
pkg/kubectl/cmd/wait/wait_test.go
+0
-0
simple.go
staging/src/k8s.io/client-go/dynamic/fake/simple.go
+1
-0
No files found.
pkg/kubectl/cmd/wait/BUILD
View file @
c12d8a56
...
...
@@ -11,6 +11,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
...
...
pkg/kubectl/cmd/wait/wait.go
View file @
c12d8a56
...
...
@@ -29,6 +29,7 @@ import (
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
...
...
@@ -255,7 +256,11 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
if
len
(
info
.
Name
)
==
0
{
return
info
.
Object
,
false
,
fmt
.
Errorf
(
"resource name must be provided"
)
}
gottenObj
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
Get
(
info
.
Name
,
metav1
.
GetOptions
{})
nameSelector
:=
fields
.
OneTermEqualSelector
(
"metadata.name"
,
info
.
Name
)
.
String
()
// List with a name field selector to get the current resourceVersion to watch from (not the object's resourceVersion)
gottenObjList
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
List
(
metav1
.
ListOptions
{
FieldSelector
:
nameSelector
})
if
apierrors
.
IsNotFound
(
err
)
{
return
info
.
Object
,
true
,
nil
}
...
...
@@ -263,6 +268,10 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
// TODO this could do something slightly fancier if we wish
return
info
.
Object
,
false
,
err
}
if
len
(
gottenObjList
.
Items
)
!=
1
{
return
info
.
Object
,
true
,
nil
}
gottenObj
:=
&
gottenObjList
.
Items
[
0
]
resourceLocation
:=
ResourceLocation
{
GroupResource
:
info
.
Mapping
.
Resource
.
GroupResource
(),
Namespace
:
gottenObj
.
GetNamespace
(),
...
...
@@ -275,8 +284,8 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
}
watchOptions
:=
metav1
.
ListOptions
{}
watchOptions
.
FieldSelector
=
"metadata.name="
+
info
.
Name
watchOptions
.
ResourceVersion
=
gottenObj
.
GetResourceVersion
()
watchOptions
.
FieldSelector
=
nameSelector
watchOptions
.
ResourceVersion
=
gottenObj
List
.
GetResourceVersion
()
objWatch
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
Watch
(
watchOptions
)
if
err
!=
nil
{
return
gottenObj
,
false
,
err
...
...
@@ -343,14 +352,21 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
if
len
(
info
.
Name
)
==
0
{
return
info
.
Object
,
false
,
fmt
.
Errorf
(
"resource name must be provided"
)
}
nameSelector
:=
fields
.
OneTermEqualSelector
(
"metadata.name"
,
info
.
Name
)
.
String
()
var
gottenObj
*
unstructured
.
Unstructured
// List with a name field selector to get the current resourceVersion to watch from (not the object's resourceVersion)
gottenObjList
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
List
(
metav1
.
ListOptions
{
FieldSelector
:
nameSelector
})
resourceVersion
:=
""
gottenObj
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
Get
(
info
.
Name
,
metav1
.
GetOptions
{})
switch
{
case
apierrors
.
IsNotFound
(
err
)
:
resourceVersion
=
"0"
case
err
!=
nil
:
return
info
.
Object
,
false
,
err
case
len
(
gottenObjList
.
Items
)
!=
1
:
resourceVersion
=
gottenObjList
.
GetResourceVersion
()
default
:
gottenObj
=
&
gottenObjList
.
Items
[
0
]
conditionMet
,
err
:=
w
.
checkCondition
(
gottenObj
)
if
conditionMet
{
return
gottenObj
,
true
,
nil
...
...
@@ -358,11 +374,11 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
if
err
!=
nil
{
return
gottenObj
,
false
,
err
}
resourceVersion
=
gottenObj
.
GetResourceVersion
()
resourceVersion
=
gottenObj
List
.
GetResourceVersion
()
}
watchOptions
:=
metav1
.
ListOptions
{}
watchOptions
.
FieldSelector
=
"metadata.name="
+
info
.
Name
watchOptions
.
FieldSelector
=
nameSelector
watchOptions
.
ResourceVersion
=
resourceVersion
objWatch
,
err
:=
o
.
DynamicClient
.
Resource
(
info
.
Mapping
.
Resource
)
.
Namespace
(
info
.
Namespace
)
.
Watch
(
watchOptions
)
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/wait/wait_test.go
View file @
c12d8a56
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/client-go/dynamic/fake/simple.go
View file @
c12d8a56
...
...
@@ -303,6 +303,7 @@ func (c *dynamicResourceClient) List(opts metav1.ListOptions) (*unstructured.Uns
}
list
:=
&
unstructured
.
UnstructuredList
{}
list
.
SetResourceVersion
(
entireList
.
GetResourceVersion
())
for
i
:=
range
entireList
.
Items
{
item
:=
&
entireList
.
Items
[
i
]
metadata
,
err
:=
meta
.
Accessor
(
item
)
...
...
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