Skip to content

Commit 0ceb178

Browse files
authored
Add structured reporting diff to PubSubSnapshot (#6717)
### BRIEF Change description Fixes #6607 #### WHY do we need this change? Add structured reporting diff to the controller in `pkg/controller/direct/pubsub/pubsubsnapshot_controller.go`. The `structuredreporting.ReportDiff` should be used in the `Update` method of the adapter to report which fields are being updated. This helps in debugging reconciliation loops and provides better visibility into what changed. #### Special notes for your reviewer: #### Does this PR add something which needs to be 'release noted'? ```release-note NONE ``` #### Additional documentation e.g., references, usage docs, etc.: ```docs NONE ``` #### Intended Milestone - [ ] Reviewer tagged PR with the actual milestone. ### Tests you have done - [ ] Run `make ready-pr` to ensure this PR is ready for review. - [ ] Perform necessary E2E testing for changed resources.
2 parents 3f02289 + 5bfce1f commit 0ceb178

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/controller/direct/pubsub/pubsubsnapshot_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
4343
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
4444
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
45+
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/structuredreporting"
4546
)
4647

4748
func init() {
@@ -181,10 +182,13 @@ func (a *snapshotAdapter) Update(ctx context.Context, updateOp *directbase.Updat
181182
log := klog.FromContext(ctx)
182183
log.V(2).Info("updating pubsub snapshot", "name", a.id)
183184

185+
report := &structuredreporting.Diff{Object: updateOp.GetUnstructured()}
186+
184187
updateMask := &fieldmaskpb.FieldMask{}
185188
updated := proto.Clone(a.actual).(*pb.Snapshot)
186189

187190
if !reflect.DeepEqual(a.actual.Labels, a.desired.Spec.Labels) {
191+
report.AddField("labels", a.actual.Labels, a.desired.Spec.Labels)
188192
updated.Labels = a.desired.Spec.Labels
189193
updateMask.Paths = append(updateMask.Paths, "labels")
190194
}
@@ -196,6 +200,8 @@ func (a *snapshotAdapter) Update(ctx context.Context, updateOp *directbase.Updat
196200
return updateOp.UpdateStatus(ctx, status, nil)
197201
}
198202

203+
structuredreporting.ReportDiff(ctx, report)
204+
199205
req := &pb.UpdateSnapshotRequest{
200206
Snapshot: updated,
201207
UpdateMask: updateMask,

0 commit comments

Comments
 (0)