mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 04:52:08 +00:00
Merge pull request #117370 from bart0sh/PR110-remove-dependency-e2e-framework-k/k/pkg/kubelet
e2e framework: remove last dependency to k/k/pkg/kubelet
This commit is contained in:
commit
6e541a6da7
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
@ -71,14 +70,14 @@ var _ = SIGDescribe("Ephemeral Containers [NodeConformance]", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := podClient.AddEphemeralContainerSync(ctx, pod, ec, time.Minute)
|
err := podClient.AddEphemeralContainerSync(ctx, pod, ec, time.Minute)
|
||||||
framework.ExpectNoError(err, "Failed to patch ephemeral containers in pod %q", format.Pod(pod))
|
framework.ExpectNoError(err, "Failed to patch ephemeral containers in pod %q", e2epod.FormatPod(pod))
|
||||||
|
|
||||||
ginkgo.By("checking pod container endpoints")
|
ginkgo.By("checking pod container endpoints")
|
||||||
// Can't use anything depending on kubectl here because it's not available in the node test environment
|
// Can't use anything depending on kubectl here because it's not available in the node test environment
|
||||||
output := e2epod.ExecCommandInContainer(f, pod.Name, ecName, "/bin/echo", "marco")
|
output := e2epod.ExecCommandInContainer(f, pod.Name, ecName, "/bin/echo", "marco")
|
||||||
gomega.Expect(output).To(gomega.ContainSubstring("marco"))
|
gomega.Expect(output).To(gomega.ContainSubstring("marco"))
|
||||||
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, pod.Namespace, pod.Name, ecName)
|
log, err := e2epod.GetPodLogs(ctx, f.ClientSet, pod.Namespace, pod.Name, ecName)
|
||||||
framework.ExpectNoError(err, "Failed to get logs for pod %q ephemeral container %q", format.Pod(pod), ecName)
|
framework.ExpectNoError(err, "Failed to get logs for pod %q ephemeral container %q", e2epod.FormatPod(pod), ecName)
|
||||||
gomega.Expect(log).To(gomega.ContainSubstring("polo"))
|
gomega.Expect(log).To(gomega.ContainSubstring("polo"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
|
||||||
"k8s.io/kubernetes/pkg/util/slice"
|
"k8s.io/kubernetes/pkg/util/slice"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
)
|
)
|
||||||
@ -154,15 +153,15 @@ func (c *PodClient) AddEphemeralContainerSync(ctx context.Context, pod *v1.Pod,
|
|||||||
namespace := c.f.Namespace.Name
|
namespace := c.f.Namespace.Name
|
||||||
|
|
||||||
podJS, err := json.Marshal(pod)
|
podJS, err := json.Marshal(pod)
|
||||||
framework.ExpectNoError(err, "error creating JSON for pod %q", format.Pod(pod))
|
framework.ExpectNoError(err, "error creating JSON for pod %q", FormatPod(pod))
|
||||||
|
|
||||||
ecPod := pod.DeepCopy()
|
ecPod := pod.DeepCopy()
|
||||||
ecPod.Spec.EphemeralContainers = append(ecPod.Spec.EphemeralContainers, *ec)
|
ecPod.Spec.EphemeralContainers = append(ecPod.Spec.EphemeralContainers, *ec)
|
||||||
ecJS, err := json.Marshal(ecPod)
|
ecJS, err := json.Marshal(ecPod)
|
||||||
framework.ExpectNoError(err, "error creating JSON for pod with ephemeral container %q", format.Pod(pod))
|
framework.ExpectNoError(err, "error creating JSON for pod with ephemeral container %q", FormatPod(pod))
|
||||||
|
|
||||||
patch, err := strategicpatch.CreateTwoWayMergePatch(podJS, ecJS, pod)
|
patch, err := strategicpatch.CreateTwoWayMergePatch(podJS, ecJS, pod)
|
||||||
framework.ExpectNoError(err, "error creating patch to add ephemeral container %q", format.Pod(pod))
|
framework.ExpectNoError(err, "error creating patch to add ephemeral container %q", FormatPod(pod))
|
||||||
|
|
||||||
// Clients may optimistically attempt to add an ephemeral container to determine whether the EphemeralContainers feature is enabled.
|
// Clients may optimistically attempt to add an ephemeral container to determine whether the EphemeralContainers feature is enabled.
|
||||||
if _, err := c.Patch(ctx, pod.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "ephemeralcontainers"); err != nil {
|
if _, err := c.Patch(ctx, pod.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "ephemeralcontainers"); err != nil {
|
||||||
@ -173,6 +172,17 @@ func (c *PodClient) AddEphemeralContainerSync(ctx context.Context, pod *v1.Pod,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FormatPod returns a string representing a pod in a consistent human readable format,
|
||||||
|
// with pod name, namespace and pod UID as part of the string.
|
||||||
|
// This code is taken from k/k/pkg/kubelet/util/format/pod.go to remove
|
||||||
|
// e2e framework -> k/k/pkg/kubelet dependency.
|
||||||
|
func FormatPod(pod *v1.Pod) string {
|
||||||
|
if pod == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s_%s(%s)", pod.Name, pod.Namespace, pod.UID)
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteSync deletes the pod and wait for the pod to disappear for `timeout`. If the pod doesn't
|
// DeleteSync deletes the pod and wait for the pod to disappear for `timeout`. If the pod doesn't
|
||||||
// disappear before the timeout, it will fail the test.
|
// disappear before the timeout, it will fail the test.
|
||||||
func (c *PodClient) DeleteSync(ctx context.Context, name string, options metav1.DeleteOptions, timeout time.Duration) {
|
func (c *PodClient) DeleteSync(ctx context.Context, name string, options metav1.DeleteOptions, timeout time.Duration) {
|
||||||
|
Loading…
Reference in New Issue
Block a user