mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Passing pod UUID to Kubelet.
This commit is contained in:
@@ -40,14 +40,14 @@ type fakeKubelet struct {
|
||||
rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
||||
machineInfoFunc func() (*info.MachineInfo, error)
|
||||
logFunc func(w http.ResponseWriter, req *http.Request)
|
||||
runFunc func(podFullName, containerName string, cmd []string) ([]byte, error)
|
||||
runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetPodInfo(name string) (api.PodInfo, error) {
|
||||
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
||||
return fk.infoFunc(name)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetContainerInfo(podFullName, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
func (fk *fakeKubelet) GetContainerInfo(podFullName, uuid, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
||||
return fk.containerInfoFunc(podFullName, containerName, req)
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ func (fk *fakeKubelet) ServeLogs(w http.ResponseWriter, req *http.Request) {
|
||||
fk.logFunc(w, req)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) RunInContainer(podFullName, containerName string, cmd []string) ([]byte, error) {
|
||||
return fk.runFunc(podFullName, containerName, cmd)
|
||||
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
return fk.runFunc(podFullName, uuid, containerName, cmd)
|
||||
}
|
||||
|
||||
type serverTestFramework struct {
|
||||
@@ -301,7 +301,7 @@ func TestServeRunInContainer(t *testing.T) {
|
||||
expectedPodName := podName + ".etcd"
|
||||
expectedContainerName := "baz"
|
||||
expectedCommand := "ls -a"
|
||||
fw.fakeKubelet.runFunc = func(podFullName, containerName string, cmd []string) ([]byte, error) {
|
||||
fw.fakeKubelet.runFunc = func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
if podFullName != expectedPodName {
|
||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||
}
|
||||
@@ -332,3 +332,46 @@ func TestServeRunInContainer(t *testing.T) {
|
||||
t.Errorf("expected %s, got %s", output, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeRunInContainerWithUUID(t *testing.T) {
|
||||
fw := newServerTest()
|
||||
output := "foo bar"
|
||||
podName := "foo"
|
||||
expectedPodName := podName + ".etcd"
|
||||
expectedUuid := "7e00838d_-_3523_-_11e4_-_8421_-_42010af0a720"
|
||||
expectedContainerName := "baz"
|
||||
expectedCommand := "ls -a"
|
||||
fw.fakeKubelet.runFunc = func(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||
if podFullName != expectedPodName {
|
||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||
}
|
||||
if uuid != expectedUuid {
|
||||
t.Errorf("expected %s, got %s", expectedUuid, uuid)
|
||||
}
|
||||
if containerName != expectedContainerName {
|
||||
t.Errorf("expected %s, got %s", expectedContainerName, containerName)
|
||||
}
|
||||
if strings.Join(cmd, " ") != expectedCommand {
|
||||
t.Errorf("expected: %s, got %v", expectedCommand, cmd)
|
||||
}
|
||||
|
||||
return []byte(output), nil
|
||||
}
|
||||
|
||||
resp, err := http.Get(fw.testHTTPServer.URL + "/run/" + podName + "/" + expectedUuid + "/" + expectedContainerName + "?cmd=ls%20-a")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Got error GETing: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
// copying the response body did not work
|
||||
t.Errorf("Cannot copy resp: %#v", err)
|
||||
}
|
||||
result := string(body)
|
||||
if result != output {
|
||||
t.Errorf("expected %s, got %s", output, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user