Fix/1946 traffic split export (#2007)

* fix(service): include lastest revision in kn service export

* fix(e2e_test) add revisionName to export service test

* chore: format code
This commit is contained in:
thiagomedina 2025-07-23 06:53:08 -03:00 committed by GitHub
parent 8216e64a8b
commit 268aba6929
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -177,6 +177,11 @@ func exportLatestService(latestSvc *servingv1.Service, withRoutes bool) *serving
if withRoutes {
exportedSvc.Spec.RouteSpec = latestSvc.Spec.RouteSpec
for i := range exportedSvc.Spec.RouteSpec.Traffic {
if exportedSvc.Spec.RouteSpec.Traffic[i].LatestRevision != nil && *exportedSvc.Spec.RouteSpec.Traffic[i].LatestRevision {
exportedSvc.Spec.RouteSpec.Traffic[i].RevisionName = latestSvc.Status.LatestReadyRevisionName
}
}
}
stripIgnoredAnnotationsFromService(&exportedSvc)

View File

@ -72,6 +72,9 @@ func TestServiceExport(t *testing.T) {
servingtest.WithConfigSpec(test.BuildConfigurationSpec()),
servingtest.WithBYORevisionName("hello-rev2"),
test.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
func(s *servingv1.Service) {
s.Spec.Traffic[0].RevisionName = "hello-rev2"
},
servingtest.WithEnv(corev1.EnvVar{Name: "a", Value: "mouse"}),
)),
), "--with-revisions", "--mode", "replay", "-o", "yaml")
@ -82,6 +85,9 @@ func TestServiceExport(t *testing.T) {
servingtest.WithBYORevisionName("hello-rev2"),
test.WithTrafficSpec([]string{"latest"}, []int{100}, []string{""}),
servingtest.WithEnv(corev1.EnvVar{Name: "a", Value: "mouse"}),
func(s *servingv1.Service) {
s.Spec.Traffic[0].RevisionName = "hello-rev2"
},
), test.BuildKNExportWithOptions(), "--with-revisions", "--mode", "export", "-o", "yaml")
t.Log("update service with tag and split traffic")
@ -102,6 +108,9 @@ func TestServiceExport(t *testing.T) {
servingtest.WithBYORevisionName("hello-rev2"),
test.WithTrafficSpec([]string{"latest", "hello-rev1"}, []int{98, 2}, []string{"", "candidate"}),
servingtest.WithEnv(corev1.EnvVar{Name: "a", Value: "mouse"}),
func(s *servingv1.Service) {
s.Spec.Traffic[0].RevisionName = "hello-rev2"
},
)),
), "--with-revisions", "--mode", "replay", "-o", "yaml")
@ -111,6 +120,9 @@ func TestServiceExport(t *testing.T) {
servingtest.WithBYORevisionName("hello-rev2"),
test.WithTrafficSpec([]string{"latest", "hello-rev1"}, []int{98, 2}, []string{"", "candidate"}),
servingtest.WithEnv(corev1.EnvVar{Name: "a", Value: "mouse"}),
func(s *servingv1.Service) {
s.Spec.Traffic[0].RevisionName = "hello-rev2"
},
), test.BuildKNExportWithOptions(
test.WithKNRevision(*(test.BuildRevision("hello-rev1",
servingtest.WithRevisionAnn("client.knative.dev/user-image", userImage),