Skip to content

Start experimental preview command #4438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025

Conversation

justinsb
Copy link
Collaborator

@justinsb justinsb commented Apr 25, 2025

The goal of the command is to capture for each object the changes that will be made at the cloud level.

This step adds some of the mechanics and a test, it does not yet expose the functionality.

@justinsb justinsb force-pushed the cli_preview branch 2 times, most recently from e3cc422 to b2731e0 Compare April 29, 2025 16:42
@justinsb justinsb changed the title WIP: CLI tool to preview changes Start experimental preview command Apr 29, 2025
@justinsb
Copy link
Collaborator Author

/assign @cheftako

@justinsb justinsb force-pushed the cli_preview branch 5 times, most recently from aa5f131 to 42c3db8 Compare April 29, 2025 20:18
func (e BlockedGCPError) Error() string {
// encode in json so that we can unwrap even if this is (incorrectly) wrapped as a string (terraform)
j, _ := json.Marshal(e)
return fmt.Sprintf("call to GCP blocked (method=%v, url=%v) [jsonstart:BlockedGCPError:%v:jsonend]", e.Method, e.URL, string(j))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why %v if we know they are strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly because %v works for both, but %s does not.

// GRPCUnaryClientInterceptor intercepts GCP GRPC API calls.
func (c *interceptingGCPClient) GRPCUnaryClientInterceptor() grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
// TODO!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this commented out block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to need it to support GRPC-based resources. It's a placeholder and reminder :-)

}

func (c *interceptingControllerRuntimeClient) SubResource(subResource string) client.SubResourceClient {
panic("not implemented")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to panic? I buy that we need to exit the current resource being tested. However it would be nice to get info on more that just the first problem we hit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to not panic! In general we don't actually use most of these methods, I believe. So I'd rather figure out how to catch the panics (I think we do). But switched this one to not panic (it's pretty similar to status above).

}()

// TODO: Add real waiting
time.Sleep(time.Second * 10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to wait for recorder.objects > 0 with timeout, I think we have helper functions which could do that. Seems like that would average faster and be less flaky.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I think it's pretty involved if we want to package this as a CLI tool, and I'd rather leave this task for a follow-on PR. (It's easy to do it for this test, because we know how many objects there are, but I'd rather fix it for the arbitrary case)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the proposed wait for objects > 0. There might still be a race here though I think it is unlikely. But we're eventually going to want a reconcileEnd event, I think.

}

// recordDiff captures the diff into our recorder.
func (r *Recorder) recordDiff(ctx context.Context, diff *structuredreporting.Diff) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight concern this is being done on the primary goroutine of the reconcile. My concern is what happens if we have large volumes of data and a slow disk. Also what happens if the disk runs out of room?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So even in "preview mode" it only goes to memory. In existing modes of operation we expect no listeners.

I will add a warning to the interface though, saying you should treat this as a logger and generally copy the data and queue it for another thread if you are going to do anything substantial with it (like writing to disk)

The goal of the command is to capture for each object the changes
that will be made at the cloud level.

This step adds some of the mechanics and a test, it does not yet expose
the functionality.
@cheftako
Copy link
Collaborator

cheftako commented May 3, 2025

/lgtm
/approve

@google-oss-prow google-oss-prow bot added the lgtm label May 3, 2025
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheftako

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 8543b37 into GoogleCloudPlatform:master May 3, 2025
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants