Merge pull request #107550 from wojtek-t/remove_selflink_from_kubelet

Remove no-longer used selflink code from kubelet
This commit is contained in:
Kubernetes Prow Robot 2022-01-14 03:28:27 -08:00 committed by GitHub
commit 8c6b910e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1 additions and 74 deletions

View File

@ -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.
pod.Spec.NodeName = string(nodeName)
pod.ObjectMeta.SelfLink = getSelfLink(pod.Name, pod.Namespace)
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
}
@ -102,15 +100,6 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName types.Node
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
// tryDecodeSinglePod takes data and tries to extract valid Pod config information from it.

View File

@ -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) {
testCases := []struct {
nodeName types.NodeName

View File

@ -173,7 +173,6 @@ func getTestCases(hostname types.NodeName) []*testCase {
UID: "12345",
Namespace: "mynamespace",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "12345"},
SelfLink: getSelfLink("test-"+string(hostname), "mynamespace"),
},
Spec: v1.PodSpec{
NodeName: string(hostname),

View File

@ -164,7 +164,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
Name: "foo" + "-" + nodeName,
Namespace: "mynamespace",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
SelfLink: getSelfLink("foo-"+nodeName, "mynamespace"),
},
Spec: v1.PodSpec{
NodeName: nodeName,
@ -236,7 +235,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
Name: "foo" + "-" + nodeName,
Namespace: "default",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
SelfLink: getSelfLink("foo-"+nodeName, metav1.NamespaceDefault),
},
Spec: v1.PodSpec{
NodeName: nodeName,
@ -265,7 +263,6 @@ func TestExtractPodsFromHTTP(t *testing.T) {
Name: "bar" + "-" + nodeName,
Namespace: "default",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "222"},
SelfLink: getSelfLink("bar-"+nodeName, metav1.NamespaceDefault),
},
Spec: v1.PodSpec{
NodeName: nodeName,

View File

@ -32,9 +32,6 @@ var ImplicitContainerPrefix = "implicitly required 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
// 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) {
fieldPath, err := fieldPath(pod, container)
if err != nil {

View File

@ -74,7 +74,6 @@ func TestGenerateContainerRef(t *testing.T) {
Namespace: "test-ns",
UID: "bar",
ResourceVersion: "42",
SelfLink: "/api/v1/pods/foo",
},
Spec: v1.PodSpec{
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 {
name string
@ -132,23 +125,6 @@ func TestGenerateContainerRef(t *testing.T) {
},
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",
pod: &okPod,

View File

@ -187,7 +187,6 @@ func TestParallelPuller(t *testing.T) {
Namespace: "test-ns",
UID: "bar",
ResourceVersion: "42",
SelfLink: "/api/v1/pods/foo",
}}
cases := pullerTestCases()
@ -215,7 +214,6 @@ func TestSerializedPuller(t *testing.T) {
Namespace: "test-ns",
UID: "bar",
ResourceVersion: "42",
SelfLink: "/api/v1/pods/foo",
}}
cases := pullerTestCases()
@ -264,7 +262,6 @@ func TestPullAndListImageWithPodAnnotations(t *testing.T) {
Namespace: "test-ns",
UID: "bar",
ResourceVersion: "42",
SelfLink: "/api/v1/pods/foo",
Annotations: map[string]string{
"kubernetes.io/runtimehandler": "handler_name",
},

View File

@ -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() 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
// UID returns the globally unique identifier for the most recently downloaded payload targeted by the source.