From 068a7eb415aef550a87557970818c8772bd79cbd Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Fri, 18 Nov 2016 12:55:57 -0800 Subject: [PATCH] test/utils --- test/utils/conditions.go | 31 +++--- test/utils/density_utils.go | 5 +- test/utils/pod_store.go | 26 ++--- test/utils/runners.go | 185 ++++++++++++++++++------------------ 4 files changed, 126 insertions(+), 121 deletions(-) diff --git a/test/utils/conditions.go b/test/utils/conditions.go index 023e84694ed..fc9bb1e1c98 100644 --- a/test/utils/conditions.go +++ b/test/utils/conditions.go @@ -18,33 +18,34 @@ package utils import ( "fmt" - "k8s.io/kubernetes/pkg/api" + + "k8s.io/kubernetes/pkg/api/v1" ) type ContainerFailures struct { - status *api.ContainerStateTerminated + status *v1.ContainerStateTerminated Restarts int } // PodRunningReady checks whether pod p's phase is running and it has a ready // condition of status true. -func PodRunningReady(p *api.Pod) (bool, error) { +func PodRunningReady(p *v1.Pod) (bool, error) { // Check the phase is running. - if p.Status.Phase != api.PodRunning { + if p.Status.Phase != v1.PodRunning { return false, fmt.Errorf("want pod '%s' on '%s' to be '%v' but was '%v'", - p.ObjectMeta.Name, p.Spec.NodeName, api.PodRunning, p.Status.Phase) + p.ObjectMeta.Name, p.Spec.NodeName, v1.PodRunning, p.Status.Phase) } // Check the ready condition is true. if !PodReady(p) { return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v", - p.ObjectMeta.Name, p.Spec.NodeName, api.PodReady, api.ConditionTrue, p.Status.Conditions) + p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionTrue, p.Status.Conditions) } return true, nil } -func PodRunningReadyOrSucceeded(p *api.Pod) (bool, error) { +func PodRunningReadyOrSucceeded(p *v1.Pod) (bool, error) { // Check if the phase is succeeded. - if p.Status.Phase == api.PodSucceeded { + if p.Status.Phase == v1.PodSucceeded { return true, nil } return PodRunningReady(p) @@ -54,7 +55,7 @@ func PodRunningReadyOrSucceeded(p *api.Pod) (bool, error) { // information for containers that have failed or been restarted. // A map is returned where the key is the containerID and the value is a // struct containing the restart and failure information -func FailedContainers(pod *api.Pod) map[string]ContainerFailures { +func FailedContainers(pod *v1.Pod) map[string]ContainerFailures { var state ContainerFailures states := make(map[string]ContainerFailures) @@ -85,7 +86,7 @@ func FailedContainers(pod *api.Pod) map[string]ContainerFailures { // TerminatedContainers inspects all containers in a pod and returns a map // of "container name: termination reason", for all currently terminated // containers. -func TerminatedContainers(pod *api.Pod) map[string]string { +func TerminatedContainers(pod *v1.Pod) map[string]string { states := make(map[string]string) statuses := pod.Status.ContainerStatuses if len(statuses) == 0 { @@ -100,20 +101,20 @@ func TerminatedContainers(pod *api.Pod) map[string]string { } // PodNotReady checks whether pod p's has a ready condition of status false. -func PodNotReady(p *api.Pod) (bool, error) { +func PodNotReady(p *v1.Pod) (bool, error) { // Check the ready condition is false. if PodReady(p) { return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v", - p.ObjectMeta.Name, p.Spec.NodeName, api.PodReady, api.ConditionFalse, p.Status.Conditions) + p.ObjectMeta.Name, p.Spec.NodeName, v1.PodReady, v1.ConditionFalse, p.Status.Conditions) } return true, nil } // podReady returns whether pod has a condition of Ready with a status of true. -// TODO: should be replaced with api.IsPodReady -func PodReady(pod *api.Pod) bool { +// TODO: should be replaced with v1.IsPodReady +func PodReady(pod *v1.Pod) bool { for _, cond := range pod.Status.Conditions { - if cond.Type == api.PodReady && cond.Status == api.ConditionTrue { + if cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue { return true } } diff --git a/test/utils/density_utils.go b/test/utils/density_utils.go index 148eb3ab05d..234fee897e5 100644 --- a/test/utils/density_utils.go +++ b/test/utils/density_utils.go @@ -23,7 +23,8 @@ import ( "k8s.io/kubernetes/pkg/api" apierrs "k8s.io/kubernetes/pkg/api/errors" - clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + "k8s.io/kubernetes/pkg/api/v1" + clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5" "github.com/golang/glog" ) @@ -57,7 +58,7 @@ func AddLabelsToNode(c clientset.Interface, nodeName string, labels map[string]s // RemoveLabelOffNode is for cleaning up labels temporarily added to node, // won't fail if target label doesn't exist or has been removed. func RemoveLabelOffNode(c clientset.Interface, nodeName string, labelKeys []string) error { - var node *api.Node + var node *v1.Node var err error for attempt := 0; attempt < retries; attempt++ { node, err = c.Core().Nodes().Get(nodeName) diff --git a/test/utils/pod_store.go b/test/utils/pod_store.go index d7700ffdc01..712943c38f6 100644 --- a/test/utils/pod_store.go +++ b/test/utils/pod_store.go @@ -17,16 +17,16 @@ limitations under the License. package utils import ( - "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/client/cache" - clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/watch" ) -// Convenient wrapper around cache.Store that returns list of api.Pod instead of interface{}. +// Convenient wrapper around cache.Store that returns list of v1.Pod instead of interface{}. type PodStore struct { cache.Store stopCh chan struct{} @@ -35,30 +35,30 @@ type PodStore struct { func NewPodStore(c clientset.Interface, namespace string, label labels.Selector, field fields.Selector) *PodStore { lw := &cache.ListWatch{ - ListFunc: func(options api.ListOptions) (runtime.Object, error) { - options.LabelSelector = label - options.FieldSelector = field + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + options.LabelSelector = label.String() + options.FieldSelector = field.String() obj, err := c.Core().Pods(namespace).List(options) return runtime.Object(obj), err }, - WatchFunc: func(options api.ListOptions) (watch.Interface, error) { - options.LabelSelector = label - options.FieldSelector = field + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + options.LabelSelector = label.String() + options.FieldSelector = field.String() return c.Core().Pods(namespace).Watch(options) }, } store := cache.NewStore(cache.MetaNamespaceKeyFunc) stopCh := make(chan struct{}) - reflector := cache.NewReflector(lw, &api.Pod{}, store, 0) + reflector := cache.NewReflector(lw, &v1.Pod{}, store, 0) reflector.RunUntil(stopCh) return &PodStore{Store: store, stopCh: stopCh, Reflector: reflector} } -func (s *PodStore) List() []*api.Pod { +func (s *PodStore) List() []*v1.Pod { objects := s.Store.List() - pods := make([]*api.Pod, 0) + pods := make([]*v1.Pod, 0) for _, o := range objects { - pods = append(pods, o.(*api.Pod)) + pods = append(pods, o.(*v1.Pod)) } return pods } diff --git a/test/utils/runners.go b/test/utils/runners.go index 8a1a1e98a46..a6a50d1036a 100644 --- a/test/utils/runners.go +++ b/test/utils/runners.go @@ -27,8 +27,10 @@ import ( apierrs "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/resource" "k8s.io/kubernetes/pkg/api/unversioned" - "k8s.io/kubernetes/pkg/apis/extensions" - clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + "k8s.io/kubernetes/pkg/api/v1" + extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" + "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util/sets" @@ -45,6 +47,7 @@ const ( type RCConfig struct { Client clientset.Interface + InternalClient internalclientset.Interface Image string Command []string Name string @@ -57,8 +60,8 @@ type RCConfig struct { CpuLimit int64 // millicores MemRequest int64 // bytes MemLimit int64 // bytes - ReadinessProbe *api.Probe - DNSPolicy *api.DNSPolicy + ReadinessProbe *v1.Probe + DNSPolicy *v1.DNSPolicy // Env vars, set the same for every pod. Env map[string]string @@ -74,12 +77,12 @@ type RCConfig struct { // Ports to declare in the container as host and container ports. HostPorts map[string]int - Volumes []api.Volume - VolumeMounts []api.VolumeMount + Volumes []v1.Volume + VolumeMounts []v1.VolumeMount // Pointer to a list of pods; if non-nil, will be set to a list of pods // created by this RC by RunRC. - CreatedPods *[]*api.Pod + CreatedPods *[]*v1.Pod // Maximum allowable container failures. If exceeded, RunRC returns an error. // Defaults to replicas*0.1 if unspecified. @@ -159,7 +162,7 @@ func (p PodDiff) String(ignorePhases sets.String) string { } // Diff computes a PodDiff given 2 lists of pods. -func Diff(oldPods []*api.Pod, curPods []*api.Pod) PodDiff { +func Diff(oldPods []*v1.Pod, curPods []*v1.Pod) PodDiff { podInfoMap := PodDiff{} // New pods will show up in the curPods list but not in oldPods. They have oldhostname/phase == nonexist. @@ -192,27 +195,27 @@ func RunDeployment(config DeploymentConfig) error { func (config *DeploymentConfig) create() error { deployment := &extensions.Deployment{ - ObjectMeta: api.ObjectMeta{ + ObjectMeta: v1.ObjectMeta{ Name: config.Name, }, Spec: extensions.DeploymentSpec{ - Replicas: int32(config.Replicas), + Replicas: func(i int) *int32 { x := int32(i); return &x }(config.Replicas), Selector: &unversioned.LabelSelector{ MatchLabels: map[string]string{ "name": config.Name, }, }, - Template: api.PodTemplateSpec{ - ObjectMeta: api.ObjectMeta{ + Template: v1.PodTemplateSpec{ + ObjectMeta: v1.ObjectMeta{ Labels: map[string]string{"name": config.Name}, }, - Spec: api.PodSpec{ - Containers: []api.Container{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ { Name: config.Name, Image: config.Image, Command: config.Command, - Ports: []api.ContainerPort{{ContainerPort: 80}}, + Ports: []v1.ContainerPort{{ContainerPort: 80}}, }, }, }, @@ -244,27 +247,27 @@ func RunReplicaSet(config ReplicaSetConfig) error { func (config *ReplicaSetConfig) create() error { rs := &extensions.ReplicaSet{ - ObjectMeta: api.ObjectMeta{ + ObjectMeta: v1.ObjectMeta{ Name: config.Name, }, Spec: extensions.ReplicaSetSpec{ - Replicas: int32(config.Replicas), + Replicas: func(i int) *int32 { x := int32(i); return &x }(config.Replicas), Selector: &unversioned.LabelSelector{ MatchLabels: map[string]string{ "name": config.Name, }, }, - Template: api.PodTemplateSpec{ - ObjectMeta: api.ObjectMeta{ + Template: v1.PodTemplateSpec{ + ObjectMeta: v1.ObjectMeta{ Labels: map[string]string{"name": config.Name}, }, - Spec: api.PodSpec{ - Containers: []api.Container{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ { Name: config.Name, Image: config.Image, Command: config.Command, - Ports: []api.ContainerPort{{ContainerPort: 80}}, + Ports: []v1.ContainerPort{{ContainerPort: 80}}, }, }, }, @@ -295,30 +298,30 @@ func RunRC(config RCConfig) error { } func (config *RCConfig) create() error { - dnsDefault := api.DNSDefault + dnsDefault := v1.DNSDefault if config.DNSPolicy == nil { config.DNSPolicy = &dnsDefault } - rc := &api.ReplicationController{ - ObjectMeta: api.ObjectMeta{ + rc := &v1.ReplicationController{ + ObjectMeta: v1.ObjectMeta{ Name: config.Name, }, - Spec: api.ReplicationControllerSpec{ - Replicas: int32(config.Replicas), + Spec: v1.ReplicationControllerSpec{ + Replicas: func(i int) *int32 { x := int32(i); return &x }(config.Replicas), Selector: map[string]string{ "name": config.Name, }, - Template: &api.PodTemplateSpec{ - ObjectMeta: api.ObjectMeta{ + Template: &v1.PodTemplateSpec{ + ObjectMeta: v1.ObjectMeta{ Labels: map[string]string{"name": config.Name}, }, - Spec: api.PodSpec{ - Containers: []api.Container{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ { Name: config.Name, Image: config.Image, Command: config.Command, - Ports: []api.ContainerPort{{ContainerPort: 80}}, + Ports: []v1.ContainerPort{{ContainerPort: 80}}, ReadinessProbe: config.ReadinessProbe, }, }, @@ -339,11 +342,11 @@ func (config *RCConfig) create() error { return nil } -func (config *RCConfig) applyTo(template *api.PodTemplateSpec) { +func (config *RCConfig) applyTo(template *v1.PodTemplateSpec) { if config.Env != nil { for k, v := range config.Env { c := &template.Spec.Containers[0] - c.Env = append(c.Env, api.EnvVar{Name: k, Value: v}) + c.Env = append(c.Env, v1.EnvVar{Name: k, Value: v}) } } if config.Labels != nil { @@ -360,32 +363,32 @@ func (config *RCConfig) applyTo(template *api.PodTemplateSpec) { if config.Ports != nil { for k, v := range config.Ports { c := &template.Spec.Containers[0] - c.Ports = append(c.Ports, api.ContainerPort{Name: k, ContainerPort: int32(v)}) + c.Ports = append(c.Ports, v1.ContainerPort{Name: k, ContainerPort: int32(v)}) } } if config.HostPorts != nil { for k, v := range config.HostPorts { c := &template.Spec.Containers[0] - c.Ports = append(c.Ports, api.ContainerPort{Name: k, ContainerPort: int32(v), HostPort: int32(v)}) + c.Ports = append(c.Ports, v1.ContainerPort{Name: k, ContainerPort: int32(v), HostPort: int32(v)}) } } if config.CpuLimit > 0 || config.MemLimit > 0 { - template.Spec.Containers[0].Resources.Limits = api.ResourceList{} + template.Spec.Containers[0].Resources.Limits = v1.ResourceList{} } if config.CpuLimit > 0 { - template.Spec.Containers[0].Resources.Limits[api.ResourceCPU] = *resource.NewMilliQuantity(config.CpuLimit, resource.DecimalSI) + template.Spec.Containers[0].Resources.Limits[v1.ResourceCPU] = *resource.NewMilliQuantity(config.CpuLimit, resource.DecimalSI) } if config.MemLimit > 0 { - template.Spec.Containers[0].Resources.Limits[api.ResourceMemory] = *resource.NewQuantity(config.MemLimit, resource.DecimalSI) + template.Spec.Containers[0].Resources.Limits[v1.ResourceMemory] = *resource.NewQuantity(config.MemLimit, resource.DecimalSI) } if config.CpuRequest > 0 || config.MemRequest > 0 { - template.Spec.Containers[0].Resources.Requests = api.ResourceList{} + template.Spec.Containers[0].Resources.Requests = v1.ResourceList{} } if config.CpuRequest > 0 { - template.Spec.Containers[0].Resources.Requests[api.ResourceCPU] = *resource.NewMilliQuantity(config.CpuRequest, resource.DecimalSI) + template.Spec.Containers[0].Resources.Requests[v1.ResourceCPU] = *resource.NewMilliQuantity(config.CpuRequest, resource.DecimalSI) } if config.MemRequest > 0 { - template.Spec.Containers[0].Resources.Requests[api.ResourceMemory] = *resource.NewQuantity(config.MemRequest, resource.DecimalSI) + template.Spec.Containers[0].Resources.Requests[v1.ResourceMemory] = *resource.NewQuantity(config.MemRequest, resource.DecimalSI) } if len(config.Volumes) > 0 { template.Spec.Volumes = config.Volumes @@ -405,7 +408,7 @@ type RCStartupStatus struct { Unknown int Inactive int FailedContainers int - Created []*api.Pod + Created []*v1.Pod ContainerRestartNodes sets.String } @@ -414,10 +417,10 @@ func (s *RCStartupStatus) String(name string) string { name, len(s.Created), s.Expected, s.Running, s.Pending, s.Waiting, s.Inactive, s.Terminating, s.Unknown, s.RunningButNotReady) } -func ComputeRCStartupStatus(pods []*api.Pod, expected int) RCStartupStatus { +func ComputeRCStartupStatus(pods []*v1.Pod, expected int) RCStartupStatus { startupStatus := RCStartupStatus{ Expected: expected, - Created: make([]*api.Pod, 0, expected), + Created: make([]*v1.Pod, 0, expected), ContainerRestartNodes: sets.NewString(), } for _, p := range pods { @@ -426,10 +429,10 @@ func ComputeRCStartupStatus(pods []*api.Pod, expected int) RCStartupStatus { continue } startupStatus.Created = append(startupStatus.Created, p) - if p.Status.Phase == api.PodRunning { + if p.Status.Phase == v1.PodRunning { ready := false for _, c := range p.Status.Conditions { - if c.Type == api.PodReady && c.Status == api.ConditionTrue { + if c.Type == v1.PodReady && c.Status == v1.ConditionTrue { ready = true break } @@ -444,15 +447,15 @@ func ComputeRCStartupStatus(pods []*api.Pod, expected int) RCStartupStatus { startupStatus.FailedContainers = startupStatus.FailedContainers + v.Restarts startupStatus.ContainerRestartNodes.Insert(p.Spec.NodeName) } - } else if p.Status.Phase == api.PodPending { + } else if p.Status.Phase == v1.PodPending { if p.Spec.NodeName == "" { startupStatus.Waiting++ } else { startupStatus.Pending++ } - } else if p.Status.Phase == api.PodSucceeded || p.Status.Phase == api.PodFailed { + } else if p.Status.Phase == v1.PodSucceeded || p.Status.Phase == v1.PodFailed { startupStatus.Inactive++ - } else if p.Status.Phase == api.PodUnknown { + } else if p.Status.Phase == v1.PodUnknown { startupStatus.Unknown++ } } @@ -481,7 +484,7 @@ func (config *RCConfig) start() error { if timeout <= 0 { timeout = 5 * time.Minute } - oldPods := make([]*api.Pod, 0) + oldPods := make([]*v1.Pod, 0) oldRunning := 0 lastChange := time.Now() for oldRunning != config.Replicas { @@ -537,8 +540,8 @@ func (config *RCConfig) start() error { if oldRunning != config.Replicas { // List only pods from a given replication controller. - options := api.ListOptions{LabelSelector: label} - if pods, err := config.Client.Core().Pods(api.NamespaceAll).List(options); err == nil { + options := v1.ListOptions{LabelSelector: label.String()} + if pods, err := config.Client.Core().Pods(v1.NamespaceAll).List(options); err == nil { for _, pod := range pods.Items { config.RCConfigLog("Pod %s\t%s\t%s\t%s", pod.Name, pod.Spec.NodeName, pod.Status.Phase, pod.DeletionTimestamp) @@ -555,7 +558,7 @@ func (config *RCConfig) start() error { // Optionally waits for pods to start running (if waitForRunning == true). // The number of replicas must be non-zero. func StartPods(c clientset.Interface, replicas int, namespace string, podNamePrefix string, - pod api.Pod, waitForRunning bool, logFunc func(fmt string, args ...interface{})) error { + pod v1.Pod, waitForRunning bool, logFunc func(fmt string, args ...interface{})) error { // no pod to start if replicas < 1 { panic("StartPods: number of replicas must be non-zero") @@ -596,7 +599,7 @@ waitLoop: continue waitLoop } for _, p := range pods { - if p.Status.Phase != api.PodRunning { + if p.Status.Phase != v1.PodRunning { continue waitLoop } } @@ -620,17 +623,17 @@ type TestNodePreparer interface { } type PrepareNodeStrategy interface { - PreparePatch(node *api.Node) []byte - CleanupNode(node *api.Node) *api.Node + PreparePatch(node *v1.Node) []byte + CleanupNode(node *v1.Node) *v1.Node } type TrivialNodePrepareStrategy struct{} -func (*TrivialNodePrepareStrategy) PreparePatch(*api.Node) []byte { +func (*TrivialNodePrepareStrategy) PreparePatch(*v1.Node) []byte { return []byte{} } -func (*TrivialNodePrepareStrategy) CleanupNode(node *api.Node) *api.Node { +func (*TrivialNodePrepareStrategy) CleanupNode(node *v1.Node) *v1.Node { nodeCopy := *node return &nodeCopy } @@ -647,20 +650,20 @@ func NewLabelNodePrepareStrategy(labelKey string, labelValue string) *LabelNodeP } } -func (s *LabelNodePrepareStrategy) PreparePatch(*api.Node) []byte { +func (s *LabelNodePrepareStrategy) PreparePatch(*v1.Node) []byte { labelString := fmt.Sprintf("{\"%v\":\"%v\"}", s.labelKey, s.labelValue) patch := fmt.Sprintf(`{"metadata":{"labels":%v}}`, labelString) return []byte(patch) } -func (s *LabelNodePrepareStrategy) CleanupNode(node *api.Node) *api.Node { +func (s *LabelNodePrepareStrategy) CleanupNode(node *v1.Node) *v1.Node { objCopy, err := api.Scheme.DeepCopy(*node) if err != nil { - return &api.Node{} + return &v1.Node{} } - nodeCopy, ok := (objCopy).(*api.Node) + nodeCopy, ok := (objCopy).(*v1.Node) if !ok { - return &api.Node{} + return &v1.Node{} } if node.Labels != nil && len(node.Labels[s.labelKey]) != 0 { delete(nodeCopy.Labels, s.labelKey) @@ -668,7 +671,7 @@ func (s *LabelNodePrepareStrategy) CleanupNode(node *api.Node) *api.Node { return nodeCopy } -func DoPrepareNode(client clientset.Interface, node *api.Node, strategy PrepareNodeStrategy) error { +func DoPrepareNode(client clientset.Interface, node *v1.Node, strategy PrepareNodeStrategy) error { var err error patch := strategy.PreparePatch(node) if len(patch) == 0 { @@ -693,7 +696,7 @@ func DoCleanupNode(client clientset.Interface, nodeName string, strategy Prepare return fmt.Errorf("Skipping cleanup of Node: failed to get Node %v: %v", nodeName, err) } updatedNode := strategy.CleanupNode(node) - if api.Semantic.DeepEqual(node, updatedNode) { + if v1.Semantic.DeepEqual(node, updatedNode) { return nil } if _, err = client.Core().Nodes().Update(updatedNode); err == nil { @@ -750,27 +753,27 @@ func (c *TestPodCreator) CreatePods() error { return nil } -func MakePodSpec() api.PodSpec { - return api.PodSpec{ - Containers: []api.Container{{ +func MakePodSpec() v1.PodSpec { + return v1.PodSpec{ + Containers: []v1.Container{{ Name: "pause", Image: "kubernetes/pause", - Ports: []api.ContainerPort{{ContainerPort: 80}}, - Resources: api.ResourceRequirements{ - Limits: api.ResourceList{ - api.ResourceCPU: resource.MustParse("100m"), - api.ResourceMemory: resource.MustParse("500Mi"), + Ports: []v1.ContainerPort{{ContainerPort: 80}}, + Resources: v1.ResourceRequirements{ + Limits: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + v1.ResourceMemory: resource.MustParse("500Mi"), }, - Requests: api.ResourceList{ - api.ResourceCPU: resource.MustParse("100m"), - api.ResourceMemory: resource.MustParse("500Mi"), + Requests: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + v1.ResourceMemory: resource.MustParse("500Mi"), }, }, }}, } } -func makeCreatePod(client clientset.Interface, namespace string, podTemplate *api.Pod) error { +func makeCreatePod(client clientset.Interface, namespace string, podTemplate *v1.Pod) error { var err error for attempt := 0; attempt < retries; attempt++ { if _, err := client.Core().Pods(namespace).Create(podTemplate); err == nil { @@ -781,7 +784,7 @@ func makeCreatePod(client clientset.Interface, namespace string, podTemplate *ap return fmt.Errorf("Terminal error while creating pod, won't retry: %v", err) } -func createPod(client clientset.Interface, namespace string, podCount int, podTemplate *api.Pod) error { +func createPod(client clientset.Interface, namespace string, podCount int, podTemplate *v1.Pod) error { var createError error lock := sync.Mutex{} createPodFunc := func(i int) { @@ -800,16 +803,16 @@ func createPod(client clientset.Interface, namespace string, podCount int, podTe return createError } -func createController(client clientset.Interface, controllerName, namespace string, podCount int, podTemplate *api.Pod) error { - rc := &api.ReplicationController{ - ObjectMeta: api.ObjectMeta{ +func createController(client clientset.Interface, controllerName, namespace string, podCount int, podTemplate *v1.Pod) error { + rc := &v1.ReplicationController{ + ObjectMeta: v1.ObjectMeta{ Name: controllerName, }, - Spec: api.ReplicationControllerSpec{ - Replicas: int32(podCount), + Spec: v1.ReplicationControllerSpec{ + Replicas: func(i int) *int32 { x := int32(i); return &x }(podCount), Selector: map[string]string{"name": controllerName}, - Template: &api.PodTemplateSpec{ - ObjectMeta: api.ObjectMeta{ + Template: &v1.PodTemplateSpec{ + ObjectMeta: v1.ObjectMeta{ Labels: map[string]string{"name": controllerName}, }, Spec: podTemplate.Spec, @@ -826,15 +829,15 @@ func createController(client clientset.Interface, controllerName, namespace stri return fmt.Errorf("Terminal error while creating rc, won't retry: %v", err) } -func NewCustomCreatePodStrategy(podTemplate *api.Pod) TestPodCreateStrategy { +func NewCustomCreatePodStrategy(podTemplate *v1.Pod) TestPodCreateStrategy { return func(client clientset.Interface, namespace string, podCount int) error { return createPod(client, namespace, podCount, podTemplate) } } func NewSimpleCreatePodStrategy() TestPodCreateStrategy { - basePod := &api.Pod{ - ObjectMeta: api.ObjectMeta{ + basePod := &v1.Pod{ + ObjectMeta: v1.ObjectMeta{ GenerateName: "simple-pod-", }, Spec: MakePodSpec(), @@ -844,8 +847,8 @@ func NewSimpleCreatePodStrategy() TestPodCreateStrategy { func NewSimpleWithControllerCreatePodStrategy(controllerName string) TestPodCreateStrategy { return func(client clientset.Interface, namespace string, podCount int) error { - basePod := &api.Pod{ - ObjectMeta: api.ObjectMeta{ + basePod := &v1.Pod{ + ObjectMeta: v1.ObjectMeta{ GenerateName: controllerName + "-pod-", Labels: map[string]string{"name": controllerName}, },