Don't import pod util package from k/k
These are all simple changes that will not change w/o breaking API changes upstream anyway. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
@@ -2,24 +2,13 @@ package expansion
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMapReference(t *testing.T) {
|
func TestMapReference(t *testing.T) {
|
||||||
envs := []api.EnvVar{
|
envs := map[string]string{
|
||||||
{
|
"FOO": "bar",
|
||||||
Name: "FOO",
|
"ZOO": "$(FOO)-1",
|
||||||
Value: "bar",
|
"BLU": "$(ZOO)-2",
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "ZOO",
|
|
||||||
Value: "$(FOO)-1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "BLU",
|
|
||||||
Value: "$(ZOO)-2",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declaredEnv := map[string]string{
|
declaredEnv := map[string]string{
|
||||||
@@ -32,8 +21,8 @@ func TestMapReference(t *testing.T) {
|
|||||||
|
|
||||||
mapping := MappingFuncFor(declaredEnv, serviceEnv)
|
mapping := MappingFuncFor(declaredEnv, serviceEnv)
|
||||||
|
|
||||||
for _, env := range envs {
|
for k, v := range envs {
|
||||||
declaredEnv[env.Name] = Expand(env.Value, mapping)
|
declaredEnv[k] = Expand(v, mapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedEnv := map[string]string{
|
expectedEnv := map[string]string{
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
apivalidation "k8s.io/apimachinery/pkg/util/validation"
|
apivalidation "k8s.io/apimachinery/pkg/util/validation"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
podshelper "k8s.io/kubernetes/pkg/apis/core/pods"
|
podshelper "k8s.io/kubernetes/pkg/apis/core/pods"
|
||||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
|
||||||
fieldpath "k8s.io/kubernetes/pkg/fieldpath"
|
fieldpath "k8s.io/kubernetes/pkg/fieldpath"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/envvars"
|
"k8s.io/kubernetes/pkg/kubelet/envvars"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/pointer"
|
||||||
@@ -121,6 +120,10 @@ func populateContainerEnvironment(ctx context.Context, pod *corev1.Pod, containe
|
|||||||
return nil
|
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
|
// getServiceEnvVarMap makes a map[string]string of env vars for services a
|
||||||
// pod in namespace ns should see.
|
// pod in namespace ns should see.
|
||||||
// Based on getServiceEnvVarMap in kubelet_pods.go.
|
// Based on getServiceEnvVarMap in kubelet_pods.go.
|
||||||
@@ -139,7 +142,7 @@ func getServiceEnvVarMap(rm *manager.ResourceManager, ns string, enableServiceLi
|
|||||||
for i := range services {
|
for i := range services {
|
||||||
service := services[i]
|
service := services[i]
|
||||||
// ignore services where ClusterIP is "None" or empty
|
// ignore services where ClusterIP is "None" or empty
|
||||||
if !v1helper.IsServiceIPSet(service) {
|
if !isServiceIPSet(service) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
serviceName := service.Name
|
serviceName := service.Name
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "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/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
watchapi "k8s.io/apimachinery/pkg/watch"
|
watchapi "k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/client-go/tools/watch"
|
"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.
|
// 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) {
|
func (f *Framework) WaitUntilPodReady(namespace, name string) (*corev1.Pod, error) {
|
||||||
return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) {
|
return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) {
|
||||||
pod := event.Object.(*corev1.Pod)
|
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.
|
// 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) {
|
func (f *Framework) WaitUntilPodDeleted(namespace, name string) (*corev1.Pod, error) {
|
||||||
return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) {
|
return f.WaitUntilPodCondition(namespace, name, func(event watchapi.Event) (bool, error) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/virtual-kubelet/virtual-kubelet/internal/kubernetes/remotecommand"
|
"github.com/virtual-kubelet/virtual-kubelet/internal/kubernetes/remotecommand"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
remoteutils "k8s.io/client-go/tools/remotecommand"
|
remoteutils "k8s.io/client-go/tools/remotecommand"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerExecHandlerFunc defines the handler function used for "execing" into a
|
// 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) {
|
func getExecOptions(req *http.Request) (*remotecommand.Options, error) {
|
||||||
tty := req.FormValue(api.ExecTTYParam) == "1"
|
tty := req.FormValue(execTTYParam) == "1"
|
||||||
stdin := req.FormValue(api.ExecStdinParam) == "1"
|
stdin := req.FormValue(execStdinParam) == "1"
|
||||||
stdout := req.FormValue(api.ExecStdoutParam) == "1"
|
stdout := req.FormValue(execStdoutParam) == "1"
|
||||||
stderr := req.FormValue(api.ExecStderrParam) == "1"
|
stderr := req.FormValue(execStderrParam) == "1"
|
||||||
if tty && stderr {
|
if tty && stderr {
|
||||||
return nil, errors.New("cannot exec with tty and stderr")
|
return nil, errors.New("cannot exec with tty and stderr")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user