From 36762d193f2883c69b4ab00072562c266fd5c05a Mon Sep 17 00:00:00 2001 From: Stavros Kontopoulos Date: Wed, 30 Oct 2024 17:41:11 +0200 Subject: [PATCH 1/2] fix configuration reconcile loop --- pkg/reconciler/labeler/accessors.go | 9 +++++++-- pkg/reconciler/service/resources/configuration.go | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/reconciler/labeler/accessors.go b/pkg/reconciler/labeler/accessors.go index bd30b793e87c..688ababcda87 100644 --- a/pkg/reconciler/labeler/accessors.go +++ b/pkg/reconciler/labeler/accessors.go @@ -18,6 +18,7 @@ package labeler import ( "context" + "sort" "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -128,7 +129,9 @@ func updateRouteAnnotation(acc kmeta.Accessor, routeName string, diffAnn map[str return } valSet.Delete(routeName) - diffAnn[serving.RoutesAnnotationKey] = strings.Join(valSet.UnsortedList(), ",") + sorted := valSet.UnsortedList() + sort.Strings(sorted) + diffAnn[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") case !has && !remove: if len(valSet) == 0 { @@ -136,7 +139,9 @@ func updateRouteAnnotation(acc kmeta.Accessor, routeName string, diffAnn map[str return } valSet.Insert(routeName) - diffAnn[serving.RoutesAnnotationKey] = strings.Join(valSet.UnsortedList(), ",") + sorted := valSet.UnsortedList() + sort.Strings(sorted) + diffAnn[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") } } diff --git a/pkg/reconciler/service/resources/configuration.go b/pkg/reconciler/service/resources/configuration.go index 241ac7f11d54..f04662cb9b6a 100644 --- a/pkg/reconciler/service/resources/configuration.go +++ b/pkg/reconciler/service/resources/configuration.go @@ -17,6 +17,7 @@ limitations under the License. package resources import ( + "sort" "strings" corev1 "k8s.io/api/core/v1" @@ -48,7 +49,9 @@ func MakeConfigurationFromExisting(service *v1.Service, existing *v1.Configurati routeName := names.Route(service) set := labeler.GetListAnnValue(existing.Annotations, serving.RoutesAnnotationKey) set.Insert(routeName) - anns[serving.RoutesAnnotationKey] = strings.Join(set.UnsortedList(), ",") + sorted := set.UnsortedList() + sort.Strings(sorted) + anns[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") return &v1.Configuration{ ObjectMeta: metav1.ObjectMeta{ From 0bc5f1aef0c61f0f29da596f79d8546a139988d1 Mon Sep 17 00:00:00 2001 From: Stavros Kontopoulos Date: Fri, 1 Nov 2024 12:35:22 +0200 Subject: [PATCH 2/2] rename var --- pkg/reconciler/labeler/accessors.go | 12 ++++++------ pkg/reconciler/service/resources/configuration.go | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/reconciler/labeler/accessors.go b/pkg/reconciler/labeler/accessors.go index 688ababcda87..36782ca84711 100644 --- a/pkg/reconciler/labeler/accessors.go +++ b/pkg/reconciler/labeler/accessors.go @@ -129,9 +129,9 @@ func updateRouteAnnotation(acc kmeta.Accessor, routeName string, diffAnn map[str return } valSet.Delete(routeName) - sorted := valSet.UnsortedList() - sort.Strings(sorted) - diffAnn[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") + routeNames := valSet.UnsortedList() + sort.Strings(routeNames) + diffAnn[serving.RoutesAnnotationKey] = strings.Join(routeNames, ",") case !has && !remove: if len(valSet) == 0 { @@ -139,9 +139,9 @@ func updateRouteAnnotation(acc kmeta.Accessor, routeName string, diffAnn map[str return } valSet.Insert(routeName) - sorted := valSet.UnsortedList() - sort.Strings(sorted) - diffAnn[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") + routeNames := valSet.UnsortedList() + sort.Strings(routeNames) + diffAnn[serving.RoutesAnnotationKey] = strings.Join(routeNames, ",") } } diff --git a/pkg/reconciler/service/resources/configuration.go b/pkg/reconciler/service/resources/configuration.go index f04662cb9b6a..6cede2877237 100644 --- a/pkg/reconciler/service/resources/configuration.go +++ b/pkg/reconciler/service/resources/configuration.go @@ -49,9 +49,9 @@ func MakeConfigurationFromExisting(service *v1.Service, existing *v1.Configurati routeName := names.Route(service) set := labeler.GetListAnnValue(existing.Annotations, serving.RoutesAnnotationKey) set.Insert(routeName) - sorted := set.UnsortedList() - sort.Strings(sorted) - anns[serving.RoutesAnnotationKey] = strings.Join(sorted, ",") + routeNames := set.UnsortedList() + sort.Strings(routeNames) + anns[serving.RoutesAnnotationKey] = strings.Join(routeNames, ",") return &v1.Configuration{ ObjectMeta: metav1.ObjectMeta{