Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#2890 from jasonvigil/record-di…
Browse files Browse the repository at this point in the history
…rect-updating-events

feat: Record events when updating SQLInstances
  • Loading branch information
google-oss-prow[bot] authored Oct 18, 2024
2 parents fa48ebd + bf3b1cc commit e3bbfc6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/direct/directbase/directbase_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 12 additions & 1 deletion pkg/controller/direct/directbase/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/direct/sql/sqlinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e3bbfc6

Please sign in to comment.