Skip to content

Commit 35271e9

Browse files
committed
Always validate CR upgrade compatibility.
Remove cruft that prevented compatibility tests from running on CRs when there is only 1 CSV that owns the CRD in question. Signed-off-by: Ben Luddy <[email protected]>
1 parent 0e84c1b commit 35271e9

File tree

1 file changed

+4
-30
lines changed
  • pkg/controller/operators/catalog

1 file changed

+4
-30
lines changed

pkg/controller/operators/catalog/step.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1111
crdlib "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/crd"
12-
index "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/index"
1312
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1413
errorwrap "github.com/pkg/errors"
1514
logger "github.com/sirupsen/logrus"
@@ -127,22 +126,9 @@ func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Inter
127126
_, createError := client.CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
128127
if k8serrors.IsAlreadyExists(createError) {
129128
currentCRD, _ := client.CustomResourceDefinitions().Get(context.TODO(), crd.GetName(), metav1.GetOptions{})
130-
// Verify CRD ownership, only attempt to update if
131-
// CRD has only one owner
132-
// Example: provided=database.coreos.com/v1alpha1/EtcdCluster
133-
matchedCSV, err := index.V1CRDProviderNames(b.csvToProvidedAPIs, crd)
134-
if err != nil {
135-
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error find matched CSV: %s", step.Resource.Name)
136-
}
137129
crd.SetResourceVersion(currentCRD.GetResourceVersion())
138-
if len(matchedCSV) == 1 {
139-
logger.Debugf("Found one owner for CRD %v", crd)
140-
} else if len(matchedCSV) > 1 {
141-
logger.Debugf("Found multiple owners for CRD %v", crd)
142-
143-
if err = validateV1CRDCompatibility(b.dynamicClient, currentCRD, crd); err != nil {
144-
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error validating existing CRs against new CRD's schema: %s", step.Resource.Name)
145-
}
130+
if err = validateV1CRDCompatibility(b.dynamicClient, currentCRD, crd); err != nil {
131+
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error validating existing CRs against new CRD's schema: %s", step.Resource.Name)
146132
}
147133

148134
// check to see if stored versions changed and whether the upgrade could cause potential data loss
@@ -215,22 +201,10 @@ func (b *builder) NewCRDV1Beta1Step(client apiextensionsv1beta1client.Apiextensi
215201
_, createError := client.CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
216202
if k8serrors.IsAlreadyExists(createError) {
217203
currentCRD, _ := client.CustomResourceDefinitions().Get(context.TODO(), crd.GetName(), metav1.GetOptions{})
218-
// Verify CRD ownership, only attempt to update if
219-
// CRD has only one owner
220-
// Example: provided=database.coreos.com/v1alpha1/EtcdCluster
221-
matchedCSV, err := index.V1Beta1CRDProviderNames(b.csvToProvidedAPIs, crd)
222-
if err != nil {
223-
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error find matched CSV: %s", step.Resource.Name)
224-
}
225204
crd.SetResourceVersion(currentCRD.GetResourceVersion())
226-
if len(matchedCSV) == 1 {
227-
logger.Debugf("Found one owner for CRD %v", crd)
228-
} else if len(matchedCSV) > 1 {
229-
logger.Debugf("Found multiple owners for CRD %v", crd)
230205

231-
if err = validateV1Beta1CRDCompatibility(b.dynamicClient, currentCRD, crd); err != nil {
232-
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error validating existing CRs against new CRD's schema: %s", step.Resource.Name)
233-
}
206+
if err = validateV1Beta1CRDCompatibility(b.dynamicClient, currentCRD, crd); err != nil {
207+
return v1alpha1.StepStatusUnknown, errorwrap.Wrapf(err, "error validating existing CRs against new CRD's schema: %s", step.Resource.Name)
234208
}
235209

236210
// check to see if stored versions changed and whether the upgrade could cause potential data loss

0 commit comments

Comments
 (0)