Skip to content

Commit

Permalink
Merge pull request #14923 from aveshagarwal/master-rhbz-1449891
Browse files Browse the repository at this point in the history
UPSTREAM: kubernetes-incubator/cluster-capacity: 81: Fix cluster-capacity to avoid pending pods not created by it.
  • Loading branch information
eparis committed Jun 28, 2017
2 parents 3ff2db7 + 75c4fb6 commit 478cfe2
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -51,6 +51,10 @@ import (
"github.com/kubernetes-incubator/cluster-capacity/pkg/framework/strategy"
)

const (
podProvisioner = "cc.kubernetes.io/provisioned-by"
)

type ClusterCapacity struct {
// caches modified by emulation strategy
resourceStore store.ResourceStore
Expand Down Expand Up @@ -210,7 +214,9 @@ func (c *ClusterCapacity) Close() {

func (c *ClusterCapacity) Update(pod *v1.Pod, podCondition *v1.PodCondition, schedulerName string) error {
stop := podCondition.Type == v1.PodScheduled && podCondition.Status == v1.ConditionFalse && podCondition.Reason == "Unschedulable"
if stop {

// Only for pending pods provisioned by cluster-capacity
if stop && metav1.HasAnnotation(pod.ObjectMeta, podProvisioner) {
c.status.StopReason = fmt.Sprintf("%v: %v", podCondition.Reason, podCondition.Message)
c.Close()
// The Update function can be run more than once before any corresponding
Expand All @@ -235,6 +241,14 @@ func (c *ClusterCapacity) nextPod() error {
// use simulated pod name with an index to construct the name
pod.ObjectMeta.Name = fmt.Sprintf("%v-%v", c.simulatedPod.Name, c.simulated)

// Add pod provisioner annotation
if pod.ObjectMeta.Annotations == nil {
pod.ObjectMeta.Annotations = map[string]string{}
}

// Stores the scheduler name
pod.ObjectMeta.Annotations[podProvisioner] = c.defaultScheduler

c.simulated++
c.lastSimulatedPod = &pod

Expand Down

0 comments on commit 478cfe2

Please sign in to comment.