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
91c027d6
Commit
91c027d6
authored
Mar 08, 2017
by
andrewsykim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support hostIP in downward API
parent
b4c71b1f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
9 deletions
+37
-9
conversion.go
pkg/api/v1/conversion.go
+1
-0
validation.go
pkg/api/validation/validation.go
+1
-1
validation_test.go
pkg/api/validation/validation_test.go
+21
-3
fieldpath.go
pkg/fieldpath/fieldpath.go
+0
-5
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+2
-0
downward_api.go
test/e2e/common/downward_api.go
+8
-0
dapi-pod.yaml
test/fixtures/doc-yaml/user-guide/downward-api/dapi-pod.yaml
+4
-0
No files found.
pkg/api/v1/conversion.go
View file @
91c027d6
...
...
@@ -190,6 +190,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
"spec.restartPolicy"
,
"spec.serviceAccountName"
,
"status.phase"
,
"status.hostIP"
,
"status.podIP"
:
return
label
,
value
,
nil
// This is for backwards compatibility with old v1 clients which send spec.host
...
...
pkg/api/validation/validation.go
View file @
91c027d6
...
...
@@ -1416,7 +1416,7 @@ func ValidateEnv(vars []api.EnvVar, fldPath *field.Path) field.ErrorList {
return
allErrs
}
var
validFieldPathExpressionsEnv
=
sets
.
NewString
(
"metadata.name"
,
"metadata.namespace"
,
"spec.nodeName"
,
"spec.serviceAccountName"
,
"status.podIP"
)
var
validFieldPathExpressionsEnv
=
sets
.
NewString
(
"metadata.name"
,
"metadata.namespace"
,
"spec.nodeName"
,
"spec.serviceAccountName"
,
"status.
hostIP"
,
"status.
podIP"
)
var
validContainerResourceFieldPathExpressions
=
sets
.
NewString
(
"limits.cpu"
,
"limits.memory"
,
"requests.cpu"
,
"requests.memory"
)
func
validateEnvVarValueFrom
(
ev
api
.
EnvVar
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
...
...
pkg/api/validation/validation_test.go
View file @
91c027d6
...
...
@@ -2154,6 +2154,24 @@ func TestValidateEnv(t *testing.T) {
},
},
{
Name
:
"abc"
,
ValueFrom
:
&
api
.
EnvVarSource
{
FieldRef
:
&
api
.
ObjectFieldSelector
{
APIVersion
:
api
.
Registry
.
GroupOrDie
(
api
.
GroupName
)
.
GroupVersion
.
String
(),
FieldPath
:
"status.hostIP"
,
},
},
},
{
Name
:
"abc"
,
ValueFrom
:
&
api
.
EnvVarSource
{
FieldRef
:
&
api
.
ObjectFieldSelector
{
APIVersion
:
api
.
Registry
.
GroupOrDie
(
api
.
GroupName
)
.
GroupVersion
.
String
(),
FieldPath
:
"status.podIP"
,
},
},
},
{
Name
:
"secret_value"
,
ValueFrom
:
&
api
.
EnvVarSource
{
SecretKeyRef
:
&
api
.
SecretKeySelector
{
...
...
@@ -2328,7 +2346,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError
:
`[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.labels": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.podIP`
,
expectedError
:
`[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.labels": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.
hostIP, status.
podIP`
,
},
{
name
:
"invalid fieldPath annotations"
,
...
...
@@ -2341,7 +2359,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError
:
`[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.annotations": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.podIP`
,
expectedError
:
`[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.annotations": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.
hostIP, status.
podIP`
,
},
{
name
:
"unsupported fieldPath"
,
...
...
@@ -2354,7 +2372,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError
:
`valueFrom.fieldRef.fieldPath: Unsupported value: "status.phase": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.podIP`
,
expectedError
:
`valueFrom.fieldRef.fieldPath: Unsupported value: "status.phase": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.
hostIP, status.
podIP`
,
},
}
for
_
,
tc
:=
range
errorCases
{
...
...
pkg/fieldpath/fieldpath.go
View file @
91c027d6
...
...
@@ -41,11 +41,6 @@ func FormatMap(m map[string]string) (fmtStr string) {
// ExtractFieldPathAsString extracts the field from the given object
// and returns it as a string. The object must be a pointer to an
// API type.
//
// Currently, this API is limited to supporting the fieldpaths:
//
// 1. metadata.name - The name of an API object
// 2. metadata.namespace - The namespace of an API object
func
ExtractFieldPathAsString
(
obj
interface
{},
fieldPath
string
)
(
string
,
error
)
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
...
...
pkg/kubelet/kubelet_pods.go
View file @
91c027d6
...
...
@@ -617,6 +617,8 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *v1.ObjectFieldSelector, pod
return
pod
.
Spec
.
NodeName
,
nil
case
"spec.serviceAccountName"
:
return
pod
.
Spec
.
ServiceAccountName
,
nil
case
"status.hostIP"
:
return
pod
.
Status
.
HostIP
,
nil
case
"status.podIP"
:
return
podIP
,
nil
}
...
...
test/e2e/common/downward_api.go
View file @
91c027d6
...
...
@@ -73,11 +73,19 @@ var _ = framework.KubeDescribe("Downward API", func() {
FieldPath
:
"status.podIP"
,
},
},
Name
:
"HOST_IP"
,
ValueFrom
:
&
v1
.
EnvVarSource
{
FieldRef
:
&
v1
.
ObjectFieldSelector
{
APIVersion
:
"v1"
,
FieldPath
:
"status.hostIP"
,
},
},
},
}
expectations
:=
[]
string
{
"POD_IP=(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)"
,
"HOST_IP=(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)"
,
}
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
...
...
test/fixtures/doc-yaml/user-guide/downward-api/dapi-pod.yaml
View file @
91c027d6
...
...
@@ -20,4 +20,8 @@ spec:
valueFrom
:
fieldRef
:
fieldPath
:
status.podIP
-
name
:
MY_HOST_IP
valueFrom
:
fieldRef
:
fieldPath
:
status.hostIP
restartPolicy
:
Never
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