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
c1390a08
Commit
c1390a08
authored
Apr 07, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version field selector field names in the client
parent
71e7079a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
42 deletions
+89
-42
request.go
pkg/client/request.go
+84
-28
apiserver.go
pkg/kubelet/config/apiserver.go
+2
-2
kubelet.go
pkg/kubelet/kubelet.go
+1
-1
factory.go
plugin/pkg/scheduler/factory/factory.go
+2
-11
No files found.
pkg/client/request.go
View file @
c1390a08
...
...
@@ -248,36 +248,85 @@ func (r *Request) RequestURI(uri string) *Request {
return
r
}
/*
// ParseSelectorParam parses the given string as a resource selector.
// This is a convenience function so you don't have to first check that it's a
// validly formatted selector.
func (r *Request) ParseSelectorParam(paramName, item string) *Request {
if r.err != nil {
return r
const
(
// A constant that clients can use to refer in a field selector to the object name field.
// Will be automatically emitted as the correct name for the API version.
ObjectNameField
=
"metadata.name"
PodHost
=
"spec.host"
)
type
clientFieldNameToAPIVersionFieldName
map
[
string
]
string
func
(
c
clientFieldNameToAPIVersionFieldName
)
filterField
(
field
,
value
string
)
(
newField
,
newValue
string
,
err
error
)
{
newFieldName
,
ok
:=
c
[
field
]
if
!
ok
{
return
""
,
""
,
fmt
.
Errorf
(
"%v - %v - no field mapping defined"
,
field
,
value
)
}
var selector string
var err error
switch paramName {
case "labels":
var lsel labels.Selector
if lsel, err = labels.Parse(item); err == nil {
selector = lsel.String()
}
case "fields":
var fsel fields.Selector
if fsel, err = fields.ParseSelector(item); err == nil {
selector = fsel.String()
}
default:
err = fmt.Errorf("unknown parameter name '%s'", paramName)
return
newFieldName
,
value
,
nil
}
type
resourceTypeToFieldMapping
map
[
string
]
clientFieldNameToAPIVersionFieldName
func
(
r
resourceTypeToFieldMapping
)
filterField
(
resourceType
,
field
,
value
string
)
(
newField
,
newValue
string
,
err
error
)
{
fMapping
,
ok
:=
r
[
resourceType
]
if
!
ok
{
return
""
,
""
,
fmt
.
Errorf
(
"%v - %v - %v - no field mapping defined"
,
resourceType
,
field
,
value
)
}
if err != nil {
r.err = err
return r
return
fMapping
.
filterField
(
field
,
value
)
}
type
versionToResourceToFieldMapping
map
[
string
]
resourceTypeToFieldMapping
func
(
v
versionToResourceToFieldMapping
)
filterField
(
apiVersion
,
resourceType
,
field
,
value
string
)
(
newField
,
newValue
string
,
err
error
)
{
rMapping
,
ok
:=
v
[
apiVersion
]
if
!
ok
{
glog
.
Warningf
(
"field selector: %v - %v - %v - %v: need to check if this is versioned correctly."
,
apiVersion
,
resourceType
,
field
,
value
)
return
field
,
value
,
nil
}
return r.setParam(paramName, selector)
}*/
newField
,
newValue
,
err
=
rMapping
.
filterField
(
resourceType
,
field
,
value
)
if
err
!=
nil
{
// This is only a warning until we find and fix all of the client's usages.
glog
.
Warningf
(
"field selector: %v - %v - %v - %v: need to check if this is versioned correctly."
,
apiVersion
,
resourceType
,
field
,
value
)
return
field
,
value
,
nil
}
return
newField
,
newValue
,
nil
}
var
fieldMappings
=
versionToResourceToFieldMapping
{
"v1beta1"
:
resourceTypeToFieldMapping
{
"nodes"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"name"
,
},
"minions"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"name"
,
},
"pods"
:
clientFieldNameToAPIVersionFieldName
{
PodHost
:
"DesiredState.Host"
,
},
},
"v1beta2"
:
resourceTypeToFieldMapping
{
"nodes"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"name"
,
},
"minions"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"name"
,
},
"pods"
:
clientFieldNameToAPIVersionFieldName
{
PodHost
:
"DesiredState.Host"
,
},
},
"v1beta3"
:
resourceTypeToFieldMapping
{
"nodes"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"metadata.name"
,
},
"minions"
:
clientFieldNameToAPIVersionFieldName
{
ObjectNameField
:
"metadata.name"
,
},
"pods"
:
clientFieldNameToAPIVersionFieldName
{
PodHost
:
"spec.host"
,
},
},
}
// FieldsSelectorParam adds the given selector as a query parameter with the name paramName.
func
(
r
*
Request
)
FieldsSelectorParam
(
s
fields
.
Selector
)
*
Request
{
...
...
@@ -287,7 +336,14 @@ func (r *Request) FieldsSelectorParam(s fields.Selector) *Request {
if
s
.
Empty
()
{
return
r
}
return
r
.
setParam
(
api
.
FieldSelectorQueryParam
(
r
.
apiVersion
),
s
.
String
())
s2
,
err
:=
s
.
Transform
(
func
(
field
,
value
string
)
(
newField
,
newValue
string
,
err
error
)
{
return
fieldMappings
.
filterField
(
r
.
apiVersion
,
r
.
resource
,
field
,
value
)
})
if
err
!=
nil
{
r
.
err
=
err
return
r
}
return
r
.
setParam
(
api
.
FieldSelectorQueryParam
(
r
.
apiVersion
),
s2
.
String
())
}
// LabelsSelectorParam adds the given selector as a query parameter
...
...
pkg/kubelet/config/apiserver.go
View file @
c1390a08
...
...
@@ -28,8 +28,8 @@ import (
)
// NewSourceApiserver creates a config source that watches and pulls from the apiserver.
func
NewSourceApiserver
(
c
lient
*
client
.
Client
,
hostname
string
,
updates
chan
<-
interface
{})
{
lw
:=
cache
.
NewListWatchFromClient
(
c
lient
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
getHostFieldLabel
(
client
.
APIVersion
())
,
hostname
))
func
NewSourceApiserver
(
c
*
client
.
Client
,
hostname
string
,
updates
chan
<-
interface
{})
{
lw
:=
cache
.
NewListWatchFromClient
(
c
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
client
.
PodHost
,
hostname
))
newSourceApiserverFromLW
(
lw
,
updates
)
}
...
...
pkg/kubelet/kubelet.go
View file @
c1390a08
...
...
@@ -168,7 +168,7 @@ func NewMainKubelet(
if
kubeClient
!=
nil
{
// TODO: cache.NewListWatchFromClient is limited as it takes a client implementation rather
// than an interface. There is no way to construct a list+watcher using resource name.
fieldSelector
:=
fields
.
Set
{
"metadata.name"
:
hostname
}
.
AsSelector
()
fieldSelector
:=
fields
.
Set
{
client
.
ObjectNameField
:
hostname
}
.
AsSelector
()
listWatch
:=
&
cache
.
ListWatch
{
ListFunc
:
func
()
(
runtime
.
Object
,
error
)
{
// TODO: Use List() with fieldSelector when it is supported.
...
...
plugin/pkg/scheduler/factory/factory.go
View file @
c1390a08
...
...
@@ -208,7 +208,7 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSe
// Returns a cache.ListWatch that finds all pods that need to be
// scheduled.
func
(
factory
*
ConfigFactory
)
createUnassignedPodLW
()
*
cache
.
ListWatch
{
return
cache
.
NewListWatchFromClient
(
factory
.
Client
,
"pods"
,
api
.
NamespaceAll
,
fields
.
Set
{
getHostFieldLabel
(
factory
.
Client
.
APIVersion
())
:
""
}
.
AsSelector
())
return
cache
.
NewListWatchFromClient
(
factory
.
Client
,
"pods"
,
api
.
NamespaceAll
,
fields
.
Set
{
client
.
PodHost
:
""
}
.
AsSelector
())
}
func
parseSelectorOrDie
(
s
string
)
fields
.
Selector
{
...
...
@@ -224,7 +224,7 @@ func parseSelectorOrDie(s string) fields.Selector {
// TODO: return a ListerWatcher interface instead?
func
(
factory
*
ConfigFactory
)
createAssignedPodLW
()
*
cache
.
ListWatch
{
return
cache
.
NewListWatchFromClient
(
factory
.
Client
,
"pods"
,
api
.
NamespaceAll
,
parseSelectorOrDie
(
getHostFieldLabel
(
factory
.
Client
.
APIVersion
())
+
"!="
))
parseSelectorOrDie
(
client
.
PodHost
+
"!="
))
}
// createMinionLW returns a cache.ListWatch that gets all changes to minions.
...
...
@@ -295,15 +295,6 @@ func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue
}
}
func
getHostFieldLabel
(
apiVersion
string
)
string
{
switch
apiVersion
{
case
"v1beta1"
,
"v1beta2"
:
return
"DesiredState.Host"
default
:
return
"spec.host"
}
}
// nodeEnumerator allows a cache.Poller to enumerate items in an api.NodeList
type
nodeEnumerator
struct
{
*
api
.
NodeList
...
...
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