forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.go
76 lines (58 loc) · 3.11 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cmd
import (
"errors"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/kubectl"
"github.com/openshift/origin/pkg/client"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deployutil "github.com/openshift/origin/pkg/deploy/util"
)
func NewDeploymentConfigStatusViewer(oc client.Interface) kubectl.StatusViewer {
return &DeploymentConfigStatusViewer{dn: oc}
}
// DeploymentConfigStatusViewer is an implementation of the kubectl StatusViewer interface
// for deployment configs.
type DeploymentConfigStatusViewer struct {
dn client.DeploymentConfigsNamespacer
}
var _ kubectl.StatusViewer = &DeploymentConfigStatusViewer{}
// Status returns a message describing deployment status, and a bool value indicating if the status is considered done
func (s *DeploymentConfigStatusViewer) Status(namespace, name string, desiredRevision int64) (string, bool, error) {
config, err := s.dn.DeploymentConfigs(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return "", false, err
}
latestRevision := config.Status.LatestVersion
if latestRevision == 0 {
switch {
case deployutil.HasImageChangeTrigger(config):
return fmt.Sprintf("Deployment config %q waiting on image update\n", name), false, nil
case len(config.Spec.Triggers) == 0:
return "", true, fmt.Errorf("Deployment config %q waiting on manual update (use 'oc rollout latest %s')", name, name)
}
}
if desiredRevision > 0 && latestRevision != desiredRevision {
return "", false, fmt.Errorf("desired revision (%d) is different from the running revision (%d)", desiredRevision, latestRevision)
}
cond := deployutil.GetDeploymentCondition(config.Status, deployapi.DeploymentProgressing)
if config.Generation <= config.Status.ObservedGeneration {
switch {
case cond != nil && cond.Reason == deployapi.NewRcAvailableReason:
return fmt.Sprintf("%s\n", cond.Message), true, nil
case cond != nil && cond.Reason == deployapi.TimedOutReason:
return "", true, errors.New(cond.Message)
case cond != nil && cond.Reason == deployapi.CancelledRolloutReason:
return "", true, errors.New(cond.Message)
case cond != nil && cond.Reason == deployapi.PausedConfigReason:
return "", true, fmt.Errorf("Deployment config %q is paused. Resume to continue watching the status of the rollout.\n", config.Name)
case config.Status.UpdatedReplicas < config.Spec.Replicas:
return fmt.Sprintf("Waiting for rollout to finish: %d out of %d new replicas have been updated...\n", config.Status.UpdatedReplicas, config.Spec.Replicas), false, nil
case config.Status.Replicas > config.Status.UpdatedReplicas:
return fmt.Sprintf("Waiting for rollout to finish: %d old replicas are pending termination...\n", config.Status.Replicas-config.Status.UpdatedReplicas), false, nil
case config.Status.AvailableReplicas < config.Status.UpdatedReplicas:
return fmt.Sprintf("Waiting for rollout to finish: %d of %d updated replicas are available...\n", config.Status.AvailableReplicas, config.Status.UpdatedReplicas), false, nil
}
}
return fmt.Sprintf("Waiting for latest deployment config spec to be observed by the controller loop...\n"), false, nil
}