Skip to content

Commit f6388e5

Browse files
committed
apps: deployment config stuck in the new state should respect timeoutSecods
1 parent 05d2e14 commit f6388e5

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

pkg/apps/apis/apps/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const (
113113
DeploymentCancelledNewerDeploymentExists = "newer deployment was found running"
114114
DeploymentFailedUnrelatedDeploymentExists = "unrelated pod with the same name as this deployment is already running"
115115
DeploymentFailedDeployerPodNoLongerExists = "deployer pod no longer exists"
116+
DeploymentFailedUnableToCreateDeployerPod = "unable to create deployer pod"
116117
)
117118

118119
// DeploymentStatus describes the possible states a deployment can be in.

pkg/apps/controller/deployer/deployer_controller.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ func (c *DeploymentController) handle(deployment *v1.ReplicationController, will
127127
}
128128
break
129129
}
130+
// In case the deployment is stuck in "new" state because we fail to create
131+
// deployer pod (quota, etc..) we should respect the timeoutSeconds in the
132+
// config strategy and transition the rollout to failed instead of waiting for
133+
// the deployment pod forever.
134+
config, err := deployutil.DecodeDeploymentConfig(deployment, c.codec)
135+
if err != nil {
136+
return err
137+
}
138+
if deployutil.RolloutExceededTimeoutSeconds(config, deployment) {
139+
nextStatus = deployapi.DeploymentStatusFailed
140+
updatedAnnotations[deployapi.DeploymentStatusReasonAnnotation] = deployapi.DeploymentFailedUnableToCreateDeployerPod
141+
break
142+
}
130143

131144
switch {
132145
case kerrors.IsNotFound(deployerErr):

pkg/apps/controller/deploymentconfig/deploymentconfig_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
128128
return err
129129
}
130130
}
131+
131132
// Process triggers and start an initial rollouts
132133
configCopy, err := deployutil.DeploymentConfigDeepCopy(config)
133134
if err != nil {

pkg/apps/util/util.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ func IsTerminatedDeployment(deployment runtime.Object) bool {
652652
return IsCompleteDeployment(deployment) || IsFailedDeployment(deployment)
653653
}
654654

655+
// IsNewDeployment returns true if the passed deployment is in new state.
656+
func IsNewDeployment(deployment runtime.Object) bool {
657+
current := DeploymentStatusFor(deployment)
658+
return current == deployapi.DeploymentStatusNew
659+
}
660+
655661
// IsCompleteDeployment returns true if the passed deployment is in state complete.
656662
func IsCompleteDeployment(deployment runtime.Object) bool {
657663
current := DeploymentStatusFor(deployment)
@@ -782,6 +788,23 @@ func DeploymentsForCleanup(configuration *deployapi.DeploymentConfig, deployment
782788
return relevantDeployments
783789
}
784790

791+
func RolloutExceededTimeoutSeconds(config *deployapi.DeploymentConfig, latestRC *v1.ReplicationController) bool {
792+
var timeoutSeconds int64
793+
if params := config.Spec.Strategy.RollingParams; params != nil {
794+
timeoutSeconds = deployapi.DefaultRollingTimeoutSeconds
795+
if params.TimeoutSeconds != nil {
796+
timeoutSeconds = *params.TimeoutSeconds
797+
}
798+
}
799+
if params := config.Spec.Strategy.RecreateParams; params != nil {
800+
timeoutSeconds = deployapi.DefaultRecreateTimeoutSeconds
801+
if params.TimeoutSeconds != nil {
802+
timeoutSeconds = *params.TimeoutSeconds
803+
}
804+
}
805+
return int64(time.Since(latestRC.CreationTimestamp.Time)*time.Second) > timeoutSeconds
806+
}
807+
785808
// WaitForRunningDeployerPod waits a given period of time until the deployer pod
786809
// for given replication controller is not running.
787810
func WaitForRunningDeployerPod(podClient kcoreclient.PodsGetter, rc *api.ReplicationController, timeout time.Duration) error {

0 commit comments

Comments
 (0)