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(labels): propagates labels to Deployment's spec.template #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bartoszmajsak
Copy link
Contributor

PR #91 brought the ability to propagate labels defined for Authorino CR
down to Deployment. However, more often than not, it's more desired to
have those labels propagated to template and therefore pods which are
part of the deployment. This can simplify e.g. making Authorino part of
service mesh, as injection label can be consistently added to relevant
resources.

When creating the deployment, instead of having fixed set of labels for
Deployment's spec.template this change appends Authorino CR labels as
well.

PR Kuadrant#91 brought the ability to propagate labels defined for Authorino CR
down to Deployment. However, more often than not, it's more desired to
have those labels propagated to template and therefore pods which are
part of the deployment. This can simplify e.g. making Authorino part of
service mesh, as injection label can be consistently added to relevant
resources.

When creating the deployment, instead of having fixed set of labels for
Deployment's `spec.template` this change appends Authorino CR labels as
well.

Signed-off-by: bartoszmajsak <bartosz.majsak@gmail.com>
@bartoszmajsak bartoszmajsak force-pushed the label-propagation-fix branch from d58757e to fe08b87 Compare January 9, 2025 18:13
Signed-off-by: bartoszmajsak <bartosz.majsak@gmail.com>
Copy link
Contributor

@KevFan KevFan 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 your contribution @bartoszmajsak. Nice work 👍

I've left a comment on some further consideration around updates and upgrades. Let me know your thoughts 🧑‍💻

Comment on lines 10 to +14
objMeta := getObjectMeta(namespace, name, labels)
authorinoLabels := labelsForAuthorino(name)
for key, value := range labels {
authorinoLabels[key] = value
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works well for the inital creation of an Authorino CR but there's a few things missing that require some further consideration for this to work for if an existing Authorino CR labels is updated also:

  1. The comparison logic for labels to determine if the Authorino CR has changed is currently missing and needs to be added. Currently, the labels is not compared so it will not be updated if the labels are changed.
  1. Once 1) is addressed and updating labels is allowed, the current logic will also update the deployment.spec.matchLabels which are immutable once set. Because these labels are immutable, the update will never succeed with an error from the API server
  • Selector: &v1.LabelSelector{
    MatchLabels: authorinoLabels,
    },
  • Not sure do we want a separate podLabels map of labels that contains the hardcoded authorinoLabels and the Authorino CR labels and use this in the deployment pod template. The matchLabel should always just use the hardcoded labels 🤔
  1. There is a possibilty that the labels defined in the Authorino CR can overwrite the hardcoded labels in labelsForAuthorino function, which then hit into 2) where the we attempt to update the deployment.spec.matchLabels. The hardcoded labels should take precedence in this case the prevent this 🤔

Other considerations around upgrade are:

  1. This currently do not respect any user added labels to deployment.spec.template.labels 🤔. In this case, if the deployment is upgraded, any user added labels will be lost since only the labels currently present on the Authorino CR and the hardcoded labels is kept. We should do a "smart" merge of labels where:
  • Known hardcoded labels take precedence
  • Merge Authorino CR labels
  • Keep any other user added labels already added to the deployment pod template.

This will however mean there's a wider scope of change as the desired deployment will need awareness of the existing deployment pod template labels

@eguzki Let me know if I've missed anything or if you have any thoughts on these suggestions.

@bartoszmajsak What are your thought on the above?

Copy link
Contributor Author

@bartoszmajsak bartoszmajsak Jan 20, 2025

Choose a reason for hiding this comment

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

These are all valid points. Thanks for your thorough analysis.

Do you want me to expand this PR based on this discussion or is something to be done as a follow-up? Happy to work on it either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I think it would be nicer to exapnd this PR based on this discussion, especially for points 1 - 3 for accounting for updates.

However, If you feel the PR change would get too big though, I think the smart merge bit for upgrades can be done as follow-up/seperate PR. Let me know if you prefer this. Thanks for taking on this work 👍

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.

3 participants