Skip to content

Commit

Permalink
Add last transition time to Canary CRD status
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Nov 24, 2018
1 parent 82bf63f commit 65bd77c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/flagger/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type CanaryStatus struct {
State string `json:"state"`
CanaryRevision string `json:"canaryRevision"`
FailedChecks int `json:"failedChecks"`
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// CanaryService is used to create ClusterIP services
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/flagger/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (c *CanaryDeployer) IsNewSpec(cd *flaggerv1.Canary) (bool, error) {
// SetFailedChecks updates the canary failed checks counter
func (c *CanaryDeployer) SetFailedChecks(cd *flaggerv1.Canary, val int) error {
cd.Status.FailedChecks = val
cd.Status.LastTransitionTime = metav1.Now()
cd, err := c.flaggerClient.FlaggerV1alpha1().Canaries(cd.Namespace).Update(cd)
if err != nil {
return fmt.Errorf("deployment %s.%s update error %v", cd.Spec.TargetRef.Name, cd.Namespace, err)
Expand All @@ -137,6 +138,7 @@ func (c *CanaryDeployer) SetFailedChecks(cd *flaggerv1.Canary, val int) error {
// SetState updates the canary status state
func (c *CanaryDeployer) SetState(cd *flaggerv1.Canary, state string) error {
cd.Status.State = state
cd.Status.LastTransitionTime = metav1.Now()
cd, err := c.flaggerClient.FlaggerV1alpha1().Canaries(cd.Namespace).Update(cd)
if err != nil {
return fmt.Errorf("deployment %s.%s update error %v", cd.Spec.TargetRef.Name, cd.Namespace, err)
Expand All @@ -163,6 +165,7 @@ func (c *CanaryDeployer) SyncStatus(cd *flaggerv1.Canary, status flaggerv1.Canar
cd.Status.State = status.State
cd.Status.FailedChecks = status.FailedChecks
cd.Status.CanaryRevision = specEnc
cd.Status.LastTransitionTime = metav1.Now()
cd, err = c.flaggerClient.FlaggerV1alpha1().Canaries(cd.Namespace).Update(cd)
if err != nil {
return fmt.Errorf("deployment %s.%s update error %v", cd.Spec.TargetRef.Name, cd.Namespace, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func newTestHPA() *hpav2.HorizontalPodAutoscaler {
{
Type: "Resource",
Resource: &hpav2.ResourceMetricSource{
Name: "cpu",
Name: "cpu",
TargetAverageUtilization: int32p(99),
},
},
Expand Down

0 comments on commit 65bd77c

Please sign in to comment.