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
335d4216
Commit
335d4216
authored
Jun 20, 2018
by
Mehdy Bohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consume watch event for all versions of CRD
parent
152b0c12
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
30 deletions
+47
-30
resources.go
...nsions-apiserver/test/integration/testserver/resources.go
+47
-30
No files found.
staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go
View file @
335d4216
...
@@ -258,35 +258,41 @@ func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceD
...
@@ -258,35 +258,41 @@ func CreateNewCustomResourceDefinition(crd *apiextensionsv1beta1.CustomResourceD
// For this test, we'll actually cycle, "list/watch/create/delete" until we get an RV from list that observes the create and not an error.
// For this test, we'll actually cycle, "list/watch/create/delete" until we get an RV from list that observes the create and not an error.
// This way all the tests that are checking for watches don't have to worry about RV too old problems because crazy things *could* happen
// This way all the tests that are checking for watches don't have to worry about RV too old problems because crazy things *could* happen
// before like the created RV could be too old to watch.
// before like the created RV could be too old to watch.
for
_
,
version
:=
range
servedVersions
(
crd
)
{
err
=
wait
.
PollImmediate
(
500
*
time
.
Millisecond
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
err
:=
wait
.
PollImmediate
(
500
*
time
.
Millisecond
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
return
isWatchCachePrimed
(
crd
,
dynamicClientSet
)
return
isWatchCachePrimed
(
crd
,
dynamicClientSet
,
version
)
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
return
crd
,
nil
return
crd
,
nil
}
}
func
resourceClientForVersion
(
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
,
dynamicClientSet
dynamic
.
Interface
,
namespace
,
version
string
)
dynamic
.
ResourceInterface
{
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
return
dynamicClientSet
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
}
else
{
return
dynamicClientSet
.
Resource
(
gvr
)
}
}
// isWatchCachePrimed returns true if the watch is primed for an specified version of CRD watch
// isWatchCachePrimed returns true if the watch is primed for an specified version of CRD watch
func
isWatchCachePrimed
(
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
,
dynamicClientSet
dynamic
.
Interface
,
version
string
)
(
bool
,
error
)
{
func
isWatchCachePrimed
(
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
,
dynamicClientSet
dynamic
.
Interface
)
(
bool
,
error
)
{
ns
:=
""
ns
:=
""
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
ns
=
"aval"
ns
=
"aval"
}
}
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
versions
:=
servedVersions
(
crd
)
var
resourceClient
dynamic
.
ResourceInterface
if
len
(
versions
)
==
0
{
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
return
true
,
nil
resourceClient
=
dynamicClientSet
.
Resource
(
gvr
)
.
Namespace
(
ns
)
}
else
{
resourceClient
=
dynamicClientSet
.
Resource
(
gvr
)
}
}
resourceClient
:=
resourceClientForVersion
(
crd
,
dynamicClientSet
,
ns
,
versions
[
0
])
instanceName
:=
"setup-instance"
instanceName
:=
"setup-instance"
instance
:=
&
unstructured
.
Unstructured
{
instance
:=
&
unstructured
.
Unstructured
{
Object
:
map
[
string
]
interface
{}{
Object
:
map
[
string
]
interface
{}{
"apiVersion"
:
crd
.
Spec
.
Group
+
"/"
+
version
,
"apiVersion"
:
crd
.
Spec
.
Group
+
"/"
+
version
s
[
0
]
,
"kind"
:
crd
.
Spec
.
Names
.
Kind
,
"kind"
:
crd
.
Spec
.
Names
.
Kind
,
"metadata"
:
map
[
string
]
interface
{}{
"metadata"
:
map
[
string
]
interface
{}{
"namespace"
:
ns
,
"namespace"
:
ns
,
...
@@ -309,24 +315,35 @@ func isWatchCachePrimed(crd *apiextensionsv1beta1.CustomResourceDefinition, dyna
...
@@ -309,24 +315,35 @@ func isWatchCachePrimed(crd *apiextensionsv1beta1.CustomResourceDefinition, dyna
return
false
,
err
return
false
,
err
}
}
noxuWatch
,
err
:=
resourceClient
.
Watch
(
metav1
.
ListOptions
{
ResourceVersion
:
createdInstance
.
GetResourceVersion
()})
// Wait for all versions of watch cache to be primed and also make sure we consumed the DELETE event for all
if
err
!=
nil
{
// versions so that any new watch with ResourceVersion=0 does not get those events. This is source of some flaky tests.
return
false
,
err
// When a client creates a watch with resourceVersion=0, it will get an ADD event for any existing objects
}
// but because they specified resourceVersion=0, there is no starting point in the cache buffer to return existing events
defer
noxuWatch
.
Stop
()
// from, thus the server will return anything from current head of the cache to the end. By accessing the delete
// events for all versions here, we make sure that the head of the cache is passed those events and they will not being
select
{
// delivered to any future watch with resourceVersion=0.
case
watchEvent
:=
<-
noxuWatch
.
ResultChan
()
:
for
_
,
v
:=
range
versions
{
if
watch
.
Error
==
watchEvent
.
Type
{
noxuWatch
,
err
:=
resourceClientForVersion
(
crd
,
dynamicClientSet
,
ns
,
v
)
.
Watch
(
return
false
,
nil
metav1
.
ListOptions
{
ResourceVersion
:
createdInstance
.
GetResourceVersion
()})
if
err
!=
nil
{
return
false
,
err
}
}
if
watch
.
Deleted
!=
watchEvent
.
Type
{
defer
noxuWatch
.
Stop
()
return
false
,
fmt
.
Errorf
(
"expected DELETE, but got %#v"
,
watchEvent
)
select
{
case
watchEvent
:=
<-
noxuWatch
.
ResultChan
()
:
if
watch
.
Error
==
watchEvent
.
Type
{
return
false
,
nil
}
if
watch
.
Deleted
!=
watchEvent
.
Type
{
return
false
,
fmt
.
Errorf
(
"expected DELETE, but got %#v"
,
watchEvent
)
}
case
<-
time
.
After
(
5
*
time
.
Second
)
:
return
false
,
fmt
.
Errorf
(
"gave up waiting for watch event"
)
}
}
return
true
,
nil
case
<-
time
.
After
(
5
*
time
.
Second
)
:
return
false
,
fmt
.
Errorf
(
"gave up waiting for watch event"
)
}
}
return
true
,
nil
}
}
func
DeleteCustomResourceDefinition
(
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
,
apiExtensionsClient
clientset
.
Interface
)
error
{
func
DeleteCustomResourceDefinition
(
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
,
apiExtensionsClient
clientset
.
Interface
)
error
{
...
...
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