Skip to content

Commit

Permalink
remove workloadRef annotation after switch to inline template
Browse files Browse the repository at this point in the history
- e2e test added

Signed-off-by: Hui Kang <[email protected]>
  • Loading branch information
Hui Kang committed Jul 3, 2021
1 parent ab451dc commit 990c469
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions rollout/temlateref.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func remarshalMap(objMap map[string]interface{}, res interface{}) error {
// Resolve verifies if given rollout has template reference and resolves pod template
func (r *informerBasedTemplateResolver) Resolve(rollout *v1alpha1.Rollout) error {
if rollout.Spec.WorkloadRef == nil {
annotations.RemoveRolloutWorkloadRefGeneration(rollout)
return nil
}

Expand Down
32 changes: 32 additions & 0 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,38 @@ spec:
ExpectServiceSelector("rollout-bluegreen-active", map[string]string{"app": "rollout-ref-deployment"}, true).
ExpectRollout("Resolved template not persisted", func(rollout *v1alpha1.Rollout) bool {
return rollout.Spec.Selector == nil && len(rollout.Spec.Template.Spec.Containers) == 0
}).
When().
ApplyManifests(`
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-ref-deployment
spec:
replicas: 1
selector:
matchLabels:
app: rollout-bluegreen
progressDeadlineSeconds: 5
revisionHistoryLimit: 2
strategy:
blueGreen:
activeService: rollout-bluegreen-active
template:
metadata:
labels:
app: rollout-bluegreen
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:blue
`).WaitForRolloutStatus("Healthy").
Then().
ExpectRollout("WorkloadObservedGeneration must be removed after switch to inline template", func(r *v1alpha1.Rollout) bool {
if r.Status.WorkloadObservedGeneration != "" {
return false
}
return true
})
}

Expand Down
8 changes: 8 additions & 0 deletions utils/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func SetRolloutWorkloadRefGeneration(rollout *v1alpha1.Rollout, workloadGenerati
return false
}

// RemoveRolloutWorkloadRefGeneration remove the annotation of workload ref generation
func RemoveRolloutWorkloadRefGeneration(rollout *v1alpha1.Rollout) {
if rollout.Annotations == nil {
return
}
delete(rollout.Annotations, WorkloadGenerationAnnotation)
}

// SetReplicasAnnotations sets the desiredReplicas into the annotations
func SetReplicasAnnotations(rs *appsv1.ReplicaSet, desiredReplicas int32) bool {
if rs.Annotations == nil {
Expand Down
7 changes: 7 additions & 0 deletions utils/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ func TestAnnotationUtils(t *testing.T) {
t.Errorf("WorkloadGeneration Expected=2 Obtained=%s", copyRollout.Annotations[WorkloadGenerationAnnotation])
}
})
t.Run("RemoveRolloutWorkloadRefGeneration", func(t *testing.T) {
copyRollout := tRollout.DeepCopy()
copyRollout.Annotations = map[string]string{WorkloadGenerationAnnotation: "2"}
RemoveRolloutWorkloadRefGeneration(copyRollout)
_, ok := copyRollout.Annotations[WorkloadGenerationAnnotation]
assert.False(t, ok)
})

t.Run("SetRolloutRevisionAlreadySet", func(t *testing.T) {
copyRollout := tRollout.DeepCopy()
Expand Down
4 changes: 2 additions & 2 deletions utils/rollout/rolloututil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetRolloutPhase(ro *v1alpha1.Rollout) (v1alpha1.RolloutPhase, string) {
return v1alpha1.RolloutPhaseProgressing, "waiting for rollout spec update to be observed"
}

if !isWorkloadGenerationObserved(ro) {
if ro.Spec.TemplateResolvedFromRef && !isWorkloadGenerationObserved(ro) {
return v1alpha1.RolloutPhaseProgressing, "waiting for rollout spec update to be observed for the reference workload"
}

Expand Down Expand Up @@ -50,7 +50,7 @@ func isWorkloadGenerationObserved(ro *v1alpha1.Rollout) bool {
return true
}
workloadGeneration, _ := annotations.GetWorkloadGenerationAnnotation(ro)
observedWorkloadGen, err := strconv.Atoi(ro.Status.WorkloadObservedGeneration)
observedWorkloadGen, err := strconv.ParseInt(ro.Status.WorkloadObservedGeneration, 10, 32)
if err != nil {
return true
}
Expand Down

0 comments on commit 990c469

Please sign in to comment.