diff --git a/internal/expansion/expand_test.go b/internal/expansion/expand_test.go index 55a7f4e26..6326994f1 100644 --- a/internal/expansion/expand_test.go +++ b/internal/expansion/expand_test.go @@ -2,24 +2,13 @@ package expansion import ( "testing" - - api "k8s.io/kubernetes/pkg/apis/core" ) func TestMapReference(t *testing.T) { - envs := []api.EnvVar{ - { - Name: "FOO", - Value: "bar", - }, - { - Name: "ZOO", - Value: "$(FOO)-1", - }, - { - Name: "BLU", - Value: "$(ZOO)-2", - }, + envs := map[string]string{ + "FOO": "bar", + "ZOO": "$(FOO)-1", + "BLU": "$(ZOO)-2", } declaredEnv := map[string]string{ @@ -32,8 +21,8 @@ func TestMapReference(t *testing.T) { mapping := MappingFuncFor(declaredEnv, serviceEnv) - for _, env := range envs { - declaredEnv[env.Name] = Expand(env.Value, mapping) + for k, v := range envs { + declaredEnv[k] = Expand(v, mapping) } expectedEnv := map[string]string{ diff --git a/internal/podutils/env.go b/internal/podutils/env.go index 2914589f1..b78faaa8e 100644 --- a/internal/podutils/env.go +++ b/internal/podutils/env.go @@ -30,7 +30,6 @@ import ( apivalidation "k8s.io/apimachinery/pkg/util/validation" "k8s.io/client-go/tools/record" podshelper "k8s.io/kubernetes/pkg/apis/core/pods" - v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper" fieldpath "k8s.io/kubernetes/pkg/fieldpath" "k8s.io/kubernetes/pkg/kubelet/envvars" "k8s.io/utils/pointer" @@ -121,6 +120,10 @@ func populateContainerEnvironment(ctx context.Context, pod *corev1.Pod, containe return nil } +func isServiceIPSet(service *corev1.Service) bool { + return service.Spec.ClusterIP != corev1.ClusterIPNone && service.Spec.ClusterIP != "" +} + // getServiceEnvVarMap makes a map[string]string of env vars for services a // pod in namespace ns should see. // Based on getServiceEnvVarMap in kubelet_pods.go. @@ -139,7 +142,7 @@ func getServiceEnvVarMap(rm *manager.ResourceManager, ns string, enableServiceLi for i := range services { service := services[i] // ignore services where ClusterIP is "None" or empty - if !v1helper.IsServiceIPSet(service) { + if !isServiceIPSet(service) { continue } serviceName := service.Name diff --git a/internal/test/e2e/framework/pod.go b/internal/test/e2e/framework/pod.go index 7a3f93d79..0d2e46ed7 100644 --- a/internal/test/e2e/framework/pod.go +++ b/internal/test/e2e/framework/pod.go @@ -6,13 +6,13 @@ import ( "strings" corev1 "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" watchapi "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/watch" - podutil "k8s.io/kubernetes/pkg/api/v1/pod" ) // CreateDummyPodObjectWithPrefix creates a dujmmy pod object using the specified prefix as the value of .metadata.generateName. @@ -101,10 +101,20 @@ func (f *Framework) WaitUntilPodCondition(namespace, name string, fn watch.Condi func (f *Framework) WaitUntilPodReady(namespace, name string) (*corev1.Pod, error) { return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) { pod := event.Object.(*corev1.Pod) - return pod.Status.Phase == corev1.PodRunning && podutil.IsPodReady(pod) && pod.Status.PodIP != "", nil + return pod.Status.Phase == corev1.PodRunning && IsPodReady(pod) && pod.Status.PodIP != "", nil }) } +// IsPodReady returns true if a pod is ready. +func IsPodReady(pod *v1.Pod) bool { + for _, cond := range pod.Status.Conditions { + if cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue { + return true + } + } + return false +} + // WaitUntilPodDeleted blocks until the pod with the specified name and namespace is deleted from apiserver. func (f *Framework) WaitUntilPodDeleted(namespace, name string) (*corev1.Pod, error) { return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) { diff --git a/node/api/exec.go b/node/api/exec.go index b1eca4b7d..9f493199a 100644 --- a/node/api/exec.go +++ b/node/api/exec.go @@ -27,7 +27,6 @@ import ( "github.com/virtual-kubelet/virtual-kubelet/internal/kubernetes/remotecommand" "k8s.io/apimachinery/pkg/types" remoteutils "k8s.io/client-go/tools/remotecommand" - api "k8s.io/kubernetes/pkg/apis/core" ) // ContainerExecHandlerFunc defines the handler function used for "execing" into a @@ -136,11 +135,18 @@ func HandleContainerExec(h ContainerExecHandlerFunc, opts ...ContainerExecHandle }) } +const ( + execTTYParam = "tty" + execStdinParam = "input" + execStdoutParam = "output" + execStderrParam = "error" +) + func getExecOptions(req *http.Request) (*remotecommand.Options, error) { - tty := req.FormValue(api.ExecTTYParam) == "1" - stdin := req.FormValue(api.ExecStdinParam) == "1" - stdout := req.FormValue(api.ExecStdoutParam) == "1" - stderr := req.FormValue(api.ExecStderrParam) == "1" + tty := req.FormValue(execTTYParam) == "1" + stdin := req.FormValue(execStdinParam) == "1" + stdout := req.FormValue(execStdoutParam) == "1" + stderr := req.FormValue(execStderrParam) == "1" if tty && stderr { return nil, errors.New("cannot exec with tty and stderr") }