Skip to content

Commit

Permalink
Sort apiResources
Browse files Browse the repository at this point in the history
Signed-off-by: pigletfly <[email protected]>
  • Loading branch information
pigletfly committed Jan 24, 2022
1 parent e5aeb26 commit 2d797ac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/controllers/status/cluster_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -354,27 +355,28 @@ 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 {
// skip subresources such as "/status", "/scale" and etc because these are not real APIResources that we are caring about.
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
}

Expand Down

0 comments on commit 2d797ac

Please sign in to comment.