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
34a7b3de
Commit
34a7b3de
authored
Nov 22, 2017
by
Yang Guo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a separate conversion function for the field labels used by downward API
parent
82c9eec1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
176 additions
and
11 deletions
+176
-11
BUILD
pkg/apis/core/BUILD
+1
-0
BUILD
pkg/apis/core/pods/BUILD
+30
-0
helpers.go
pkg/apis/core/pods/helpers.go
+51
-0
helpers_test.go
pkg/apis/core/pods/helpers_test.go
+87
-0
conversion.go
pkg/apis/core/v1/conversion.go
+1
-6
BUILD
pkg/apis/core/validation/BUILD
+1
-0
validation.go
pkg/apis/core/validation/validation.go
+2
-2
BUILD
pkg/kubelet/BUILD
+1
-1
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+2
-2
No files found.
pkg/apis/core/BUILD
View file @
34a7b3de
...
@@ -51,6 +51,7 @@ filegroup(
...
@@ -51,6 +51,7 @@ filegroup(
"//pkg/apis/core/fuzzer:all-srcs",
"//pkg/apis/core/fuzzer:all-srcs",
"//pkg/apis/core/helper:all-srcs",
"//pkg/apis/core/helper:all-srcs",
"//pkg/apis/core/install:all-srcs",
"//pkg/apis/core/install:all-srcs",
"//pkg/apis/core/pods:all-srcs",
"//pkg/apis/core/v1:all-srcs",
"//pkg/apis/core/v1:all-srcs",
"//pkg/apis/core/validation:all-srcs",
"//pkg/apis/core/validation:all-srcs",
],
],
...
...
pkg/apis/core/pods/BUILD
0 → 100644
View file @
34a7b3de
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["helpers.go"],
importpath = "k8s.io/kubernetes/pkg/apis/core/pods",
visibility = ["//visibility:public"],
deps = ["//pkg/fieldpath:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["helpers_test.go"],
importpath = "k8s.io/kubernetes/pkg/apis/core/pods",
library = ":go_default_library",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
pkg/apis/core/pods/helpers.go
0 → 100644
View file @
34a7b3de
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
pods
import
(
"fmt"
"k8s.io/kubernetes/pkg/fieldpath"
)
func
ConvertDownwardAPIFieldLabel
(
version
,
label
,
value
string
)
(
string
,
string
,
error
)
{
if
version
!=
"v1"
{
return
""
,
""
,
fmt
.
Errorf
(
"unsupported pod version: %s"
,
version
)
}
path
,
_
:=
fieldpath
.
SplitMaybeSubscriptedPath
(
label
)
switch
path
{
case
"metadata.annotations"
,
"metadata.labels"
,
"metadata.name"
,
"metadata.namespace"
,
"metadata.uid"
,
"spec.nodeName"
,
"spec.restartPolicy"
,
"spec.serviceAccountName"
,
"spec.schedulerName"
,
"status.phase"
,
"status.hostIP"
,
"status.podIP"
:
return
label
,
value
,
nil
// This is for backwards compatibility with old v1 clients which send spec.host
case
"spec.host"
:
return
"spec.nodeName"
,
value
,
nil
default
:
return
""
,
""
,
fmt
.
Errorf
(
"field label not supported: %s"
,
label
)
}
}
pkg/apis/core/pods/helpers_test.go
0 → 100644
View file @
34a7b3de
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
pods
import
(
"testing"
)
func
TestConvertDownwardAPIFieldLabel
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
version
string
label
string
value
string
expectedErr
bool
expectedLabel
string
expectedValue
string
}{
{
version
:
"v2"
,
label
:
"metadata.name"
,
value
:
"test-pod"
,
expectedErr
:
true
,
},
{
version
:
"v1"
,
label
:
"invalid-label"
,
value
:
"value"
,
expectedErr
:
true
,
},
{
version
:
"v1"
,
label
:
"metadata.name"
,
value
:
"test-pod"
,
expectedLabel
:
"metadata.name"
,
expectedValue
:
"test-pod"
,
},
{
version
:
"v1"
,
label
:
"metadata.annotations"
,
value
:
"myValue"
,
expectedLabel
:
"metadata.annotations"
,
expectedValue
:
"myValue"
,
},
{
version
:
"v1"
,
label
:
"metadata.annotations['myKey']"
,
value
:
"myValue"
,
expectedLabel
:
"metadata.annotations['myKey']"
,
expectedValue
:
"myValue"
,
},
{
version
:
"v1"
,
label
:
"spec.host"
,
value
:
"127.0.0.1"
,
expectedLabel
:
"spec.nodeName"
,
expectedValue
:
"127.0.0.1"
,
},
}
for
_
,
tc
:=
range
testCases
{
label
,
value
,
err
:=
ConvertDownwardAPIFieldLabel
(
tc
.
version
,
tc
.
label
,
tc
.
value
)
if
err
!=
nil
{
if
tc
.
expectedErr
{
continue
}
t
.
Errorf
(
"ConvertDownwardAPIFieldLabel(%s, %s, %s) failed: %s"
,
tc
.
version
,
tc
.
label
,
tc
.
value
,
err
)
}
if
tc
.
expectedLabel
!=
label
||
tc
.
expectedValue
!=
value
{
t
.
Errorf
(
"ConvertDownwardAPIFieldLabel(%s, %s, %s) = (%s, %s, nil), expected (%s, %s, nil)"
,
tc
.
version
,
tc
.
label
,
tc
.
value
,
label
,
value
,
tc
.
expectedLabel
,
tc
.
expectedValue
)
}
}
}
pkg/apis/core/v1/conversion.go
View file @
34a7b3de
...
@@ -159,17 +159,12 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
...
@@ -159,17 +159,12 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
func
(
label
,
value
string
)
(
string
,
string
,
error
)
{
func
(
label
,
value
string
)
(
string
,
string
,
error
)
{
path
,
_
:=
fieldpath
.
SplitMaybeSubscriptedPath
(
label
)
path
,
_
:=
fieldpath
.
SplitMaybeSubscriptedPath
(
label
)
switch
path
{
switch
path
{
case
"metadata.annotations"
,
case
"metadata.name"
,
"metadata.labels"
,
"metadata.name"
,
"metadata.namespace"
,
"metadata.namespace"
,
"metadata.uid"
,
"spec.nodeName"
,
"spec.nodeName"
,
"spec.restartPolicy"
,
"spec.restartPolicy"
,
"spec.serviceAccountName"
,
"spec.schedulerName"
,
"spec.schedulerName"
,
"status.phase"
,
"status.phase"
,
"status.hostIP"
,
"status.podIP"
:
"status.podIP"
:
return
label
,
value
,
nil
return
label
,
value
,
nil
// This is for backwards compatibility with old v1 clients which send spec.host
// This is for backwards compatibility with old v1 clients which send spec.host
...
...
pkg/apis/core/validation/BUILD
View file @
34a7b3de
...
@@ -18,6 +18,7 @@ go_library(
...
@@ -18,6 +18,7 @@ go_library(
"//pkg/api/service:go_default_library",
"//pkg/api/service:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/helper:go_default_library",
"//pkg/apis/core/helper:go_default_library",
"//pkg/apis/core/pods:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/capabilities:go_default_library",
"//pkg/capabilities:go_default_library",
...
...
pkg/apis/core/validation/validation.go
View file @
34a7b3de
...
@@ -42,10 +42,10 @@ import (
...
@@ -42,10 +42,10 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/api/legacyscheme"
apiservice
"k8s.io/kubernetes/pkg/api/service"
apiservice
"k8s.io/kubernetes/pkg/api/service"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/apis/core/helper"
podshelper
"k8s.io/kubernetes/pkg/apis/core/pods"
corev1
"k8s.io/kubernetes/pkg/apis/core/v1"
corev1
"k8s.io/kubernetes/pkg/apis/core/v1"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/capabilities"
...
@@ -1964,7 +1964,7 @@ func validateObjectFieldSelector(fs *core.ObjectFieldSelector, expressions *sets
...
@@ -1964,7 +1964,7 @@ func validateObjectFieldSelector(fs *core.ObjectFieldSelector, expressions *sets
return
allErrs
return
allErrs
}
}
internalFieldPath
,
_
,
err
:=
legacyscheme
.
Scheme
.
ConvertFieldLabel
(
fs
.
APIVersion
,
"Pod"
,
fs
.
FieldPath
,
""
)
internalFieldPath
,
_
,
err
:=
podshelper
.
ConvertDownwardAPIFieldLabel
(
fs
.
APIVersion
,
fs
.
FieldPath
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"fieldPath"
),
fs
.
FieldPath
,
fmt
.
Sprintf
(
"error converting fieldPath: %v"
,
err
)))
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"fieldPath"
),
fs
.
FieldPath
,
fmt
.
Sprintf
(
"error converting fieldPath: %v"
,
err
)))
return
allErrs
return
allErrs
...
...
pkg/kubelet/BUILD
View file @
34a7b3de
...
@@ -29,10 +29,10 @@ go_library(
...
@@ -29,10 +29,10 @@ go_library(
],
],
importpath = "k8s.io/kubernetes/pkg/kubelet",
importpath = "k8s.io/kubernetes/pkg/kubelet",
deps = [
deps = [
"//pkg/api/legacyscheme:go_default_library",
"//pkg/api/v1/pod:go_default_library",
"//pkg/api/v1/pod:go_default_library",
"//pkg/api/v1/resource:go_default_library",
"//pkg/api/v1/resource:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/pods:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/apis/core/v1/helper/qos:go_default_library",
"//pkg/apis/core/v1/helper/qos:go_default_library",
...
...
pkg/kubelet/kubelet_pods.go
View file @
34a7b3de
...
@@ -43,9 +43,9 @@ import (
...
@@ -43,9 +43,9 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/kubernetes/pkg/api/legacyscheme"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/api/v1/resource"
"k8s.io/kubernetes/pkg/api/v1/resource"
podshelper
"k8s.io/kubernetes/pkg/apis/core/pods"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
v1qos
"k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
v1qos
"k8s.io/kubernetes/pkg/apis/core/v1/helper/qos"
"k8s.io/kubernetes/pkg/apis/core/v1/validation"
"k8s.io/kubernetes/pkg/apis/core/v1/validation"
...
@@ -733,7 +733,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
...
@@ -733,7 +733,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *v1.Pod, container *v1.Container
// podFieldSelectorRuntimeValue returns the runtime value of the given
// podFieldSelectorRuntimeValue returns the runtime value of the given
// selector for a pod.
// selector for a pod.
func
(
kl
*
Kubelet
)
podFieldSelectorRuntimeValue
(
fs
*
v1
.
ObjectFieldSelector
,
pod
*
v1
.
Pod
,
podIP
string
)
(
string
,
error
)
{
func
(
kl
*
Kubelet
)
podFieldSelectorRuntimeValue
(
fs
*
v1
.
ObjectFieldSelector
,
pod
*
v1
.
Pod
,
podIP
string
)
(
string
,
error
)
{
internalFieldPath
,
_
,
err
:=
legacyscheme
.
Scheme
.
ConvertFieldLabel
(
fs
.
APIVersion
,
"Pod"
,
fs
.
FieldPath
,
""
)
internalFieldPath
,
_
,
err
:=
podshelper
.
ConvertDownwardAPIFieldLabel
(
fs
.
APIVersion
,
fs
.
FieldPath
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
...
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