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

Preserve rendered annotations & labels on composed resources #2423

Merged
merged 3 commits into from
Jul 8, 2021

Conversation

ulucinar
Copy link
Contributor

@ulucinar ulucinar commented Jul 6, 2021

Description of your changes

As detailed in #2416, we would like to keep any rendered annotations or labels on composed resources when patches on metada.annotations or metadata.labels are applied. Notably, if there is a patch (from composition to composed) is defined on metadata.annotations in the composition:

...
  patchSets:
  - name: metadata
    patches:
    - fromFieldPath: metadata.annotations
      type: FromCompositeFieldPath

and the composite has non-zero metadata.annotations, we lose the rendered crossplane.io/composition-resource-name: rdsinstance annotation on the composed.

Fixes #2416

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

With a composition specifying a patch on metadata.annotations (exemplified above) selected, a dynamically provisioned XR with the following annotations:

...
metadata:
  annotations:
    a: b
  labels:
    crossplane.io/claim-name: my-db
    crossplane.io/claim-namespace: default
    crossplane.io/composite: my-db-p7vk9
...

now renders the following composed resource:

...
metadata:
  annotations:
    a: b
    crossplane.io/composition-resource-name: rdsinstance
  labels:
    crossplane.io/claim-name: my-db
    crossplane.io/claim-namespace: default
    crossplane.io/composite: my-db-p7vk9
...

Without the proposed changes, it renders a composed like the following:

...
metadata:
  annotations:
    a: b
  labels:
    crossplane.io/claim-name: my-db
    crossplane.io/claim-namespace: default
    crossplane.io/composite: my-db-p7vk9
...

- Do not override rendered annotations or labels when
  patches on metadata.annotations or metadata.labels are
  defined
- Fixes crossplane#2416

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
Comment on lines 361 to 362
cd.SetName(name)
cd.SetNamespace(namespace)
Copy link
Member

Choose a reason for hiding this comment

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

@ulucinar would this change mean that it is now impossible to patch over the metadata.name and metadata.namespace values? If so, I think this may be a breaking change that we are not willing to make. The existing behavior is desirable in cases where you want to provision a resource like a ProviderConfig with an identifying name that is used to group all the resources in a composition: https://github.com/upbound/platform-ref-aws/blob/63e724fc104ca1147c61787acc8a2891aced0393/cluster/eks/composition.yaml#L180

Copy link
Contributor Author

@ulucinar ulucinar Jul 6, 2021

Choose a reason for hiding this comment

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

Hi @hasheddan,
Yes it would prevent such use cases, thanks for pointing to the example use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the second commit, we now allow such patches.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me -- we are essentially mandating that our opinionated labels always be present. I would like for @negz to sign off on this though as it is somewhat subjective and I believe he originally added this functionality.

@@ -359,6 +350,17 @@ func (r *APIDryRunRenderer) Render(ctx context.Context, cp resource.Composite, c
}
}

// Fix(2416): composed labels and annotations should be rendered after patches are applied
Copy link
Member

Choose a reason for hiding this comment

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

This Fix(NNNN) practice is new to me. Do you think it's something we should adopt? Typically I've mostly trusted git to create the audit trail we need through commit messages, git blame, etc such that code can be traced back to a PR. We do specifically link to a PR or via its full URL in some cases when we feel that the reader would benefit from additional context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to use a concise format similar to GitHub's autolinked references to refer to a related issue (in case of a Fix, to refer to an issue reporting a bug) in order to add some more context on the source listing itself. I think it draws attention to the specific site and warns future maintainers about a potential pitfall on the site. But we can of course embed full URLs or just leave comments (+ git blame) to achieve the same goal.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@hasheddan hasheddan merged commit e006435 into crossplane:master Jul 8, 2021
@github-actions
Copy link

github-actions bot commented Jul 8, 2021

Backport failed for release-1.1, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-1.1
git worktree add -d .worktree/backport-2423-to-release-1.1 origin/release-1.1
cd .worktree/backport-2423-to-release-1.1
git checkout -b backport-2423-to-release-1.1
ancref=$(git merge-base 1842c4bb2e1258980bca4eda43a55761fe8e19f4 e83ee5777cbc3beab66ed7422654b30a43a66592)
git cherry-pick -x $ancref..e83ee5777cbc3beab66ed7422654b30a43a66592

@github-actions
Copy link

github-actions bot commented Jul 8, 2021

Backport failed for release-1.2, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-1.2
git worktree add -d .worktree/backport-2423-to-release-1.2 origin/release-1.2
cd .worktree/backport-2423-to-release-1.2
git checkout -b backport-2423-to-release-1.2
ancref=$(git merge-base 1842c4bb2e1258980bca4eda43a55761fe8e19f4 e83ee5777cbc3beab66ed7422654b30a43a66592)
git cherry-pick -x $ancref..e83ee5777cbc3beab66ed7422654b30a43a66592

@github-actions
Copy link

github-actions bot commented Jul 8, 2021

Successfully created backport PR #2428 for release-1.3.

@hasheddan
Copy link
Member

@ulucinar it looks like we will need manual backports to release-1.1 and release-1.2, do you want to get those in motion?

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.

Rendered Annotations on Managed Resources Get Lost if a Patch on the root Annotations Object is Specified
3 participants