diff --git a/pkg/kubelet/network/cni/cni_test.go b/pkg/kubelet/network/cni/cni_test.go index e973309e4ba..4ca9f505c19 100644 --- a/pkg/kubelet/network/cni/cni_test.go +++ b/pkg/kubelet/network/cni/cni_test.go @@ -74,6 +74,8 @@ func installPluginUnderTest(t *testing.T, vendorName string, plugName string) { const execScriptTempl = `#!/bin/bash read ignore +env > {{.OutputEnv}} +echo "%@" >> {{.OutputEnv}} export $(echo ${CNI_ARGS} | sed 's/;/ /g') &> /dev/null mkdir -p {{.OutputDir}} &> /dev/null echo -n "$CNI_COMMAND $CNI_NETNS $K8S_POD_NAMESPACE $K8S_POD_NAME $K8S_POD_INFRA_CONTAINER_ID" >& {{.OutputFile}} @@ -81,6 +83,7 @@ echo -n "{ \"ip4\": { \"ip\": \"10.1.0.23/24\" } }" ` execTemplateData := &map[string]interface{}{ "OutputFile": path.Join(pluginDir, plugName+".out"), + "OutputEnv": path.Join(pluginDir, plugName+".env"), "OutputDir": pluginDir, } @@ -179,7 +182,13 @@ func TestCNIPlugin(t *testing.T) { if err != nil { t.Errorf("Expected nil: %v", err) } - output, err := ioutil.ReadFile(path.Join(testNetworkConfigPath, pluginName, pluginName+".out")) + outputEnv := path.Join(testNetworkConfigPath, pluginName, pluginName+".env") + eo, eerr := ioutil.ReadFile(outputEnv) + outputFile := path.Join(testNetworkConfigPath, pluginName, pluginName+".out") + output, err := ioutil.ReadFile(outputFile) + if err != nil { + t.Errorf("Failed to read output file %s: %v (env %s err %v)", outputFile, err, eo, eerr) + } expectedOutput := "ADD /proc/12345/ns/net podNamespace podName dockerid2345" if string(output) != expectedOutput { t.Errorf("Mismatch in expected output for setup hook. Expected '%s', got '%s'", expectedOutput, string(output))