From 2d797acb23835c30a994c8f84115bbc0a253e257 Mon Sep 17 00:00:00 2001 From: pigletfly Date: Fri, 21 Jan 2022 15:34:03 +0800 Subject: [PATCH] Sort apiResources Signed-off-by: pigletfly --- pkg/controllers/status/cluster_status_controller.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/controllers/status/cluster_status_controller.go b/pkg/controllers/status/cluster_status_controller.go index 92ffdc194297..30527397476a 100644 --- a/pkg/controllers/status/cluster_status_controller.go +++ b/pkg/controllers/status/cluster_status_controller.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "sort" "strings" "sync" "time" @@ -354,9 +355,7 @@ func getAPIEnablements(clusterClient *util.ClusterClient) ([]clusterv1alpha1.API if err != nil { return nil, err } - var apiEnablements []clusterv1alpha1.APIEnablement - for _, list := range apiResourceList { var apiResources []clusterv1alpha1.APIResource for _, resource := range list.APIResources { @@ -364,17 +363,20 @@ func getAPIEnablements(clusterClient *util.ClusterClient) ([]clusterv1alpha1.API if strings.Contains(resource.Name, "/") { continue } - apiResource := clusterv1alpha1.APIResource{ Name: resource.Name, Kind: resource.Kind, } - apiResources = append(apiResources, apiResource) } + sort.SliceStable(apiResources, func(i, j int) bool { + return apiResources[i].Name < apiResources[j].Name + }) apiEnablements = append(apiEnablements, clusterv1alpha1.APIEnablement{GroupVersion: list.GroupVersion, Resources: apiResources}) } - + sort.SliceStable(apiEnablements, func(i, j int) bool { + return apiEnablements[i].GroupVersion < apiEnablements[j].GroupVersion + }) return apiEnablements, nil }