@@ -652,6 +652,12 @@ func IsTerminatedDeployment(deployment runtime.Object) bool {
652
652
return IsCompleteDeployment (deployment ) || IsFailedDeployment (deployment )
653
653
}
654
654
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
+
655
661
// IsCompleteDeployment returns true if the passed deployment is in state complete.
656
662
func IsCompleteDeployment (deployment runtime.Object ) bool {
657
663
current := DeploymentStatusFor (deployment )
@@ -782,6 +788,37 @@ func DeploymentsForCleanup(configuration *deployapi.DeploymentConfig, deployment
782
788
return relevantDeployments
783
789
}
784
790
791
+ // GetTimeoutSecondsForStrategy returns the timeout in seconds defined in the
792
+ // deployment config strategy.
793
+ func GetTimeoutSecondsForStrategy (config * deployapi.DeploymentConfig ) int64 {
794
+ var timeoutSeconds int64
795
+ switch config .Spec .Strategy .Type {
796
+ case deployapi .DeploymentStrategyTypeRolling :
797
+ timeoutSeconds = deployapi .DefaultRollingTimeoutSeconds
798
+ if t := config .Spec .Strategy .RollingParams .TimeoutSeconds ; t != nil {
799
+ timeoutSeconds = * t
800
+ }
801
+ case deployapi .DeploymentStrategyTypeRecreate :
802
+ timeoutSeconds = deployapi .DefaultRecreateTimeoutSeconds
803
+ if t := config .Spec .Strategy .RecreateParams .TimeoutSeconds ; t != nil {
804
+ timeoutSeconds = * t
805
+ }
806
+ case deployapi .DeploymentStrategyTypeCustom :
807
+ timeoutSeconds = deployapi .DefaultRecreateTimeoutSeconds
808
+ }
809
+ return timeoutSeconds
810
+ }
811
+
812
+ // RolloutExceededTimeoutSeconds returns true if the current deployment exceeded
813
+ // the timeoutSeconds defined for its strategy.
814
+ // Note that this is different than activeDeadlineSeconds which is the timeout
815
+ // set for the deployer pod. In some cases, the deployer pod cannot be created
816
+ // (like quota, etc...). In that case deployer controller use this function to
817
+ // measure if the created deployment (RC) exceeded the timeout.
818
+ func RolloutExceededTimeoutSeconds (config * deployapi.DeploymentConfig , latestRC * v1.ReplicationController ) bool {
819
+ return int64 (time .Since (latestRC .CreationTimestamp .Time ).Seconds ()) > GetTimeoutSecondsForStrategy (config )
820
+ }
821
+
785
822
// WaitForRunningDeployerPod waits a given period of time until the deployer pod
786
823
// for given replication controller is not running.
787
824
func WaitForRunningDeployerPod (podClient kcoreclient.PodsGetter , rc * api.ReplicationController , timeout time.Duration ) error {
0 commit comments