Skip to content

Conversation

@p0lyn0mial
Copy link

@p0lyn0mial p0lyn0mial commented Oct 3, 2022

This PR allows:

  • for setting a generation during object creation so that it matches the original object
  • for setting a generation during an update so that it matches the original one

Essentially, the generation field for cached objects won't be managed by the generic/extensions API server.

part of kcp-dev/kcp#342

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe you need to get/set the map. You should be able to delete directly. https://go.dev/play/p/r7Wr8PbmwN9. Hopefully meta.Accessor doesn't change that?

Copy link
Author

Choose a reason for hiding this comment

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

ah, right, recently I have worked with an unstructured object that gave me a copy, here indeed we get a pointer.

Copy link
Member

Choose a reason for hiding this comment

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

idiomatic: _, found := accessor.GetAnnotations()[genericapirequest.AnnotationKey]; found

Copy link
Member

Choose a reason for hiding this comment

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

Funny, I told Joaquim to just do if annotations[key] != "" the other day. I'd call this one personal preference maybe.

Copy link
Author

Choose a reason for hiding this comment

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

if the language was more strict we wouldn't have to discuss at least 3 different ways of reading a value from a map :)

Copy link
Member

Choose a reason for hiding this comment

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

don't think this is correct (have seen the old thread). GetAnnotations() returns a map[string]string. In unstructured, it is map[string]interface{}. Hence, there must be a deepcopy with type cast happening.

Copy link
Member

Choose a reason for hiding this comment

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

To avoid the deepcopy use the *NoCopy unstructured helpers.

Copy link
Author

Choose a reason for hiding this comment

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

brought back the previous version, I don't think we need to use NoCopy. Using GetAnnotaions/SetAnnotations is always correct.

Copy link
Author

Choose a reason for hiding this comment

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

serverResource uses unstructuredCreator, that means requests to that EP will operate on unstructured data

@p0lyn0mial p0lyn0mial force-pushed the kcp-1.24-generation branch from a267022 to f64b618 Compare October 4, 2022 10:10
Copy link
Author

@p0lyn0mial p0lyn0mial Oct 4, 2022

Choose a reason for hiding this comment

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

I think that comparing to an empty string is more readable but I can change to _, found := accessor.GetAnnotations()[genericapirequest.AnnotationKey]; !found

@p0lyn0mial p0lyn0mial force-pushed the kcp-1.24-generation branch from f64b618 to eada9e1 Compare October 4, 2022 10:14
@sttts
Copy link
Member

sttts commented Oct 4, 2022

/lgtm
/approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants