diff --git a/pkg/commands/service/export.go b/pkg/commands/service/export.go index fb653cc15..6f7db33a2 100644 --- a/pkg/commands/service/export.go +++ b/pkg/commands/service/export.go @@ -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) diff --git a/test/e2e/service_export_test.go b/test/e2e/service_export_test.go index 816cbbe20..4bee2b4e6 100644 --- a/test/e2e/service_export_test.go +++ b/test/e2e/service_export_test.go @@ -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),