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: append weighted destination only when weight is mentioned #2734

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experiments/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ func TestServiceInheritPortsFromRS(t *testing.T) {
assert.NotNil(t, exCtx.templateServices["bar"])
assert.Equal(t, exCtx.templateServices["bar"].Name, "foo-bar")
assert.Equal(t, exCtx.templateServices["bar"].Spec.Ports[0].Port, int32(80))
assert.Equal(t, exCtx.templateServices["bar"].Spec.Ports[0].Name, "testport")
}

func TestServiceNameSet(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions rollout/trafficrouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ func (c *rolloutContext) calculateWeightDestinationsFromExperiment() []v1alpha1.
}
for _, templateStatus := range c.currentEx.Status.TemplateStatuses {
templateWeight := getTemplateWeight(templateStatus.Name)
weightDestinations = append(weightDestinations, v1alpha1.WeightDestination{
ServiceName: templateStatus.ServiceName,
PodTemplateHash: templateStatus.PodTemplateHash,
Weight: *templateWeight,
})
if templateWeight != nil {
weightDestinations = append(weightDestinations, v1alpha1.WeightDestination{
ServiceName: templateStatus.ServiceName,
PodTemplateHash: templateStatus.PodTemplateHash,
Weight: *templateWeight,
})
}
}
}
return weightDestinations
Expand Down
34 changes: 19 additions & 15 deletions rollout/trafficrouting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,21 @@ func TestRolloutWithExperimentStep(t *testing.T) {
SpecRef: "canary",
Replicas: pointer.Int32Ptr(1),
Weight: pointer.Int32Ptr(5),
}},
},
{
Name: "experiment-template-without-weight",
SpecRef: "stable",
Replicas: pointer.Int32Ptr(1),
}},
},
},
}
r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(1), intstr.FromInt(1), intstr.FromInt(0))
r2 := bumpVersion(r1)
r2.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{}
r1.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
SMI: &v1alpha1.SMITrafficRouting{},
}
r2.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{SMI: &v1alpha1.SMITrafficRouting{}}
r2.Spec.Strategy.Canary.CanaryService = "canary"
r2.Spec.Strategy.Canary.StableService = "stable"

Expand All @@ -273,7 +281,12 @@ func TestRolloutWithExperimentStep(t *testing.T) {
Name: "experiment-template",
ServiceName: "experiment-service",
PodTemplateHash: rs2PodHash,
}}
},
{
Name: "experiment-template-without-weight",
ServiceName: "experiment-service-without-weight",
PodTemplateHash: rs2PodHash,
}}
r2.Status.Canary.CurrentExperiment = ex.Name

f.kubeobjects = append(f.kubeobjects, rs1, rs2, canarySvc, stableSvc)
Expand All @@ -293,18 +306,13 @@ func TestRolloutWithExperimentStep(t *testing.T) {
// make sure SetWeight was called with correct value
assert.Equal(t, int32(10), desiredWeight)
assert.Equal(t, int32(5), weightDestinations[0].Weight)
assert.Len(t, weightDestinations, 1)
assert.Equal(t, ex.Status.TemplateStatuses[0].ServiceName, weightDestinations[0].ServiceName)
assert.Equal(t, ex.Status.TemplateStatuses[0].PodTemplateHash, weightDestinations[0].PodTemplateHash)
return nil
})
f.fakeTrafficRouting.On("SetHeaderRoute", mock.Anything, mock.Anything).Return(nil)
f.fakeTrafficRouting.On("VerifyWeight", mock.Anything).Return(func(desiredWeight int32, weightDestinations ...v1alpha1.WeightDestination) error {
divyansh375 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, int32(10), desiredWeight)
assert.Equal(t, int32(5), weightDestinations[0].Weight)
assert.Equal(t, ex.Status.TemplateStatuses[0].ServiceName, weightDestinations[0].ServiceName)
assert.Equal(t, ex.Status.TemplateStatuses[0].PodTemplateHash, weightDestinations[0].PodTemplateHash)
return nil
})
f.fakeTrafficRouting.On("VerifyWeight", mock.Anything, mock.Anything).Return(pointer.BoolPtr(true), nil)
f.run(getKey(r2, t))
})

Expand All @@ -319,11 +327,7 @@ func TestRolloutWithExperimentStep(t *testing.T) {
return nil
})
f.fakeTrafficRouting.On("SetHeaderRoute", mock.Anything, mock.Anything).Return(nil)
f.fakeTrafficRouting.On("VerifyWeight", mock.Anything).Return(func(desiredWeight int32, weightDestinations ...v1alpha1.WeightDestination) error {
divyansh375 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, int32(10), desiredWeight)
assert.Len(t, weightDestinations, 0)
return nil
})
f.fakeTrafficRouting.On("VerifyWeight", mock.Anything, mock.Anything).Return(pointer.BoolPtr(true), nil)
f.run(getKey(r2, t))
})
}
Expand Down
Loading