Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use actual weight from status field on rollout object #1937

Merged
merged 10 commits into from
Apr 1, 2022
16 changes: 16 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,21 @@ func TestCanaryRolloutInfo(t *testing.T) {
})
}

func TestCanaryRolloutInfoWeights(t *testing.T) {
rolloutObjs := testdata.NewCanaryRollout()
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))

//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)
Copy link
Contributor

@leoluz leoluz Mar 31, 2022

Choose a reason for hiding this comment

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

More as a suggestion but there is a more interesting pattern to use in tests when you want to validate 2 different scenarios like what you are doing. Instead of mixing the 2 scenarios in one single test case we can leverage testing.Run to run nested executions making more evident what exactly your are testing. See this example.

Advantages are:

  • Easier to understand what the test is doing
  • Test description in plain english
  • Better report when test fail
  • Running tests in parallel

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
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
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