Skip to content
25 changes: 25 additions & 0 deletions pkg/kubectl-argo-rollouts/info/info_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package info

import (
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubectl-argo-rollouts/info/rollout_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good..what happens for bluegreen ? is there a different object with weight?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement can not be hit for blue green and blue green dose not have the ability to have a weight set as well. It dose not exist in the status object.

} else {
roInfo.ActualWeight = roInfo.SetWeight
}
}
}
} else if ro.Spec.Strategy.BlueGreen != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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