From bf3b1ccd582833c53c64381d907ab6a647ace0eb Mon Sep 17 00:00:00 2001 From: Jason Vigil Date: Wed, 9 Oct 2024 23:58:43 +0000 Subject: [PATCH] feat: Record events when updating SQLInstances --- .../direct/directbase/directbase_controller.go | 2 +- pkg/controller/direct/directbase/operations.go | 13 ++++++++++++- pkg/controller/direct/sql/sqlinstance_controller.go | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/controller/direct/directbase/directbase_controller.go b/pkg/controller/direct/directbase/directbase_controller.go index 8d0e02631a..9e5add419e 100644 --- a/pkg/controller/direct/directbase/directbase_controller.go +++ b/pkg/controller/direct/directbase/directbase_controller.go @@ -306,7 +306,7 @@ func (r *reconcileContext) doReconcile(ctx context.Context, u *unstructured.Unst hasSetReadyCondition = createOp.HasSetReadyCondition requeueRequested = createOp.RequeueRequested } else { - updateOp := NewUpdateOperation(r.Reconciler.Client, u) + updateOp := NewUpdateOperation(r.Reconciler.LifecycleHandler, r.Reconciler.Client, u) if err := adapter.Update(ctx, updateOp); err != nil { if unwrappedErr, ok := lifecyclehandler.CausedByUnresolvableDeps(err); ok { logger.Info(unwrappedErr.Error(), "resource", k8s.GetNamespacedName(u)) diff --git a/pkg/controller/direct/directbase/operations.go b/pkg/controller/direct/directbase/operations.go index ed15609130..a921b640ca 100644 --- a/pkg/controller/direct/directbase/operations.go +++ b/pkg/controller/direct/directbase/operations.go @@ -20,6 +20,9 @@ import ( "time" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/lifecyclehandler" + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -56,15 +59,23 @@ func (o *operationBase) GetUnstructured() *unstructured.Unstructured { type UpdateOperation struct { operationBase + + lifecycleHandler lifecyclehandler.LifecycleHandler } -func NewUpdateOperation(client client.Client, object *unstructured.Unstructured) *UpdateOperation { +func NewUpdateOperation(lifecycleHandler lifecyclehandler.LifecycleHandler, client client.Client, object *unstructured.Unstructured) *UpdateOperation { op := &UpdateOperation{} + op.lifecycleHandler = lifecycleHandler op.client = client op.object = object return op } +func (o *UpdateOperation) RecordUpdatingEvent() { + r := o.lifecycleHandler.Recorder + r.Event(o.object, corev1.EventTypeNormal, k8s.Updating, k8s.UpdatingMessage) +} + type CreateOperation struct { operationBase } diff --git a/pkg/controller/direct/sql/sqlinstance_controller.go b/pkg/controller/direct/sql/sqlinstance_controller.go index 7a3fbd3831..bc5fb1bd81 100644 --- a/pkg/controller/direct/sql/sqlinstance_controller.go +++ b/pkg/controller/direct/sql/sqlinstance_controller.go @@ -387,6 +387,8 @@ func (a *sqlInstanceAdapter) Update(ctx context.Context, updateOp *directbase.Up } if !InstancesMatch(desiredGCP, a.actual) { + updateOp.RecordUpdatingEvent() + // GCP API requires we set the current settings version, otherwise update will fail. desiredGCP.Settings.SettingsVersion = a.actual.Settings.SettingsVersion