Skip to content

Commit e3bbfc6

Browse files
Merge pull request GoogleCloudPlatform#2890 from jasonvigil/record-direct-updating-events
feat: Record events when updating SQLInstances
2 parents fa48ebd + bf3b1cc commit e3bbfc6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

pkg/controller/direct/directbase/directbase_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (r *reconcileContext) doReconcile(ctx context.Context, u *unstructured.Unst
306306
hasSetReadyCondition = createOp.HasSetReadyCondition
307307
requeueRequested = createOp.RequeueRequested
308308
} else {
309-
updateOp := NewUpdateOperation(r.Reconciler.Client, u)
309+
updateOp := NewUpdateOperation(r.Reconciler.LifecycleHandler, r.Reconciler.Client, u)
310310
if err := adapter.Update(ctx, updateOp); err != nil {
311311
if unwrappedErr, ok := lifecyclehandler.CausedByUnresolvableDeps(err); ok {
312312
logger.Info(unwrappedErr.Error(), "resource", k8s.GetNamespacedName(u))

pkg/controller/direct/directbase/operations.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"time"
2121

2222
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1"
23+
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/lifecyclehandler"
24+
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
25+
corev1 "k8s.io/api/core/v1"
2326
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2427
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2528
"k8s.io/apimachinery/pkg/runtime"
@@ -56,15 +59,23 @@ func (o *operationBase) GetUnstructured() *unstructured.Unstructured {
5659

5760
type UpdateOperation struct {
5861
operationBase
62+
63+
lifecycleHandler lifecyclehandler.LifecycleHandler
5964
}
6065

61-
func NewUpdateOperation(client client.Client, object *unstructured.Unstructured) *UpdateOperation {
66+
func NewUpdateOperation(lifecycleHandler lifecyclehandler.LifecycleHandler, client client.Client, object *unstructured.Unstructured) *UpdateOperation {
6267
op := &UpdateOperation{}
68+
op.lifecycleHandler = lifecycleHandler
6369
op.client = client
6470
op.object = object
6571
return op
6672
}
6773

74+
func (o *UpdateOperation) RecordUpdatingEvent() {
75+
r := o.lifecycleHandler.Recorder
76+
r.Event(o.object, corev1.EventTypeNormal, k8s.Updating, k8s.UpdatingMessage)
77+
}
78+
6879
type CreateOperation struct {
6980
operationBase
7081
}

pkg/controller/direct/sql/sqlinstance_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ func (a *sqlInstanceAdapter) Update(ctx context.Context, updateOp *directbase.Up
387387
}
388388

389389
if !InstancesMatch(desiredGCP, a.actual) {
390+
updateOp.RecordUpdatingEvent()
391+
390392
// GCP API requires we set the current settings version, otherwise update will fail.
391393
desiredGCP.Settings.SettingsVersion = a.actual.Settings.SettingsVersion
392394

0 commit comments

Comments
 (0)