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

Remove delegation to RNode in Resource #3888

Merged
merged 1 commit into from
May 11, 2021

Conversation

monopole
Copy link
Contributor

@monopole monopole commented May 11, 2021

Close #3885

Builds on #3886 (that should go first) - it's the same as the first commit in this PR.

ALLOW_MODULE_SPAN

Also, this PR stops swallowing errors on SetLabel and SetAnnotations calls. It's rare those should fail, but if they do it's better to fail than swallow.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 11, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: monopole

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

@k8s-ci-robot k8s-ci-robot requested review from justinsb and KnVerey May 11, 2021 03:58
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 11, 2021
@monopole monopole requested review from natasha41575 and removed request for justinsb and KnVerey May 11, 2021 04:26
@monopole
Copy link
Contributor Author

@KnVerey fyi, i think i mentioned this to you once as a possible simplification step. we can go further in this vein.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 11, 2021
@monopole monopole requested a review from KnVerey May 11, 2021 17:25

func (r *Resource) SetBinaryDataMap(m map[string]string) {
r.node.SetBinaryDataMap(m)
return h.Hash(&r.RNode)
}

func (r *Resource) SetGvk(gvk resid.Gvk) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we push this one and GetGvk down to RNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want to, but at the moment, kyaml/resid (where gvk.go lives) depends on kyaml/yaml (which is where rnode.go lives). So we'd get a circular dependence if we made RNode depend on Gvk. Still whittling away at this...,

@@ -107,6 +107,7 @@ func (ra *ResAccumulator) findVarValueFromResources(v types.Var) (interface{}, e
for _, res := range ra.resMap.Resources() {
for _, varName := range res.GetRefVarNames() {
if varName == v.Name {
//nolint: staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suppresses a lint failure, because the next line is calling a deprecated function.
We need to remove that call, but its outside the scope of this pr

func (r *Resource) AllowKindChange() {
annotations := r.GetAnnotations()
annotations[buildAnnotationAllowKindChange] = allowed
r.SetAnnotations(annotations)
if err := r.SetAnnotations(annotations); err != nil {
panic(err)
Copy link
Contributor

@natasha41575 natasha41575 May 11, 2021

Choose a reason for hiding this comment

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

why panic instead of returning the error?

Copy link
Contributor Author

@monopole monopole May 11, 2021

Choose a reason for hiding this comment

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

i'd have to change the signature of AllowKindChange and propagate up. I tried to only panic where that wasn't a possibilty already.

frankly i'm about ready to remove error from the SetLabels and SetAnnotations signature.

edit:

I'm pretty sure it only fails if the underlying object is nil (which means its unlikely execution will ever get there anyway)

They will even add a metadata field if it's missing (which is arguably too accommodating).

Even if we remove the error from SetLabels and SetAnnotations return, we'd have to panic inside those functions rather than swallow the error.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, thanks for the explanation :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you folks think? remove the error return from SetLabels and SetAnnotations, and panic inside them if there's an error? There's no way to recover, because the node would have to be nil and that's a programmer error anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as there's no user error that could trigger this panic, I think it's fine as it is

func (r *Resource) AllowNameChange() {
annotations := r.GetAnnotations()
annotations[buildAnnotationAllowNameChange] = allowed
r.SetAnnotations(annotations)
if err := r.SetAnnotations(annotations); err != nil {
panic(err)
Copy link
Contributor

@natasha41575 natasha41575 May 11, 2021

Choose a reason for hiding this comment

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

same here

@natasha41575
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2021
@natasha41575
Copy link
Contributor

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 11, 2021
@natasha41575 natasha41575 removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 11, 2021
@k8s-ci-robot k8s-ci-robot merged commit 017a094 into kubernetes-sigs:master May 11, 2021
@monopole monopole deleted the popRNodeUp branch May 18, 2021 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove delegation to RNode in Resource
4 participants