mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #107550 from wojtek-t/remove_selflink_from_kubelet
Remove no-longer used selflink code from kubelet
This commit is contained in:
commit
8c6b910e68
@ -80,8 +80,6 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName types.Node
|
|||||||
// Set the Host field to indicate this pod is scheduled on the current node.
|
// Set the Host field to indicate this pod is scheduled on the current node.
|
||||||
pod.Spec.NodeName = string(nodeName)
|
pod.Spec.NodeName = string(nodeName)
|
||||||
|
|
||||||
pod.ObjectMeta.SelfLink = getSelfLink(pod.Name, pod.Namespace)
|
|
||||||
|
|
||||||
if pod.Annotations == nil {
|
if pod.Annotations == nil {
|
||||||
pod.Annotations = make(map[string]string)
|
pod.Annotations = make(map[string]string)
|
||||||
}
|
}
|
||||||
@ -102,15 +100,6 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName types.Node
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSelfLink(name, namespace string) string {
|
|
||||||
var selfLink string
|
|
||||||
if len(namespace) == 0 {
|
|
||||||
namespace = metav1.NamespaceDefault
|
|
||||||
}
|
|
||||||
selfLink = fmt.Sprintf("/api/v1/namespaces/%s/pods/%s", namespace, name)
|
|
||||||
return selfLink
|
|
||||||
}
|
|
||||||
|
|
||||||
type defaultFunc func(pod *api.Pod) error
|
type defaultFunc func(pod *api.Pod) error
|
||||||
|
|
||||||
// tryDecodeSinglePod takes data and tries to extract valid Pod config information from it.
|
// tryDecodeSinglePod takes data and tries to extract valid Pod config information from it.
|
||||||
|
@ -186,34 +186,6 @@ func TestDecodePodList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSelfLink(t *testing.T) {
|
|
||||||
var testCases = []struct {
|
|
||||||
desc string
|
|
||||||
name string
|
|
||||||
namespace string
|
|
||||||
expectedSelfLink string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
desc: "No namespace specified",
|
|
||||||
name: "foo",
|
|
||||||
namespace: "",
|
|
||||||
expectedSelfLink: "/api/v1/namespaces/default/pods/foo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "Namespace specified",
|
|
||||||
name: "foo",
|
|
||||||
namespace: "bar",
|
|
||||||
expectedSelfLink: "/api/v1/namespaces/bar/pods/foo",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, testCase := range testCases {
|
|
||||||
selfLink := getSelfLink(testCase.name, testCase.namespace)
|
|
||||||
if testCase.expectedSelfLink != selfLink {
|
|
||||||
t.Errorf("%s: getSelfLink error, expected: %s, got: %s", testCase.desc, testCase.expectedSelfLink, selfLink)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStaticPodNameGenerate(t *testing.T) {
|
func TestStaticPodNameGenerate(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
nodeName types.NodeName
|
nodeName types.NodeName
|
||||||
|
@ -173,7 +173,6 @@ func getTestCases(hostname types.NodeName) []*testCase {
|
|||||||
UID: "12345",
|
UID: "12345",
|
||||||
Namespace: "mynamespace",
|
Namespace: "mynamespace",
|
||||||
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "12345"},
|
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "12345"},
|
||||||
SelfLink: getSelfLink("test-"+string(hostname), "mynamespace"),
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
NodeName: string(hostname),
|
NodeName: string(hostname),
|
||||||
|
@ -164,7 +164,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Name: "foo" + "-" + nodeName,
|
Name: "foo" + "-" + nodeName,
|
||||||
Namespace: "mynamespace",
|
Namespace: "mynamespace",
|
||||||
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
|
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
|
||||||
SelfLink: getSelfLink("foo-"+nodeName, "mynamespace"),
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
NodeName: nodeName,
|
NodeName: nodeName,
|
||||||
@ -236,7 +235,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Name: "foo" + "-" + nodeName,
|
Name: "foo" + "-" + nodeName,
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
|
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
|
||||||
SelfLink: getSelfLink("foo-"+nodeName, metav1.NamespaceDefault),
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
NodeName: nodeName,
|
NodeName: nodeName,
|
||||||
@ -265,7 +263,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
Name: "bar" + "-" + nodeName,
|
Name: "bar" + "-" + nodeName,
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "222"},
|
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "222"},
|
||||||
SelfLink: getSelfLink("bar-"+nodeName, metav1.NamespaceDefault),
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
NodeName: nodeName,
|
NodeName: nodeName,
|
||||||
|
@ -32,9 +32,6 @@ var ImplicitContainerPrefix = "implicitly required container "
|
|||||||
// GenerateContainerRef returns an *v1.ObjectReference which references the given container
|
// GenerateContainerRef returns an *v1.ObjectReference which references the given container
|
||||||
// within the given pod. Returns an error if the reference can't be constructed or the
|
// within the given pod. Returns an error if the reference can't be constructed or the
|
||||||
// container doesn't actually belong to the pod.
|
// container doesn't actually belong to the pod.
|
||||||
//
|
|
||||||
// This function will return an error if the provided Pod does not have a selfLink,
|
|
||||||
// but we expect selfLink to be populated at all call sites for the function.
|
|
||||||
func GenerateContainerRef(pod *v1.Pod, container *v1.Container) (*v1.ObjectReference, error) {
|
func GenerateContainerRef(pod *v1.Pod, container *v1.Container) (*v1.ObjectReference, error) {
|
||||||
fieldPath, err := fieldPath(pod, container)
|
fieldPath, err := fieldPath(pod, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,7 +74,6 @@ func TestGenerateContainerRef(t *testing.T) {
|
|||||||
Namespace: "test-ns",
|
Namespace: "test-ns",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "/api/v1/pods/foo",
|
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
@ -85,13 +84,7 @@ func TestGenerateContainerRef(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
noSelfLinkPod = okPod
|
|
||||||
defaultedSelfLinkPod = okPod
|
|
||||||
)
|
)
|
||||||
noSelfLinkPod.Kind = ""
|
|
||||||
noSelfLinkPod.APIVersion = ""
|
|
||||||
noSelfLinkPod.ObjectMeta.SelfLink = ""
|
|
||||||
defaultedSelfLinkPod.ObjectMeta.SelfLink = "/api/v1/pods/ok"
|
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -132,23 +125,6 @@ func TestGenerateContainerRef(t *testing.T) {
|
|||||||
},
|
},
|
||||||
success: true,
|
success: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "defaulted-selflink",
|
|
||||||
pod: &defaultedSelfLinkPod,
|
|
||||||
container: &v1.Container{
|
|
||||||
Name: "by-name",
|
|
||||||
},
|
|
||||||
expected: &v1.ObjectReference{
|
|
||||||
Kind: "Pod",
|
|
||||||
APIVersion: "v1",
|
|
||||||
Name: "ok",
|
|
||||||
Namespace: "test-ns",
|
|
||||||
UID: "bar",
|
|
||||||
ResourceVersion: "42",
|
|
||||||
FieldPath: ".spec.containers{by-name}",
|
|
||||||
},
|
|
||||||
success: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "implicitly-required",
|
name: "implicitly-required",
|
||||||
pod: &okPod,
|
pod: &okPod,
|
||||||
|
@ -187,7 +187,6 @@ func TestParallelPuller(t *testing.T) {
|
|||||||
Namespace: "test-ns",
|
Namespace: "test-ns",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "/api/v1/pods/foo",
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
cases := pullerTestCases()
|
cases := pullerTestCases()
|
||||||
@ -215,7 +214,6 @@ func TestSerializedPuller(t *testing.T) {
|
|||||||
Namespace: "test-ns",
|
Namespace: "test-ns",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "/api/v1/pods/foo",
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
cases := pullerTestCases()
|
cases := pullerTestCases()
|
||||||
@ -264,7 +262,6 @@ func TestPullAndListImageWithPodAnnotations(t *testing.T) {
|
|||||||
Namespace: "test-ns",
|
Namespace: "test-ns",
|
||||||
UID: "bar",
|
UID: "bar",
|
||||||
ResourceVersion: "42",
|
ResourceVersion: "42",
|
||||||
SelfLink: "/api/v1/pods/foo",
|
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"kubernetes.io/runtimehandler": "handler_name",
|
"kubernetes.io/runtimehandler": "handler_name",
|
||||||
},
|
},
|
||||||
|
@ -60,7 +60,7 @@ type RemoteConfigSource interface {
|
|||||||
// KubeletFilename returns the name of the Kubelet config file as it should appear in the keys of Payload.Files()
|
// KubeletFilename returns the name of the Kubelet config file as it should appear in the keys of Payload.Files()
|
||||||
KubeletFilename() string
|
KubeletFilename() string
|
||||||
|
|
||||||
// APIPath returns the API path to the remote resource, e.g. its SelfLink
|
// APIPath returns the API path to the remote resource.
|
||||||
APIPath() string
|
APIPath() string
|
||||||
|
|
||||||
// UID returns the globally unique identifier for the most recently downloaded payload targeted by the source.
|
// UID returns the globally unique identifier for the most recently downloaded payload targeted by the source.
|
||||||
|
Loading…
Reference in New Issue
Block a user