github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/install/status_viewer.go (about) 1 package install 2 3 import ( 4 "fmt" 5 6 appsv1 "k8s.io/api/apps/v1" 7 corev1 "k8s.io/api/core/v1" 8 ) 9 10 const TimedOutReason = "ProgressDeadlineExceeded" 11 12 // Status returns a message describing deployment status, and a bool value indicating if the status is considered done. 13 func DeploymentStatus(deployment *appsv1.Deployment) (string, bool, error) { 14 if deployment.Generation <= deployment.Status.ObservedGeneration { 15 // check if deployment has timed out 16 progressing := getDeploymentCondition(deployment.Status, appsv1.DeploymentProgressing) 17 if progressing != nil && progressing.Reason == TimedOutReason { 18 return "", false, fmt.Errorf("deployment %q exceeded its progress deadline", deployment.Name) 19 } 20 21 if deployment.Status.Replicas > deployment.Status.UpdatedReplicas { 22 return fmt.Sprintf("deployment %q waiting for %d outdated replica(s) to be terminated", deployment.Name, deployment.Status.Replicas-deployment.Status.UpdatedReplicas), false, nil 23 } 24 25 if available := getDeploymentCondition(deployment.Status, appsv1.DeploymentAvailable); available == nil || available.Status != corev1.ConditionTrue { 26 msg := fmt.Sprintf("missing condition %q", appsv1.DeploymentAvailable) 27 if available != nil { 28 msg = available.Message 29 } 30 return fmt.Sprintf("deployment %q not available: %s", deployment.Name, msg), false, nil 31 } 32 33 return fmt.Sprintf("deployment %q is up-to-date and available", deployment.Name), true, nil 34 } 35 return fmt.Sprintf("waiting for spec update of deployment %q to be observed...", deployment.Name), false, nil 36 } 37 38 func getDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition { 39 for i := range status.Conditions { 40 c := status.Conditions[i] 41 if c.Type == condType { 42 return &c 43 } 44 } 45 return nil 46 }