From 0a8bf9efb71d218b372253d1ad257d3575a003be Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Tue, 23 Mar 2021 12:19:49 +0000 Subject: [PATCH] Bug 1910318: Ensure original conditions aren't mutated during reconcile --- go.mod | 2 +- go.sum | 4 ++-- .../pkg/controller/machine/controller.go | 10 ++++++---- vendor/modules.txt | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 635609aa9e39..398b1d141efc 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/onsi/ginkgo v1.14.1 github.com/onsi/gomega v1.10.2 github.com/openshift/api v0.0.0-20201216151826-78a19e96f9eb - github.com/openshift/machine-api-operator v0.2.1-0.20210310053650-d40398c49baf + github.com/openshift/machine-api-operator v0.2.1-0.20210322142500-9101e75223bf github.com/spf13/cobra v1.1.1 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad diff --git a/go.sum b/go.sum index d19de0fb8a60..4b09ee7257c6 100644 --- a/go.sum +++ b/go.sum @@ -565,8 +565,8 @@ github.com/openshift/machine-api-operator v0.2.1-0.20200926044412-b7d860f8074c h github.com/openshift/machine-api-operator v0.2.1-0.20200926044412-b7d860f8074c/go.mod h1:cp/wPVzxHZeLUjOLkNPNqrk4wyyW6HuHd3Kz9+hl5xw= github.com/openshift/machine-api-operator v0.2.1-0.20201002104344-6abfb5440597 h1:2leDrsKmE7ppJSthf6SiD+Pqjyis633L/n+YdTVdBbo= github.com/openshift/machine-api-operator v0.2.1-0.20201002104344-6abfb5440597/go.mod h1:+oAfoCl+TUd2TM79/6NdqLpFUHIJpmqkKdmiHe2O7mw= -github.com/openshift/machine-api-operator v0.2.1-0.20210310053650-d40398c49baf h1:C4nn2kbSDhLXwg7W87EgcDpri83QnGSbH1C0cqJxHgI= -github.com/openshift/machine-api-operator v0.2.1-0.20210310053650-d40398c49baf/go.mod h1:N3Q+UKEziycun6J3kyxQnRsBBebjwm9fnD6vSnUWqRU= +github.com/openshift/machine-api-operator v0.2.1-0.20210322142500-9101e75223bf h1:R9HI45C81V4cGbXmMF6+9NXk7d54T5sfTs84gIrBq0w= +github.com/openshift/machine-api-operator v0.2.1-0.20210322142500-9101e75223bf/go.mod h1:N3Q+UKEziycun6J3kyxQnRsBBebjwm9fnD6vSnUWqRU= github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b/go.mod h1:iVyukRkam5JZa8AnjYf+/G3rk7JI1+M6GsU0sq0B9NA= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go b/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go index 6b578e9768aa..a211cfe6e55b 100644 --- a/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go +++ b/vendor/github.com/openshift/machine-api-operator/pkg/controller/machine/controller.go @@ -173,8 +173,9 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ machineName := m.GetName() klog.Infof("%v: reconciling Machine", machineName) - // Get the original state of conditions now so that they can be used to calculate the patch later - originalConditions := m.GetConditions() + // Get the original state of conditions now so that they can be used to calculate the patch later. + // This must be a copy otherwise the referenced slice will be modified by later machine conditions changes. + originalConditions := m.GetConditions().DeepCopy() if errList := m.Validate(); len(errList) > 0 { err := fmt.Errorf("%v: machine validation failed: %v", machineName, errList.ToAggregate().Error()) @@ -293,8 +294,6 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ } if instanceExists { - conditions.MarkTrue(m, machinev1.InstanceExistsCondition) - klog.Infof("%v: reconciling machine triggers idempotent update", machineName) if err := r.actuator.Update(ctx, m); err != nil { klog.Errorf("%v: error updating machine: %v, retrying in %v seconds", machineName, err, requeueAfter) @@ -306,6 +305,9 @@ func (r *ReconcileMachine) Reconcile(ctx context.Context, request reconcile.Requ return reconcile.Result{RequeueAfter: requeueAfter}, nil } + // Mark the instance exists condition true after actuator update else the update may overwrite changes + conditions.MarkTrue(m, machinev1.InstanceExistsCondition) + if !machineIsProvisioned(m) { klog.Errorf("%v: instance exists but providerID or addresses has not been given to the machine yet, requeuing", machineName) if patchErr := r.updateStatus(m, pointer.StringPtrDerefOr(m.Status.Phase, ""), nil, originalConditions); patchErr != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 6f72ee670d63..2a3324b07800 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -189,7 +189,7 @@ github.com/openshift/client-go/config/clientset/versioned/scheme github.com/openshift/client-go/config/clientset/versioned/typed/config/v1 # github.com/openshift/cluster-api-provider-gcp v0.0.1-0.20201201000827-1117a4fc438c github.com/openshift/cluster-api-provider-gcp/pkg/apis/gcpprovider/v1beta1 -# github.com/openshift/machine-api-operator v0.2.1-0.20210310053650-d40398c49baf +# github.com/openshift/machine-api-operator v0.2.1-0.20210322142500-9101e75223bf ## explicit github.com/openshift/machine-api-operator/pkg/apis/machine github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1