@@ -1217,16 +1217,14 @@ func (o *Operator) validateExistingCRs(gvr schema.GroupVersionResource, newCRD *
1217
1217
// The function may not always succeed as storedVersions requires at least one
1218
1218
// version. If there is only stored version, it won't be removed until a new
1219
1219
// stored version is added.
1220
- func removeDeprecatedStoredVersions (oldCRD * v1beta1ext.CustomResourceDefinition , newCRD * v1beta1ext.CustomResourceDefinition ) * v1beta1ext. CustomResourceDefinition {
1220
+ func removeDeprecatedStoredVersions (oldCRD * v1beta1ext.CustomResourceDefinition , newCRD * v1beta1ext.CustomResourceDefinition ) [] string {
1221
1221
// StoredVersions requires to have at least one version.
1222
1222
if len (oldCRD .Status .StoredVersions ) <= 1 {
1223
1223
return nil
1224
1224
}
1225
1225
1226
- updatedCRD := oldCRD .DeepCopy ()
1227
-
1228
- newCRDVersions := getCRDVersionsMap (newCRD )
1229
1226
newStoredVersions := []string {}
1227
+ newCRDVersions := getCRDVersionsMap (newCRD )
1230
1228
for _ , v := range oldCRD .Status .StoredVersions {
1231
1229
_ , ok := newCRDVersions [v ]
1232
1230
if ok {
@@ -1237,8 +1235,7 @@ func removeDeprecatedStoredVersions(oldCRD *v1beta1ext.CustomResourceDefinition,
1237
1235
if len (newStoredVersions ) < 1 {
1238
1236
return nil
1239
1237
} else {
1240
- updatedCRD .Status .StoredVersions = newStoredVersions
1241
- return updatedCRD
1238
+ return newStoredVersions
1242
1239
}
1243
1240
}
1244
1241
@@ -1291,7 +1288,9 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1291
1288
if k8serrors .IsAlreadyExists (err ) {
1292
1289
currentCRD , _ := o .lister .APIExtensionsV1beta1 ().CustomResourceDefinitionLister ().Get (crd .GetName ())
1293
1290
// Compare 2 CRDs to see if it needs to be updatetd
1294
- if ! reflect .DeepEqual (crd , * currentCRD ) {
1291
+ if ! (reflect .DeepEqual (crd .Spec .Version , currentCRD .Spec .Version ) &&
1292
+ reflect .DeepEqual (crd .Spec .Versions , currentCRD .Spec .Versions ) &&
1293
+ reflect .DeepEqual (crd .Spec .Validation , currentCRD .Spec .Validation )) {
1295
1294
// Verify CRD ownership, only attempt to update if
1296
1295
// CRD has only one owner
1297
1296
// Example: provided=database.coreos.com/v1alpha1/EtcdCluster
@@ -1302,19 +1301,6 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1302
1301
crd .SetResourceVersion (currentCRD .GetResourceVersion ())
1303
1302
if len (matchedCSV ) == 1 {
1304
1303
o .logger .Debugf ("Found one owner for CRD %v" , crd )
1305
-
1306
- crdStatus := removeDeprecatedStoredVersions (currentCRD , & crd )
1307
- if crdStatus != nil {
1308
- _ , err = o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().UpdateStatus (crdStatus )
1309
- if err != nil {
1310
- return errorwrap .Wrapf (err , "error updating CRD's status: %s" , step .Resource .Name )
1311
- }
1312
- }
1313
-
1314
- _ , err = o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Update (& crd )
1315
- if err != nil {
1316
- return errorwrap .Wrapf (err , "error updating CRD: %s" , step .Resource .Name )
1317
- }
1318
1304
} else if len (matchedCSV ) > 1 {
1319
1305
o .logger .Debugf ("Found multiple owners for CRD %v" , crd )
1320
1306
@@ -1326,19 +1312,21 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1326
1312
if err = o .validateCustomResourceDefinition (currentCRD , & crd ); err != nil {
1327
1313
return errorwrap .Wrapf (err , "error validating existing CRs agains new CRD's schema: %s" , step .Resource .Name )
1328
1314
}
1329
-
1330
- crdStatus := removeDeprecatedStoredVersions (currentCRD , & crd )
1331
- if crdStatus != nil {
1332
- _ , err = o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().UpdateStatus (crdStatus )
1333
- if err != nil {
1334
- return errorwrap .Wrapf (err , "error updating CRD's status: %s" , step .Resource .Name )
1335
- }
1336
- }
1337
-
1338
- _ , err = o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Update (& crd )
1315
+ }
1316
+ // Remove deprecated version in CRD storedVersions
1317
+ storeVersions := removeDeprecatedStoredVersions (currentCRD , & crd )
1318
+ if storeVersions != nil {
1319
+ currentCRD .Status .StoredVersions = storeVersions
1320
+ resultCRD , err := o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().UpdateStatus (currentCRD )
1339
1321
if err != nil {
1340
- return errorwrap .Wrapf (err , "error update CRD: %s" , step .Resource .Name )
1322
+ return errorwrap .Wrapf (err , "error updating CRD's status : %s" , step .Resource .Name )
1341
1323
}
1324
+ crd .SetResourceVersion (resultCRD .GetResourceVersion ())
1325
+ }
1326
+ // Update CRD to new version
1327
+ _ , err = o .opClient .ApiextensionsV1beta1Interface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Update (& crd )
1328
+ if err != nil {
1329
+ return errorwrap .Wrapf (err , "error updating CRD: %s" , step .Resource .Name )
1342
1330
}
1343
1331
}
1344
1332
// If it already existed, mark the step as Present.
0 commit comments