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

Fix unknown fields warnings and possibility to suppress finalizer ones #786

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

turkenh
Copy link
Member

@turkenh turkenh commented Nov 4, 2024

Description of your changes

This PR aims to clean up warnings observed in crossplane/crossplane#6043 by:

  • Fixing "unknown field" warnings using the correct structs matching schemas.
  • Suppressing "prefer a domain-qualified finalizer" until we properly migrate them to the suggested format.

Together with the accompanying PR in Crossplane, I could validate that former warnings disappeared with the changes here.

This PR introduces a new package, warning, with the warning.LoggingHandler implementing rest.WarningHandler interface. This supports deduplication just like the current handler Crossplane uses, but it also uses provided crossplane runtime logger so that warnings logged as structured logs* and also enables discarding logs matching provided regular expressions. I opted to put this into crossplane runtime since we may want to leverage it in other repositories, e.g. providers, as well.

I have:

Need help with this checklist? See the cheat sheet.

@turkenh turkenh requested a review from a team as a code owner November 4, 2024 12:43
@turkenh turkenh requested a review from negz November 4, 2024 12:43
@@ -63,21 +64,6 @@ type Unstructured struct {
unstructured.Unstructured
}

// Reference to a claim.
type Reference struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

If I simply added a Reference type under composite package, I was getting import cycle. So, I moved them into a separate reference package.

@turkenh turkenh force-pushed the fix-unknown-fields branch 2 times, most recently from 5e5b686 to a34fc1d Compare November 4, 2024 12:49
@turkenh turkenh requested a review from jbw976 November 4, 2024 12:51
if err := fieldpath.Pave(c.Object).GetValueInto("spec.compositionRevisionRef", out); err != nil {
return nil
}
return out
}

// SetCompositionRevisionReference of this resource claim.
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.ObjectReference) {
func (c *Unstructured) SetCompositionRevisionReference(ref *corev1.LocalObjectReference) {
Copy link
Member Author

Choose a reason for hiding this comment

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

if err := fieldpath.Pave(c.Object).GetValueInto("spec.resourceRef", out); err != nil {
return nil
}
return out
}

// SetResourceReference of this composite resource claim.
func (c *Unstructured) SetResourceReference(ref *corev1.ObjectReference) {
func (c *Unstructured) SetResourceReference(ref *reference.Composite) {
Copy link
Member Author

Choose a reason for hiding this comment

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

func (c *Unstructured) GetCompositionRevisionReference() *corev1.ObjectReference {
out := &corev1.ObjectReference{}
func (c *Unstructured) GetCompositionRevisionReference() *corev1.LocalObjectReference {
out := &corev1.LocalObjectReference{}
Copy link
Member Author

Choose a reason for hiding this comment

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

@turkenh turkenh changed the title Fix unknown fields warnings by avoiding setting non-existing fields Fix unknown fields warnings and suppress finalizer ones Nov 4, 2024
@turkenh turkenh changed the title Fix unknown fields warnings and suppress finalizer ones Fix unknown fields warnings and possibility suppress finalizer ones Nov 4, 2024
@turkenh turkenh changed the title Fix unknown fields warnings and possibility suppress finalizer ones Fix unknown fields warnings and possibility to suppress finalizer ones Nov 4, 2024
Copy link
Contributor

@phisco phisco left a comment

Choose a reason for hiding this comment

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

not a huge fan of suppressing warnings, I would have probably preferred to keep them there and fix them in a follow-up PR.

Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

Thanks for continuing to tackle issues quickly for v1.18 @turkenh!! a few questions for you 🙇‍♂️


// ManagedResourceReferencer is a mock that implements ManagedResourceReferencer interface.
type ManagedResourceReferencer struct{ Ref *corev1.ObjectReference }
type ManagedResourceReferencer struct{ Ref *reference.Composite }
Copy link
Member

Choose a reason for hiding this comment

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

are these updates to ManagedResourceReferencer correct? Because it is called ManagedResource*, I would expect them not to only specifically point to a Composite now 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch! Fixing linter issues one by one and not sure how/why I changed this one 🤔

// accidental conflicts with other finalizer writers.
func DomainQualifiedFinalizer(domain string) regexp.Regexp {
return *regexp.MustCompile(
fmt.Sprintf("^metadata.finalizers:.*%s.*prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers$", domain),
Copy link
Member

Choose a reason for hiding this comment

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

will this check start to fail once we pick up https://github.com/kubernetes/kubernetes/pull/127303/files which changes the warning message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, correct. Logs would appear again until we adapt the regexp.

I'll drop the finalizer log suppressing part.

*/

// Package warning contains utilities for handling warnings.
package warning
Copy link
Member

Choose a reason for hiding this comment

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

i'm wondering how essential this is actually - it doesn't fix the underlying issue right, it just hides it from the logs? i'm wondering if we just live with the warnings in the logs now, and resolve them with a real fix during the 1.19 milestone, instead of hiding them for now and maybe forgetting about them. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll drop the last commit, e.g., finalizer log suppressing, since both you and @phisco prefer keeping logs around instead, and I am not too opinionated, at least to consider something that important doing last minute :)

Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

Thanks @turkenh for quick responses to the questions and feedback!! 🤩

@turkenh turkenh merged commit 19d95a6 into crossplane:main Nov 5, 2024
10 checks passed
Copy link

github-actions bot commented Nov 5, 2024

Successfully created backport PR for release-1.18:

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.

3 participants