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
5ff923c7
Commit
5ff923c7
authored
Apr 27, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make dynamic client slightly easier to use
parent
03c5f298
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
28 additions
and
21 deletions
+28
-21
namespaced_resources_deleter.go
...roller/namespace/deletion/namespaced_resources_deleter.go
+3
-3
registration_test.go
...xtensions-apiserver/test/integration/registration_test.go
+2
-2
resources.go
...nsions-apiserver/test/integration/testserver/resources.go
+2
-2
simple.go
staging/src/k8s.io/client-go/dynamic/simple.go
+13
-6
aggregator.go
test/e2e/apimachinery/aggregator.go
+1
-1
crd_watch.go
test/e2e/apimachinery/crd_watch.go
+2
-2
garbage_collector.go
test/e2e/apimachinery/garbage_collector.go
+1
-1
crd_util.go
test/e2e/framework/crd_util.go
+1
-1
util.go
test/e2e/framework/util.go
+2
-2
garbage_collector_test.go
test/integration/garbagecollector/garbage_collector_test.go
+1
-1
No files found.
pkg/controller/namespace/deletion/namespaced_resources_deleter.go
View file @
5ff923c7
...
...
@@ -342,7 +342,7 @@ func (d *namespacedResourcesDeleter) deleteCollection(gvr schema.GroupVersionRes
// namespace itself.
background
:=
metav1
.
DeletePropagationBackground
opts
:=
&
metav1
.
DeleteOptions
{
PropagationPolicy
:
&
background
}
err
:=
d
.
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
.
DeleteCollection
(
opts
,
metav1
.
ListOptions
{})
err
:=
d
.
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
.
DeleteCollection
(
opts
,
metav1
.
ListOptions
{})
if
err
==
nil
{
return
true
,
nil
...
...
@@ -378,7 +378,7 @@ func (d *namespacedResourcesDeleter) listCollection(gvr schema.GroupVersionResou
return
nil
,
false
,
nil
}
unstructuredList
,
err
:=
d
.
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
.
List
(
metav1
.
ListOptions
{
IncludeUninitialized
:
true
})
unstructuredList
,
err
:=
d
.
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
.
List
(
metav1
.
ListOptions
{
IncludeUninitialized
:
true
})
if
err
==
nil
{
return
unstructuredList
,
true
,
nil
}
...
...
@@ -412,7 +412,7 @@ func (d *namespacedResourcesDeleter) deleteEachItem(gvr schema.GroupVersionResou
for
_
,
item
:=
range
unstructuredList
.
Items
{
background
:=
metav1
.
DeletePropagationBackground
opts
:=
&
metav1
.
DeleteOptions
{
PropagationPolicy
:
&
background
}
if
err
=
d
.
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
.
Delete
(
item
.
GetName
(),
opts
);
err
!=
nil
&&
!
errors
.
IsNotFound
(
err
)
&&
!
errors
.
IsMethodNotSupported
(
err
)
{
if
err
=
d
.
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
.
Delete
(
item
.
GetName
(),
opts
);
err
!=
nil
&&
!
errors
.
IsNotFound
(
err
)
&&
!
errors
.
IsMethodNotSupported
(
err
)
{
return
err
}
}
...
...
staging/src/k8s.io/apiextensions-apiserver/test/integration/registration_test.go
View file @
5ff923c7
...
...
@@ -72,9 +72,9 @@ func NewNamespacedCustomResourceClient(ns string, client dynamic.DynamicInterfac
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
crd
.
Spec
.
Version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
return
client
.
NamespacedResource
(
gvr
,
ns
)
return
client
.
Resource
(
gvr
)
.
Namespace
(
ns
)
}
return
client
.
Cluster
Resource
(
gvr
)
return
client
.
Resource
(
gvr
)
}
func
NewNamespacedCustomResourceStatusClient
(
ns
string
,
client
dynamic
.
DynamicInterface
,
crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
)
dynamic
.
DynamicResourceInterface
{
...
...
staging/src/k8s.io/apiextensions-apiserver/test/integration/testserver/resources.go
View file @
5ff923c7
...
...
@@ -217,9 +217,9 @@ func checkForWatchCachePrimed(crd *apiextensionsv1beta1.CustomResourceDefinition
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
crd
.
Spec
.
Version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
var
resourceClient
dynamic
.
DynamicResourceInterface
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
resourceClient
=
dynamicClientSet
.
NamespacedResource
(
gvr
,
ns
)
resourceClient
=
dynamicClientSet
.
Resource
(
gvr
)
.
Namespace
(
ns
)
}
else
{
resourceClient
=
dynamicClientSet
.
Cluster
Resource
(
gvr
)
resourceClient
=
dynamicClientSet
.
Resource
(
gvr
)
}
initialList
,
err
:=
resourceClient
.
List
(
metav1
.
ListOptions
{})
...
...
staging/src/k8s.io/client-go/dynamic/simple.go
View file @
5ff923c7
...
...
@@ -32,8 +32,7 @@ import (
)
type
DynamicInterface
interface
{
ClusterResource
(
resource
schema
.
GroupVersionResource
)
DynamicResourceInterface
NamespacedResource
(
resource
schema
.
GroupVersionResource
,
namespace
string
)
DynamicResourceInterface
Resource
(
resource
schema
.
GroupVersionResource
)
NamespaceableDynamicResourceInterface
// Deprecated, this isn't how we want to do it
ClusterSubresource
(
resource
schema
.
GroupVersionResource
,
subresource
string
)
DynamicResourceInterface
...
...
@@ -53,6 +52,11 @@ type DynamicResourceInterface interface {
Patch
(
name
string
,
pt
types
.
PatchType
,
data
[]
byte
,
subresources
...
string
)
(
*
unstructured
.
Unstructured
,
error
)
}
type
NamespaceableDynamicResourceInterface
interface
{
Namespace
(
string
)
DynamicResourceInterface
DynamicResourceInterface
}
type
dynamicClient
struct
{
client
*
rest
.
RESTClient
}
...
...
@@ -86,12 +90,9 @@ type dynamicResourceClient struct {
subresource
string
}
func
(
c
*
dynamicClient
)
ClusterResource
(
resource
schema
.
GroupVersionResource
)
DynamicResourceInterface
{
func
(
c
*
dynamicClient
)
Resource
(
resource
schema
.
GroupVersionResource
)
Namespaceable
DynamicResourceInterface
{
return
&
dynamicResourceClient
{
client
:
c
,
resource
:
resource
}
}
func
(
c
*
dynamicClient
)
NamespacedResource
(
resource
schema
.
GroupVersionResource
,
namespace
string
)
DynamicResourceInterface
{
return
&
dynamicResourceClient
{
client
:
c
,
resource
:
resource
,
namespace
:
namespace
}
}
func
(
c
*
dynamicClient
)
ClusterSubresource
(
resource
schema
.
GroupVersionResource
,
subresource
string
)
DynamicResourceInterface
{
return
&
dynamicResourceClient
{
client
:
c
,
resource
:
resource
,
subresource
:
subresource
}
...
...
@@ -100,6 +101,12 @@ func (c *dynamicClient) NamespacedSubresource(resource schema.GroupVersionResour
return
&
dynamicResourceClient
{
client
:
c
,
resource
:
resource
,
namespace
:
namespace
,
subresource
:
subresource
}
}
func
(
c
*
dynamicResourceClient
)
Namespace
(
ns
string
)
DynamicResourceInterface
{
ret
:=
*
c
ret
.
namespace
=
ns
return
&
ret
}
func
(
c
*
dynamicResourceClient
)
Create
(
obj
*
unstructured
.
Unstructured
)
(
*
unstructured
.
Unstructured
,
error
)
{
if
len
(
c
.
subresource
)
>
0
{
return
nil
,
fmt
.
Errorf
(
"create not supported for subresources"
)
...
...
test/e2e/apimachinery/aggregator.go
View file @
5ff923c7
...
...
@@ -391,7 +391,7 @@ func TestSampleAPIServer(f *framework.Framework, image string) {
if
!
ok
{
framework
.
Failf
(
"could not find group version resource for dynamic client and wardle/flunders."
)
}
dynamicClient
:=
f
.
DynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
dynamicClient
:=
f
.
DynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
// kubectl create -f flunders-1.yaml
// Request Body: {"apiVersion":"wardle.k8s.io/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
...
...
test/e2e/apimachinery/crd_watch.go
View file @
5ff923c7
...
...
@@ -158,9 +158,9 @@ func newNamespacedCustomResourceClient(ns string, client dynamic.DynamicInterfac
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
crd
.
Spec
.
Version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
if
crd
.
Spec
.
Scope
!=
apiextensionsv1beta1
.
ClusterScoped
{
return
client
.
NamespacedResource
(
gvr
,
ns
)
return
client
.
Resource
(
gvr
)
.
Namespace
(
ns
)
}
else
{
return
client
.
Cluster
Resource
(
gvr
)
return
client
.
Resource
(
gvr
)
}
}
test/e2e/apimachinery/garbage_collector.go
View file @
5ff923c7
...
...
@@ -924,7 +924,7 @@ var _ = SIGDescribe("Garbage collector", func() {
// Get a client for the custom resource.
gvr
:=
schema
.
GroupVersionResource
{
Group
:
definition
.
Spec
.
Group
,
Version
:
definition
.
Spec
.
Version
,
Resource
:
definition
.
Spec
.
Names
.
Plural
}
resourceClient
:=
f
.
DynamicClient
.
Cluster
Resource
(
gvr
)
resourceClient
:=
f
.
DynamicClient
.
Resource
(
gvr
)
apiVersion
:=
definition
.
Spec
.
Group
+
"/"
+
definition
.
Spec
.
Version
...
...
test/e2e/framework/crd_util.go
View file @
5ff923c7
...
...
@@ -83,7 +83,7 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
}
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
crd
.
Spec
.
Version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
resourceClient
:=
dynamicClient
.
NamespacedResource
(
gvr
,
f
.
Namespace
.
Name
)
resourceClient
:=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
f
.
Namespace
.
Name
)
testcrd
.
ApiExtensionClient
=
apiExtensionClient
testcrd
.
Crd
=
crd
...
...
test/e2e/framework/util.go
View file @
5ff923c7
...
...
@@ -508,7 +508,7 @@ func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersio
}
func
SkipIfMissingResource
(
dynamicClient
dynamic
.
DynamicInterface
,
gvr
schema
.
GroupVersionResource
,
namespace
string
)
{
resourceClient
:=
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
resourceClient
:=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
_
,
err
:=
resourceClient
.
List
(
metav1
.
ListOptions
{})
if
err
!=
nil
{
// not all resources support list, so we ignore those
...
...
@@ -1258,7 +1258,7 @@ func hasRemainingContent(c clientset.Interface, dynamicClient dynamic.DynamicInt
// dump how many of resource type is on the server in a log.
for
gvr
:=
range
groupVersionResources
{
// get a client for this group version...
dynamicClient
:=
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
dynamicClient
:=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
if
err
!=
nil
{
// not all resource types support list, so some errors here are normal depending on the resource type.
Logf
(
"namespace: %s, unable to get client - gvr: %v, error: %v"
,
namespace
,
gvr
,
err
)
...
...
test/integration/garbagecollector/garbage_collector_test.go
View file @
5ff923c7
...
...
@@ -183,7 +183,7 @@ func createRandomCustomResourceDefinition(
// Get a client for the custom resource.
gvr
:=
schema
.
GroupVersionResource
{
Group
:
definition
.
Spec
.
Group
,
Version
:
definition
.
Spec
.
Version
,
Resource
:
definition
.
Spec
.
Names
.
Plural
}
resourceClient
:=
dynamicClient
.
NamespacedResource
(
gvr
,
namespace
)
resourceClient
:=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
namespace
)
return
definition
,
resourceClient
}
...
...
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