Skip to content

Commit

Permalink
fix(requirements): add CRD served version requirement check
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed Oct 12, 2018
1 parent 017a8aa commit 8c3547d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
30 changes: 26 additions & 4 deletions pkg/controller/operators/olm/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions pkg/controller/operators/olm/requirements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8c3547d

Please sign in to comment.