diff --git a/pkg/controller/operators/olm/operator_test.go b/pkg/controller/operators/olm/operator_test.go index 812907b20ec..df887a6e0db 100644 --- a/pkg/controller/operators/olm/operator_test.go +++ b/pkg/controller/operators/olm/operator_test.go @@ -423,6 +423,14 @@ func TestTransitionCSV(t *testing.T) { crds: []runtime.Object{ crd("c1", "v1"), }, + objs: []runtime.Object{ + &v1.ServiceAccount{ + ObjectMeta: metav1.ObjectMeta{ + Name: "sa", + Namespace: namespace, + }, + }, + }, }, expected: expected{ csvStates: map[string]csvState{ diff --git a/pkg/controller/operators/olm/requirements.go b/pkg/controller/operators/olm/requirements.go index bb9e166a3db..ba464fc4e4c 100644 --- a/pkg/controller/operators/olm/requirements.go +++ b/pkg/controller/operators/olm/requirements.go @@ -30,11 +30,35 @@ func (a *Operator) requirementStatus(strategyDetailsDeployment *install.Strategy if err != nil { status.Status = v1alpha1.RequirementStatusReasonNotPresent met = false - } else { + statuses = append(statuses, status) + continue + } + + if crd.Spec.Version == r.Version { status.Status = v1alpha1.RequirementStatusReasonPresent status.UUID = string(crd.GetUID()) + statuses = append(statuses, status) + continue + } + + served := false + for _, version := range crd.Spec.Versions { + if version.Name == r.Version { + if version.Served { + status.Status = v1alpha1.RequirementStatusReasonPresent + status.UUID = string(crd.GetUID()) + statuses = append(statuses, status) + served = true + } + break + } + } + + if !served { + status.Status = v1alpha1.RequirementStatusReasonNotPresent + met = false + statuses = append(statuses, status) } - statuses = append(statuses, status) } // Check for required API services @@ -215,8 +239,6 @@ func (a *Operator) requirementAndPermissionStatus(csv *v1alpha1.ClusterServiceVe return false, nil, fmt.Errorf("could not cast install strategy as type %T", strategyDetailsDeployment) } - // Ensure permissions are valid - reqMet, reqStatuses := a.requirementStatus(strategyDetailsDeployment, csv.GetAllCRDDescriptions(), csv.GetOwnedAPIServiceDescriptions(), csv.GetRequiredAPIServiceDescriptions()) ruleChecker := install.NewCSVRuleChecker(a.roleLister, a.roleBindingLister, a.clusterRoleLister, a.clusterRoleBindingLister, csv) diff --git a/pkg/controller/operators/olm/requirements_test.go b/pkg/controller/operators/olm/requirements_test.go index df1210d262f..080cba6374f 100644 --- a/pkg/controller/operators/olm/requirements_test.go +++ b/pkg/controller/operators/olm/requirements_test.go @@ -427,6 +427,32 @@ func TestRequirementAndPermissionStatus(t *testing.T) { }, expectedError: nil, }, + { + description: "RequirementNotMet/NonServedCRDVersion", + csv: csv("csv1", + namespace, + "", + installStrategy("csv1-dep", nil, nil), + []*v1beta1.CustomResourceDefinition{crd("c1", "v2")}, + nil, + v1alpha1.CSVPhasePending, + ), + existingObjs: nil, + existingExtObjs: []runtime.Object{ + crd("c1", "v1"), + }, + met: false, + expectedRequirementStatuses: map[gvkn]v1alpha1.RequirementStatus{ + {"apiextensions.k8s.io", "v1beta1", "CustomResourceDefinition", "c1group"}: { + Group: "apiextensions.k8s.io", + Version: "v1beta1", + Kind: "CustomResourceDefinition", + Name: "c1group", + Status: v1alpha1.RequirementStatusReasonNotPresent, + }, + }, + expectedError: nil, + }, } for _, test := range tests {