Skip to content
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

feat: enable golden export for direct controller (no TF dependency) #2251

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuwenma
Copy link
Collaborator

@yuwenma yuwenma commented Jul 9, 2024

Change description

Fixes #

Tests you have done

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from yuwenma. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@@ -302,7 +302,23 @@ func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) erro
}

func (a *Adapter) Export(ctx context.Context) (*unstructured.Unstructured, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idea: (unrelated to this PR) we could have this return a runtime.Object, and then have the caller convert it to unstructured if needed. Would save a few lines in each Export method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes! This also makes the golden export more "correct". Right now, I have to re-write the name and namespace for golden export but this could miss other metadata like labels and annotations.

"sigs.k8s.io/yaml"
)

func directExport(u *unstructured.Unstructured, c client.Client) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought we had this function somewhere, but .. no objection, lgtm

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 have similar code nested inside the dynamic test (but I think that will be removed eventually).

"sigs.k8s.io/yaml"
)

func directExport(u *unstructured.Unstructured, c client.Client) ([]byte, error) {
ctx := context.TODO()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: probably easier to accept a ctx context.Context parameter on new methods (the caller can always pass context.TODO if needed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea.. was trying to do that but want to make as little code change as possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, just found h.Ctx.

return nil, err
}
if !found {
return nil, fmt.Errorf("GVK %s '%v' is not found", u.GroupVersionKind(), u.GetName())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: a message like "GCP resource for %v with name %q not found", gvk.Kind, u.GetName might be clearer. My thought is that it's not the GVK that wasn't found (in the registry), it's the underlying GCP object that wasn't found.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Yes, I like this message.

unst.SetGroupVersionKind(gvk)
unst.SetName(u.GetName())
if u.GetNamespace() != "" {
unst.SetName(u.GetName())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow this logic... should it be SetNamespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. (I turned on some vscode autocompletion. It seems to be too smart to control. I think I had a similar bug before)

@justinsb
Copy link
Collaborator

justinsb commented Jul 9, 2024

A few nits but lgtm. (Tests aren't passing though)

@yuwenma yuwenma force-pushed the cbwp-export branch 6 times, most recently from d739c26 to 227b9cd Compare July 10, 2024 04:02
@yuwenma yuwenma marked this pull request as draft July 10, 2024 04:32
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.

None yet

2 participants