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

update labels/annotations_as_tags on value change #3253

Conversation

ahmed-mez
Copy link
Contributor

@ahmed-mez ahmed-mez commented Apr 3, 2019

What does this PR do?

Currently, pod labels_as_tags / annotations_as_tags get collected and set on pod/container creation. FR to be able to update these labels_as_tags / annotations_as_tags when the pod label/annotations values update.

Motivation

Feature request: update the labels programmatically and monitors them using tags

@ahmed-mez ahmed-mez added this to the 6.12.0 milestone Apr 3, 2019
@ahmed-mez ahmed-mez requested a review from a team April 3, 2019 16:53
@ahmed-mez ahmed-mez requested a review from a team as a code owner April 3, 2019 16:53
Copy link
Member

@xlucas xlucas left a comment

Choose a reason for hiding this comment

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

Digests associated to a pod entity should be removed when the latter expires. This is also something we will want to include in test scenarios.

@xlucas xlucas changed the title update labes/annotations_as_tags on value change update labels/annotations_as_tags on value change Apr 3, 2019
xlucas
xlucas previously approved these changes Apr 4, 2019
Copy link
Member

@xlucas xlucas left a comment

Choose a reason for hiding this comment

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

LGTM

tagsDigests map[string]digests
}

type digests struct {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a good reason for those hashes to be separate, or can we make a digest of both, get rid of the type, and make tagsDigests be a map[string]string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right, we can calculate a single digest of both labels and annotations and store it in a map[string]string 👍


// digestMap return a unique hash for a map
// used to track changes in labels and annotations values
func digestMap(m map[string]string) string {
Copy link
Member

Choose a reason for hiding this comment

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

I think this could take both annotations and labels, or even the whole metadata object, and return a single string for the pod (and it could be named digestPodMeta in this case). That's just a proposal, might not be the best, but the name digestMap confused me at first because I expected it to digest the whole map and it actually hashes values only.

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 I suggest:

  • rename the function to digestMapValues
  • add another function digestPodMeta which takes a metadata object as an argument
  • digestPodMeta calls digestMapValues twice to calculate digests for labels and annotations
  • digestPodMeta returns a single pod digest from both labels and annotations digests

I'd keep the digestMapValues logic (keys sorting and map values hash calculation) in a separate function to avoid duplicating it for 2 maps (labels and annotations) in digestPodMeta.
WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds great 👍 let's just make sure to define explicitly in the comment of the digestPodMeta in which order we write annotation and label hashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 👍

Copy link
Member

@hkaj hkaj left a comment

Choose a reason for hiding this comment

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

💯

@ahmed-mez ahmed-mez merged commit 163b903 into master Apr 18, 2019
@ahmed-mez ahmed-mez deleted the ahmed-mez/update-pod-labels-annotations-as-tags-on-value-change branch April 18, 2019 12:27
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