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
e3e1729c
Unverified
Commit
e3e1729c
authored
Apr 06, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make priority rest mapper handle partial discovery results
parent
d371be33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
15 deletions
+78
-15
priority.go
staging/src/k8s.io/apimachinery/pkg/api/meta/priority.go
+15
-15
priority_test.go
...ing/src/k8s.io/apimachinery/pkg/api/meta/priority_test.go
+63
-0
No files found.
staging/src/k8s.io/apimachinery/pkg/api/meta/priority.go
View file @
e3e1729c
...
@@ -54,12 +54,12 @@ func (m PriorityRESTMapper) String() string {
...
@@ -54,12 +54,12 @@ func (m PriorityRESTMapper) String() string {
// ResourceFor finds all resources, then passes them through the ResourcePriority patterns to find a single matching hit.
// ResourceFor finds all resources, then passes them through the ResourcePriority patterns to find a single matching hit.
func
(
m
PriorityRESTMapper
)
ResourceFor
(
partiallySpecifiedResource
schema
.
GroupVersionResource
)
(
schema
.
GroupVersionResource
,
error
)
{
func
(
m
PriorityRESTMapper
)
ResourceFor
(
partiallySpecifiedResource
schema
.
GroupVersionResource
)
(
schema
.
GroupVersionResource
,
error
)
{
originalGVRs
,
e
rr
:=
m
.
Delegate
.
ResourcesFor
(
partiallySpecifiedResource
)
originalGVRs
,
originalE
rr
:=
m
.
Delegate
.
ResourcesFor
(
partiallySpecifiedResource
)
if
err
!=
nil
{
if
originalErr
!=
nil
&&
len
(
originalGVRs
)
==
0
{
return
schema
.
GroupVersionResource
{},
e
rr
return
schema
.
GroupVersionResource
{},
originalE
rr
}
}
if
len
(
originalGVRs
)
==
1
{
if
len
(
originalGVRs
)
==
1
{
return
originalGVRs
[
0
],
nil
return
originalGVRs
[
0
],
originalErr
}
}
remainingGVRs
:=
append
([]
schema
.
GroupVersionResource
{},
originalGVRs
...
)
remainingGVRs
:=
append
([]
schema
.
GroupVersionResource
{},
originalGVRs
...
)
...
@@ -77,7 +77,7 @@ func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupV
...
@@ -77,7 +77,7 @@ func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupV
continue
continue
case
1
:
case
1
:
// one match, return
// one match, return
return
matchedGVRs
[
0
],
nil
return
matchedGVRs
[
0
],
originalErr
default
:
default
:
// more than one match, use the matched hits as the list moving to the next pattern.
// more than one match, use the matched hits as the list moving to the next pattern.
// this way you can have a series of selection criteria
// this way you can have a series of selection criteria
...
@@ -90,12 +90,12 @@ func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupV
...
@@ -90,12 +90,12 @@ func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupV
// KindFor finds all kinds, then passes them through the KindPriority patterns to find a single matching hit.
// KindFor finds all kinds, then passes them through the KindPriority patterns to find a single matching hit.
func
(
m
PriorityRESTMapper
)
KindFor
(
partiallySpecifiedResource
schema
.
GroupVersionResource
)
(
schema
.
GroupVersionKind
,
error
)
{
func
(
m
PriorityRESTMapper
)
KindFor
(
partiallySpecifiedResource
schema
.
GroupVersionResource
)
(
schema
.
GroupVersionKind
,
error
)
{
originalGVKs
,
e
rr
:=
m
.
Delegate
.
KindsFor
(
partiallySpecifiedResource
)
originalGVKs
,
originalE
rr
:=
m
.
Delegate
.
KindsFor
(
partiallySpecifiedResource
)
if
err
!=
nil
{
if
originalErr
!=
nil
&&
len
(
originalGVKs
)
==
0
{
return
schema
.
GroupVersionKind
{},
e
rr
return
schema
.
GroupVersionKind
{},
originalE
rr
}
}
if
len
(
originalGVKs
)
==
1
{
if
len
(
originalGVKs
)
==
1
{
return
originalGVKs
[
0
],
nil
return
originalGVKs
[
0
],
originalErr
}
}
remainingGVKs
:=
append
([]
schema
.
GroupVersionKind
{},
originalGVKs
...
)
remainingGVKs
:=
append
([]
schema
.
GroupVersionKind
{},
originalGVKs
...
)
...
@@ -113,7 +113,7 @@ func (m PriorityRESTMapper) KindFor(partiallySpecifiedResource schema.GroupVersi
...
@@ -113,7 +113,7 @@ func (m PriorityRESTMapper) KindFor(partiallySpecifiedResource schema.GroupVersi
continue
continue
case
1
:
case
1
:
// one match, return
// one match, return
return
matchedGVKs
[
0
],
nil
return
matchedGVKs
[
0
],
originalErr
default
:
default
:
// more than one match, use the matched hits as the list moving to the next pattern.
// more than one match, use the matched hits as the list moving to the next pattern.
// this way you can have a series of selection criteria
// this way you can have a series of selection criteria
...
@@ -153,9 +153,9 @@ func kindMatches(pattern schema.GroupVersionKind, kind schema.GroupVersionKind)
...
@@ -153,9 +153,9 @@ func kindMatches(pattern schema.GroupVersionKind, kind schema.GroupVersionKind)
}
}
func
(
m
PriorityRESTMapper
)
RESTMapping
(
gk
schema
.
GroupKind
,
versions
...
string
)
(
mapping
*
RESTMapping
,
err
error
)
{
func
(
m
PriorityRESTMapper
)
RESTMapping
(
gk
schema
.
GroupKind
,
versions
...
string
)
(
mapping
*
RESTMapping
,
err
error
)
{
mappings
,
e
rr
:=
m
.
Delegate
.
RESTMappings
(
gk
,
versions
...
)
mappings
,
originalE
rr
:=
m
.
Delegate
.
RESTMappings
(
gk
,
versions
...
)
if
err
!=
nil
{
if
originalErr
!=
nil
&&
len
(
mappings
)
==
0
{
return
nil
,
e
rr
return
nil
,
originalE
rr
}
}
// any versions the user provides take priority
// any versions the user provides take priority
...
@@ -187,7 +187,7 @@ func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string)
...
@@ -187,7 +187,7 @@ func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string)
continue
continue
case
1
:
case
1
:
// one match, return
// one match, return
return
matching
[
0
],
nil
return
matching
[
0
],
originalErr
default
:
default
:
// more than one match, use the matched hits as the list moving to the next pattern.
// more than one match, use the matched hits as the list moving to the next pattern.
// this way you can have a series of selection criteria
// this way you can have a series of selection criteria
...
@@ -195,7 +195,7 @@ func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string)
...
@@ -195,7 +195,7 @@ func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string)
}
}
}
}
if
len
(
remaining
)
==
1
{
if
len
(
remaining
)
==
1
{
return
remaining
[
0
],
nil
return
remaining
[
0
],
originalErr
}
}
var
kinds
[]
schema
.
GroupVersionKind
var
kinds
[]
schema
.
GroupVersionKind
...
...
staging/src/k8s.io/apimachinery/pkg/api/meta/priority_test.go
View file @
e3e1729c
...
@@ -35,6 +35,30 @@ func TestPriorityRESTMapperResourceForErrorHandling(t *testing.T) {
...
@@ -35,6 +35,30 @@ func TestPriorityRESTMapperResourceForErrorHandling(t *testing.T) {
err
string
err
string
}{
}{
{
{
name
:
"error"
,
delegate
:
fixedRESTMapper
{
err
:
errors
.
New
(
"delegateError"
)},
err
:
"delegateError"
,
},
{
name
:
"single hit + error"
,
delegate
:
fixedRESTMapper
{
resourcesFor
:
[]
schema
.
GroupVersionResource
{{
Resource
:
"single-hit"
}},
err
:
errors
.
New
(
"delegateError"
)},
result
:
schema
.
GroupVersionResource
{
Resource
:
"single-hit"
},
err
:
"delegateError"
,
},
{
name
:
"group selection + error"
,
delegate
:
fixedRESTMapper
{
resourcesFor
:
[]
schema
.
GroupVersionResource
{
{
Group
:
"one"
,
Version
:
"a"
,
Resource
:
"first"
},
{
Group
:
"two"
,
Version
:
"b"
,
Resource
:
"second"
},
},
err
:
errors
.
New
(
"delegateError"
)},
resourcePatterns
:
[]
schema
.
GroupVersionResource
{
{
Group
:
"one"
,
Version
:
AnyVersion
,
Resource
:
AnyResource
},
},
result
:
schema
.
GroupVersionResource
{
Group
:
"one"
,
Version
:
"a"
,
Resource
:
"first"
},
err
:
"delegateError"
,
},
{
name
:
"single hit"
,
name
:
"single hit"
,
delegate
:
fixedRESTMapper
{
resourcesFor
:
[]
schema
.
GroupVersionResource
{{
Resource
:
"single-hit"
}}},
delegate
:
fixedRESTMapper
{
resourcesFor
:
[]
schema
.
GroupVersionResource
{{
Resource
:
"single-hit"
}}},
result
:
schema
.
GroupVersionResource
{
Resource
:
"single-hit"
},
result
:
schema
.
GroupVersionResource
{
Resource
:
"single-hit"
},
...
@@ -106,6 +130,10 @@ func TestPriorityRESTMapperResourceForErrorHandling(t *testing.T) {
...
@@ -106,6 +130,10 @@ func TestPriorityRESTMapperResourceForErrorHandling(t *testing.T) {
if
len
(
tc
.
err
)
==
0
&&
actualErr
==
nil
{
if
len
(
tc
.
err
)
==
0
&&
actualErr
==
nil
{
continue
continue
}
}
if
len
(
tc
.
err
)
==
0
&&
actualErr
!=
nil
{
t
.
Errorf
(
"%s: unexpected err: %v"
,
tc
.
name
,
actualErr
)
continue
}
if
len
(
tc
.
err
)
>
0
&&
actualErr
==
nil
{
if
len
(
tc
.
err
)
>
0
&&
actualErr
==
nil
{
t
.
Errorf
(
"%s: missing expected err: %v"
,
tc
.
name
,
tc
.
err
)
t
.
Errorf
(
"%s: missing expected err: %v"
,
tc
.
name
,
tc
.
err
)
continue
continue
...
@@ -126,6 +154,30 @@ func TestPriorityRESTMapperKindForErrorHandling(t *testing.T) {
...
@@ -126,6 +154,30 @@ func TestPriorityRESTMapperKindForErrorHandling(t *testing.T) {
err
string
err
string
}{
}{
{
{
name
:
"error"
,
delegate
:
fixedRESTMapper
{
err
:
errors
.
New
(
"delegateErr"
)},
err
:
"delegateErr"
,
},
{
name
:
"single hit + error"
,
delegate
:
fixedRESTMapper
{
kindsFor
:
[]
schema
.
GroupVersionKind
{{
Kind
:
"single-hit"
}},
err
:
errors
.
New
(
"delegateErr"
)},
result
:
schema
.
GroupVersionKind
{
Kind
:
"single-hit"
},
err
:
"delegateErr"
,
},
{
name
:
"group selection + error"
,
delegate
:
fixedRESTMapper
{
kindsFor
:
[]
schema
.
GroupVersionKind
{
{
Group
:
"one"
,
Version
:
"a"
,
Kind
:
"first"
},
{
Group
:
"two"
,
Version
:
"b"
,
Kind
:
"second"
},
},
err
:
errors
.
New
(
"delegateErr"
)},
kindPatterns
:
[]
schema
.
GroupVersionKind
{
{
Group
:
"one"
,
Version
:
AnyVersion
,
Kind
:
AnyKind
},
},
result
:
schema
.
GroupVersionKind
{
Group
:
"one"
,
Version
:
"a"
,
Kind
:
"first"
},
err
:
"delegateErr"
,
},
{
name
:
"single hit"
,
name
:
"single hit"
,
delegate
:
fixedRESTMapper
{
kindsFor
:
[]
schema
.
GroupVersionKind
{{
Kind
:
"single-hit"
}}},
delegate
:
fixedRESTMapper
{
kindsFor
:
[]
schema
.
GroupVersionKind
{{
Kind
:
"single-hit"
}}},
result
:
schema
.
GroupVersionKind
{
Kind
:
"single-hit"
},
result
:
schema
.
GroupVersionKind
{
Kind
:
"single-hit"
},
...
@@ -197,6 +249,10 @@ func TestPriorityRESTMapperKindForErrorHandling(t *testing.T) {
...
@@ -197,6 +249,10 @@ func TestPriorityRESTMapperKindForErrorHandling(t *testing.T) {
if
len
(
tc
.
err
)
==
0
&&
actualErr
==
nil
{
if
len
(
tc
.
err
)
==
0
&&
actualErr
==
nil
{
continue
continue
}
}
if
len
(
tc
.
err
)
==
0
&&
actualErr
!=
nil
{
t
.
Errorf
(
"%s: unexpected err: %v"
,
tc
.
name
,
actualErr
)
continue
}
if
len
(
tc
.
err
)
>
0
&&
actualErr
==
nil
{
if
len
(
tc
.
err
)
>
0
&&
actualErr
==
nil
{
t
.
Errorf
(
"%s: missing expected err: %v"
,
tc
.
name
,
tc
.
err
)
t
.
Errorf
(
"%s: missing expected err: %v"
,
tc
.
name
,
tc
.
err
)
continue
continue
...
@@ -249,6 +305,13 @@ func TestPriorityRESTMapperRESTMapping(t *testing.T) {
...
@@ -249,6 +305,13 @@ func TestPriorityRESTMapperRESTMapping(t *testing.T) {
err
:
errors
.
New
(
"fail on this"
),
err
:
errors
.
New
(
"fail on this"
),
},
},
{
{
name
:
"result + error"
,
mapper
:
PriorityRESTMapper
{
Delegate
:
fixedRESTMapper
{
mappings
:
[]
*
RESTMapping
{
mapping1
},
err
:
errors
.
New
(
"fail on this"
)}},
input
:
schema
.
GroupKind
{
Kind
:
"Foo"
},
result
:
mapping1
,
err
:
errors
.
New
(
"fail on this"
),
},
{
name
:
"return error for ambiguous"
,
name
:
"return error for ambiguous"
,
mapper
:
PriorityRESTMapper
{
mapper
:
PriorityRESTMapper
{
Delegate
:
allMappers
,
Delegate
:
allMappers
,
...
...
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