Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix lint issue
Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan committed Aug 30, 2024
commit 562b5d8a9b667f9cf6332b34cea3692b4d7877a7
8 changes: 5 additions & 3 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ func (s sortableCatalogSource) Less(i, j int) bool {
return s[i].Namespace < s[j].Namespace
}

func (m *ODLMOperator) GetCatalogSourceAndChannelFromPackage(ctx context.Context, opregCatalog, opregCatalogNs, packageName, namespace, channel string, fallbackChannels []string, registryNs, odlmCatalog, odlmCatalogNs string, excludedCatalogSources []string) (catalogSourceName string, catalogSourceNs string, availableChannel string, err error) {
func (m *ODLMOperator) GetCatalogSourceAndChannelFromPackage(ctx context.Context, opregCatalog, opregCatalogNs, packageName, namespace, channel string, fallbackChannels []string,
registryNs, odlmCatalog, odlmCatalogNs string, excludedCatalogSources []string) (catalogSourceName string, catalogSourceNs string, availableChannel string, err error) {

packageManifestList := &operatorsv1.PackageManifestList{}
opts := []client.ListOption{
client.MatchingFields{"metadata.name": packageName},
Expand All @@ -156,7 +158,7 @@ func (m *ODLMOperator) GetCatalogSourceAndChannelFromPackage(ctx context.Context
default:
// Check if the CatalogSource and CatalogSource namespace are specified in OperandRegistry
if opregCatalog != "" && opregCatalogNs != "" {
curChannel := getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, packageName, namespace, opregCatalog, opregCatalogNs)
curChannel := getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, opregCatalog, opregCatalogNs)
if curChannel == "" {
klog.Errorf("Not found PackageManifest %s in the namespace %s has channel %s or fallback channels %s in the CatalogSource %s in the namespace %s", packageName, namespace, channel, fallbackChannels, opregCatalog, opregCatalogNs)
return "", "", "", nil
Expand Down Expand Up @@ -252,7 +254,7 @@ func prunedSemverChannel(fallbackChannels []string) ([]string, map[string]string
return semverlList, semVerChannelMappings
}

func getFirstAvailableSemverChannelFromCatalog(packageManifestList *operatorsv1.PackageManifestList, fallbackChannels []string, channel, packageName, namespace, catalogName, catalogNs string) string {
func getFirstAvailableSemverChannelFromCatalog(packageManifestList *operatorsv1.PackageManifestList, fallbackChannels []string, channel, catalogName, catalogNs string) string {
semverlList, semVerChannelMappings := prunedSemverChannel(fallbackChannels)
sort.Sort(semver.ByVersion(semverlList))

Expand Down
10 changes: 4 additions & 6 deletions controllers/operator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,11 @@ func TestGetFirstAvailableSemverChannelFromCatalog(t *testing.T) {
fallbackChannels := []string{}
channel := "v1.0"

packageName := "package1"
namespace := "namespace1"
catalogName := "catalog1"
catalogNs := "namespace1"

// Test with empty fallback channels and channel exists in the catalog
result := getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, packageName, namespace, catalogName, catalogNs)
result := getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, catalogName, catalogNs)
expectedResult := "v1.0"

if result != expectedResult {
Expand All @@ -185,7 +183,7 @@ func TestGetFirstAvailableSemverChannelFromCatalog(t *testing.T) {

// Test with empty fallback channels and channel does not exist in the catalog
channel = "alpha"
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, packageName, namespace, catalogName, catalogNs)
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, catalogName, catalogNs)
expectedResult = ""

if result != expectedResult {
Expand All @@ -196,7 +194,7 @@ func TestGetFirstAvailableSemverChannelFromCatalog(t *testing.T) {
channel = "v3.0"

// Test with fallback channels and channel does not exist in the catalog, but fallback channel exists
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, packageName, namespace, catalogName, catalogNs)
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, catalogName, catalogNs)
expectedResult = "v2.0"

if result != expectedResult {
Expand All @@ -208,7 +206,7 @@ func TestGetFirstAvailableSemverChannelFromCatalog(t *testing.T) {
channel = "v3.0"

// Test with fallback channels, but channel exist in the catalog
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, packageName, namespace, catalogName, catalogNs)
result = getFirstAvailableSemverChannelFromCatalog(packageManifestList, fallbackChannels, channel, catalogName, catalogNs)
expectedResult = "v3.0"

if result != expectedResult {
Expand Down
4 changes: 1 addition & 3 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ func FindSemverFromAnnotations(annotations map[string]string) ([]string, map[str

func FindMinSemverFromAnnotations(annotations map[string]string, curChannel string) string {
// check request annotation in subscription, get all available channels
var semverlList []string
var semVerChannelMappings = make(map[string]string)
semverlList, semVerChannelMappings = FindSemverFromAnnotations(annotations)
semverlList, semVerChannelMappings := FindSemverFromAnnotations(annotations)
return FindMinSemver(curChannel, semverlList, semVerChannelMappings)
}