Skip to content

Commit 8cec21a

Browse files
committed
Enable OLM to update CRD when there is only one owner of that CRD
Signed-off-by: Vu Dinh <[email protected]>
1 parent e1fd0d3 commit 8cec21a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"reflect"
89
"sync"
910
"time"
1011

@@ -1034,6 +1035,19 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
10341035
// Attempt to create the CRD.
10351036
_, err = o.opClient.ApiextensionsV1beta1Interface().ApiextensionsV1beta1().CustomResourceDefinitions().Create(&crd)
10361037
if k8serrors.IsAlreadyExists(err) {
1038+
currentCRD, _ := o.OpClient.ApiextensionsV1beta1Interface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.GetName(), metav1.GetOptions{})
1039+
// Compare 2 CRDs to see if it needs to be updatetd
1040+
if !reflect.DeepEqual(crd, *currentCRD) {
1041+
// Verify CRD ownership, only attempt to update if
1042+
// CRD has only one owner
1043+
if len(existingCRDOwners[currentCRD.GetName()]) == 1 {
1044+
// Attempt to update CRD
1045+
_, err = o.OpClient.ApiextensionsV1beta1Interface().ApiextensionsV1beta1().CustomResourceDefinitions().Update(&crd)
1046+
if err != nil {
1047+
return errorwrap.Wrapf(err, "error update CRD: %s", step.Resource.Name)
1048+
}
1049+
}
1050+
}
10371051
// If it already existed, mark the step as Present.
10381052
plan.Status.Plan[i].Status = v1alpha1.StepStatusPresent
10391053
continue

0 commit comments

Comments
 (0)