Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sort cmpv.status.serviceVersions according to the semantic version #8652

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions controllers/apps/componentversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,17 @@ func (r *ComponentVersionReconciler) status(cli client.Client, rctx intctrlutil.
}

func (r *ComponentVersionReconciler) supportedServiceVersions(compVersion *appsv1.ComponentVersion) string {
versions := map[string]bool{}
versionSet := sets.New[string]()
for _, release := range compVersion.Spec.Releases {
if len(release.ServiceVersion) > 0 {
versions[release.ServiceVersion] = true
versionSet.Insert(release.ServiceVersion)
}
}
keys := maps.Keys(versions)
slices.Sort(keys)
return strings.Join(keys, ",") // TODO(API): service versions length
versions := versionSet.UnsortedList()
slices.SortFunc(versions, func(a, b string) int {
return serviceVersionComparator(a, b) * -1
})
return strings.Join(versions, ",") // TODO(API): service versions length
}

func (r *ComponentVersionReconciler) updateSupportedCompDefLabels(cli client.Client, rctx intctrlutil.RequestCtx,
Expand Down
7 changes: 4 additions & 3 deletions controllers/apps/componentversion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ var _ = Describe("ComponentVersion Controller", func() {
// compDefinitionObjs []*appsv1.ComponentDefinition
compVersionObj *appsv1.ComponentVersion

compDefNames = []string{testapps.CompDefName("v1.0"), testapps.CompDefName("v1.1"), testapps.CompDefName("v2.0"), testapps.CompDefName("v3.0")}
serviceVersions = []string{testapps.ServiceVersion("v1"), testapps.ServiceVersion("v2"), testapps.ServiceVersion("v3")}
compDefNames = []string{testapps.CompDefName("v1.0"), testapps.CompDefName("v1.1"), testapps.CompDefName("v2.0"), testapps.CompDefName("v3.0")}
// in reverse order
serviceVersions = []string{testapps.ServiceVersion("v3"), testapps.ServiceVersion("v2"), testapps.ServiceVersion("v1")}
)

cleanEnv := func() {
Expand Down Expand Up @@ -362,7 +363,7 @@ var _ = Describe("ComponentVersion Controller", func() {
func(g Gomega, cmpv *appsv1.ComponentVersion) {
g.Expect(cmpv.Status.ObservedGeneration).Should(Equal(cmpv.GetGeneration()))
g.Expect(cmpv.Status.Phase).Should(Equal(appsv1.AvailablePhase))
g.Expect(cmpv.Status.ServiceVersions).Should(Equal(strings.Join([]string{testapps.ServiceVersion("v1"), testapps.ServiceVersion("v3")}, ",")))
g.Expect(cmpv.Status.ServiceVersions).Should(Equal(strings.Join([]string{testapps.ServiceVersion("v3"), testapps.ServiceVersion("v1")}, ",")))
for i := 0; i < len(compDefNames); i++ {
g.Expect(cmpv.Labels).Should(HaveKeyWithValue(compDefNames[i], compDefNames[i]))
}
Expand Down
Loading