diff --git a/pkg/kubectl-argo-rollouts/info/info_test.go b/pkg/kubectl-argo-rollouts/info/info_test.go index 33515e9ad4..d7bbe161fd 100644 --- a/pkg/kubectl-argo-rollouts/info/info_test.go +++ b/pkg/kubectl-argo-rollouts/info/info_test.go @@ -1,6 +1,7 @@ package info import ( + "strconv" "testing" "time" @@ -37,6 +38,30 @@ func TestCanaryRolloutInfo(t *testing.T) { }) } +func TestCanaryRolloutInfoWeights(t *testing.T) { + rolloutObjs := testdata.NewCanaryRollout() + + t.Run("TestActualWeightWithExistingWeight", func(t *testing.T) { + t.Run("will test that actual weight for info object is set from rollout status", func(t *testing.T) { + roInfo := NewRolloutInfo(rolloutObjs.Rollouts[4], rolloutObjs.ReplicaSets, rolloutObjs.Pods, rolloutObjs.Experiments, rolloutObjs.AnalysisRuns, nil) + actualWeightString := roInfo.ActualWeight + actualWeightStringInt32, err := strconv.ParseInt(actualWeightString, 10, 32) + if err != nil { + t.Error(err) + } + assert.Equal(t, rolloutObjs.Rollouts[4].Status.Canary.Weights.Canary.Weight, int32(actualWeightStringInt32)) + }) + }) + + t.Run("TestActualWeightWithoutExistingWeight", func(t *testing.T) { + t.Run("will test that actual weight is set to SetWeight when status field does not exist", func(t *testing.T) { + //This test has a no canary weight object in the status field so we fall back to using SetWeight value + roInfo := NewRolloutInfo(rolloutObjs.Rollouts[5], rolloutObjs.ReplicaSets, rolloutObjs.Pods, rolloutObjs.Experiments, rolloutObjs.AnalysisRuns, nil) + assert.Equal(t, roInfo.SetWeight, roInfo.ActualWeight) + }) + }) +} + func TestPingPongCanaryRolloutInfo(t *testing.T) { rolloutObjs := testdata.NewCanaryRollout() roInfo := NewRolloutInfo(rolloutObjs.Rollouts[3], rolloutObjs.ReplicaSets, rolloutObjs.Pods, rolloutObjs.Experiments, rolloutObjs.AnalysisRuns, nil) diff --git a/pkg/kubectl-argo-rollouts/info/rollout_info.go b/pkg/kubectl-argo-rollouts/info/rollout_info.go index f50e778ed5..98bfffb89c 100644 --- a/pkg/kubectl-argo-rollouts/info/rollout_info.go +++ b/pkg/kubectl-argo-rollouts/info/rollout_info.go @@ -65,7 +65,11 @@ func NewRolloutInfo( } } } else { - roInfo.ActualWeight = roInfo.SetWeight + if ro.Status.Canary.Weights != nil { + roInfo.ActualWeight = fmt.Sprintf("%d", ro.Status.Canary.Weights.Canary.Weight) + } else { + roInfo.ActualWeight = roInfo.SetWeight + } } } } else if ro.Spec.Strategy.BlueGreen != nil { diff --git a/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout5.yaml b/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout5.yaml new file mode 100644 index 0000000000..2ea2c4436a --- /dev/null +++ b/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout5.yaml @@ -0,0 +1,96 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + annotations: + rollout.argoproj.io/revision: "31" + creationTimestamp: "2019-10-25T06:07:18Z" + generation: 429 + labels: + app: canary-demo-weights + app.kubernetes.io/instance: jesse-test + name: canary-demo-weights + namespace: jesse-test + resourceVersion: "28253567" + selfLink: /apis/argoproj.io/v1alpha1/namespaces/jesse-test/rollouts/canary-demo-weights + uid: b350ba76-f6ed-11e9-a15b-42010aa80033 +spec: + progressDeadlineSeconds: 30 + replicas: 5 + revisionHistoryLimit: 3 + selector: + matchLabels: + app: canary-demo-weights + strategy: + canary: + canaryService: canary-demo-preview + stableService: canary-demo-stable + trafficRouting: + smi: + rootService: root-svc # optional + trafficSplitName: rollout-example-traffic-split # optional + steps: + - setWeight: 20 + - pause: {} + - setWeight: 40 + - pause: + duration: 10s + - setWeight: 60 + - pause: + duration: 10s + - setWeight: 80 + - pause: + duration: 10s + template: + metadata: + creationTimestamp: null + labels: + app: canary-demo-weights + spec: + containers: + - image: argoproj/rollouts-demo:does-not-exist + imagePullPolicy: Always + name: canary-demo + ports: + - containerPort: 8080 + name: http + protocol: TCP + resources: + requests: + cpu: 5m + memory: 32Mi +status: + HPAReplicas: 6 + availableReplicas: 5 + blueGreen: {} + canary: + weights: + canary: + podTemplateHash: 868d98998a + serviceName: canary-demo + weight: 20 + stable: + podTemplateHash: 877894d5b + serviceName: canary-demo + weight: 60 + stableRS: 877894d5b + conditions: + - lastTransitionTime: "2019-10-25T06:07:29Z" + lastUpdateTime: "2019-10-25T06:07:29Z" + message: Rollout has minimum availability + reason: AvailableReason + status: "True" + type: Available + - lastTransitionTime: "2019-10-28T04:52:55Z" + lastUpdateTime: "2019-10-28T04:52:55Z" + message: ReplicaSet "canary-demo-65fb5ffc84" has timed out progressing. + reason: ProgressDeadlineExceeded + status: "False" + type: Progressing + currentPodHash: 65fb5ffc84 + currentStepHash: f64cdc9d + currentStepIndex: 0 + observedGeneration: "429" + readyReplicas: 5 + replicas: 6 + selector: app=canary-demo-weights + updatedReplicas: 1 diff --git a/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout6.yaml b/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout6.yaml new file mode 100644 index 0000000000..54edf27937 --- /dev/null +++ b/pkg/kubectl-argo-rollouts/info/testdata/canary/canary-rollout6.yaml @@ -0,0 +1,87 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + annotations: + rollout.argoproj.io/revision: "31" + creationTimestamp: "2019-10-25T06:07:18Z" + generation: 429 + labels: + app: canary-demo-weights-na + app.kubernetes.io/instance: jesse-test + name: canary-demo-weights-na + namespace: jesse-test + resourceVersion: "28253567" + selfLink: /apis/argoproj.io/v1alpha1/namespaces/jesse-test/rollouts/canary-demo-weights-na + uid: b350ba76-f6ed-11e9-a15b-42010aa80033 +spec: + progressDeadlineSeconds: 30 + replicas: 5 + revisionHistoryLimit: 3 + selector: + matchLabels: + app: canary-demo-weights-na + strategy: + canary: + canaryService: canary-demo-preview + stableService: canary-demo-stable + trafficRouting: + smi: + rootService: root-svc # optional + trafficSplitName: rollout-example-traffic-split # optional + steps: + - setWeight: 20 + - pause: {} + - setWeight: 40 + - pause: + duration: 10s + - setWeight: 60 + - pause: + duration: 10s + - setWeight: 80 + - pause: + duration: 10s + template: + metadata: + creationTimestamp: null + labels: + app: canary-demo-weights-na + spec: + containers: + - image: argoproj/rollouts-demo:does-not-exist + imagePullPolicy: Always + name: canary-demo + ports: + - containerPort: 8080 + name: http + protocol: TCP + resources: + requests: + cpu: 5m + memory: 32Mi +status: + HPAReplicas: 6 + availableReplicas: 5 + blueGreen: {} + canary: {} + stableRS: 877894d5b + conditions: + - lastTransitionTime: "2019-10-25T06:07:29Z" + lastUpdateTime: "2019-10-25T06:07:29Z" + message: Rollout has minimum availability + reason: AvailableReason + status: "True" + type: Available + - lastTransitionTime: "2019-10-28T04:52:55Z" + lastUpdateTime: "2019-10-28T04:52:55Z" + message: ReplicaSet "canary-demo-65fb5ffc84" has timed out progressing. + reason: ProgressDeadlineExceeded + status: "False" + type: Progressing + currentPodHash: 65fb5ffc84 + currentStepHash: f64cdc9d + currentStepIndex: 0 + observedGeneration: "429" + readyReplicas: 5 + replicas: 6 + selector: app=canary-demo-weights-na + updatedReplicas: 1