|
|
|
|
@@ -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},
|
|
|
|
|
},
|
|
|
|
|
|