Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ spec:
mediatype: image/png
install:
spec:
clusterPermissions:
- rules:
- apiGroups:
- operators.coreos.com
resources:
- catalogsources
verbs:
- get
serviceAccountName: operand-deployment-lifecycle-manager
deployments:
- label:
app.kubernetes.io/instance: operand-deployment-lifecycle-manager
Expand Down
12 changes: 11 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: operand-deployment-lifecycle-manager
rules:
- apiGroups:
- operators.coreos.com
resources:
- catalogsources
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
13 changes: 13 additions & 0 deletions config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: operand-deployment-lifecycle-manager
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: operand-deployment-lifecycle-manager
subjects:
- kind: ServiceAccount
name: operand-deployment-lifecycle-manager
namespace: system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: operand-deployment-lifecycle-manager
Expand Down
23 changes: 14 additions & 9 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,15 @@ type CatalogSource struct {
Namespace string
OpNamespace string
RegistryNamespace string
Priority int
}

type sortableCatalogSource []CatalogSource

func (s sortableCatalogSource) Len() int { return len(s) }
func (s sortableCatalogSource) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sortableCatalogSource) Less(i, j int) bool {
// Check if the catalogsource is in the same namespace as OperandRegistry
inRegistryNsI, inRegistryNsJ := s[i].Namespace == s[i].RegistryNamespace, s[j].Namespace == s[j].RegistryNamespace
if inRegistryNsI && !inRegistryNsJ {
return true
}
if !inRegistryNsI && inRegistryNsJ {
return false
}

// Check if the catalogsource is in the same namespace as operator
inOpNsI, inOpNsJ := s[i].Namespace == s[i].OpNamespace, s[j].Namespace == s[j].OpNamespace
if inOpNsI && !inOpNsJ {
Expand All @@ -130,6 +124,12 @@ func (s sortableCatalogSource) Less(i, j int) bool {
if !inOpNsI && inOpNsJ {
return false
}
// Compare catalogsource priorities first, higher priority comes first
iPriority, jPriority := s[i].Priority, s[j].Priority
klog.V(2).Infof("iPriority: %v, jPriority: %v", iPriority, jPriority)
if iPriority != jPriority {
return iPriority > jPriority
}
// If their namespaces are the same, then compare the name of the catalogsource
if s[i].Namespace == s[j].Namespace {
return s[i].Name < s[j].Name
Expand Down Expand Up @@ -164,7 +164,12 @@ func (m *ODLMOperator) GetCatalogSourceFromPackage(ctx context.Context, packageN
if !channelCheck(channel, pm.Status.Channels) || (excludedCatalogSources != nil && util.Contains(excludedCatalogSources, pm.Status.CatalogSource)) {
continue
}
catalogSourceCandidate = append(catalogSourceCandidate, CatalogSource{Name: pm.Status.CatalogSource, Namespace: pm.Status.CatalogSourceNamespace, OpNamespace: namespace, RegistryNamespace: registryNs})
catalogsource := &olmv1alpha1.CatalogSource{}
if err := m.Reader.Get(ctx, types.NamespacedName{Name: pm.Status.CatalogSource, Namespace: pm.Status.CatalogSourceNamespace}, catalogsource); err != nil {
klog.Warning(err)
Comment on lines +168 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could return error here.
Usually when err != nil, we will get catalogsource as nil. Therefore, it will error out in the next line when we try to read catalogsource.Spec.Priority

continue
}
catalogSourceCandidate = append(catalogSourceCandidate, CatalogSource{Name: pm.Status.CatalogSource, Namespace: pm.Status.CatalogSourceNamespace, OpNamespace: namespace, RegistryNamespace: registryNs, Priority: catalogsource.Spec.Priority})
}
if len(catalogSourceCandidate) == 0 {
klog.Errorf("Not found PackageManifest %s in the namespace %s has channel %s", packageName, namespace, channel)
Expand Down