Skip to content

Commit af5794d

Browse files
authored
Refactor fallback channel selection to sort by semantic version and find the first available channel (#1171)
* Refactor fallback channel selection to sort by semantic version and find the first available channel Signed-off-by: Daniel Fan <[email protected]> * Increase golangci-lint timeout Signed-off-by: Daniel Fan <[email protected]> --------- Signed-off-by: Daniel Fan <[email protected]>
1 parent bb6a1a7 commit af5794d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

common/scripts/lint_go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# limitations under the License.
1616
#
1717

18-
GOGC=25 golangci-lint run -c ./common/config/.golangci.yml --timeout=480s
18+
GOGC=25 golangci-lint run -c ./common/config/.golangci.yml --timeout=600s

controllers/operator/manager.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ func findCatalogFromFallbackChannels(fallbackChannels []string, fallBackChannelA
270270
// sort fallback channels by semantic version
271271
semverlList, semVerChannelMappings := prunedSemverChannel(fallbackChannels)
272272

273-
maxChannel := util.FindMaxSemver("", semverlList, semVerChannelMappings)
274-
if catalogSources, ok := fallBackChannelAndCatalogMapping[maxChannel]; ok {
275-
fallbackChannel = maxChannel
276-
fallbackCatalog = append(fallbackCatalog, catalogSources...)
273+
sort.Sort(semver.ByVersion(semverlList))
274+
// find the first available channel from the sorted list in descending order
275+
for i := len(semverlList) - 1; i >= 0; i-- {
276+
if catalogs, ok := fallBackChannelAndCatalogMapping[semVerChannelMappings[semverlList[i]]]; ok {
277+
fallbackChannel = semVerChannelMappings[semverlList[i]]
278+
fallbackCatalog = catalogs
279+
break
280+
}
277281
}
278282
return fallbackChannel, fallbackCatalog
279283
}

0 commit comments

Comments
 (0)