-
Notifications
You must be signed in to change notification settings - Fork 211
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
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
tests/e2e/export.go
Outdated
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func directExport(u *unstructured.Unstructured, c client.Client) ([]byte, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
tests/e2e/export.go
Outdated
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func directExport(u *unstructured.Unstructured, c client.Client) ([]byte, error) { | ||
ctx := context.TODO() |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
tests/e2e/export.go
Outdated
return nil, err | ||
} | ||
if !found { | ||
return nil, fmt.Errorf("GVK %s '%v' is not found", u.GroupVersionKind(), u.GetName()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
tests/e2e/export.go
Outdated
unst.SetGroupVersionKind(gvk) | ||
unst.SetName(u.GetName()) | ||
if u.GetNamespace() != "" { | ||
unst.SetName(u.GetName()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
A few nits but lgtm. (Tests aren't passing though) |
d739c26
to
227b9cd
Compare
Change description
Fixes #
Tests you have done
make ready-pr
to ensure this PR is ready for review.