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

Adding custom labels #53

Merged
merged 25 commits into from
Feb 24, 2023
Merged

Adding custom labels #53

merged 25 commits into from
Feb 24, 2023

Conversation

gtrkiller
Copy link
Contributor

This PR focuses on the creation of a custom label for both services and ingresses, to not be dependant on the app.juju.is/created-by= label.

@gtrkiller gtrkiller requested a review from a team as a code owner February 10, 2023 18:15
@gtrkiller gtrkiller marked this pull request as draft February 10, 2023 18:15
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
@gtrkiller gtrkiller marked this pull request as ready for review February 14, 2023 18:05
merkata
merkata previously approved these changes Feb 14, 2023
Copy link
Contributor

@merkata merkata left a comment

Choose a reason for hiding this comment

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

Looks good! I wonder if we shouldn't namespace the label like juju is doing, though that is just food for thought.

Copy link
Contributor

@jdkandersson jdkandersson left a comment

Choose a reason for hiding this comment

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

I still don't see an upgrade test, maybe I missed it?

tests/integration/conftest.py Outdated Show resolved Hide resolved
tests/integration/conftest.py Show resolved Hide resolved
@jdkandersson
Copy link
Contributor

jdkandersson commented Feb 15, 2023

Since we are making a change to the behaviour (a label is now a different value), an upgrade test from a version of the charm that used to old label to the new label would help us ensure that we don't cause any issues for any users that upgrade. What do you think?

@mthaddon
Copy link
Contributor

mthaddon commented Feb 15, 2023

Looks good! I wonder if we shouldn't namespace the label like juju is doing, though that is just food for thought.

Yeah, I kind of agree that the label just being created-by is a big too generic. created-by-juju-application seems better, but looking at https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/ this one jumps out as being relevant:

Key                          | Description                                                   | Example | Type
app.kubernetes.io/managed-by | The tool being used to manage the operation of an application | helm    | string

Based on this I'd go with app.kubernetes.io/managed-by=juju-application-{self.app.name} after confirming this label isn't already set. Would be interested in other people's thoughts about this as well.

@gtrkiller
Copy link
Contributor Author

gtrkiller commented Feb 15, 2023

Regarding the new and old labels, the old label (app.juju.is/created-by=) is still there, since it is created on Juju's side and not by the charm. That means we now have two labels, the juju label and our new custom label. So, is it really necessary to have an upgrade test since the old label hasn't been removed? The ingress and service definition/update takes place only when the config or relations are changed, not in an upgrade event. I tested an upgrade and the ingress worked just fine.

@amandahla
Copy link
Contributor

amandahla commented Feb 15, 2023

Looks good! I wonder if we shouldn't namespace the label like juju is doing, though that is just food for thought.

Yeah, I kind of agree that the label just being created-by is a big too generic. created-by-juju-application seems better, but looking at https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/ this one jumps out as being relevant:

Key                          | Description                                                   | Example | Type
app.kubernetes.io/managed-by | The tool being used to manage the operation of an application | helm    | string

Based on this I'd go with app.kubernetes.io/managed-by=juju-application-{self.app.name} after confirming this label isn't already set. Would be interested in other people's thoughts about this as well.

I liked this but I think it might conflict here:
https://github.com/juju/juju/blob/develop/caas/kubernetes/provider/constants/labels.go#L19
For namespaces:

mymodel                      Active   4h9m    app.kubernetes.io/managed-by=juju,kubernetes.io/metadata.name=mymodel,model.juju.is/name=mymodel

I'm considering the idea of using the same label "app.juju.is/created-by". So will be applied even if is not done by Juju.

@jdkandersson
Copy link
Contributor

Regarding the new and old labels, the old label (app.juju.is/created-by=) is still there, since it is created on Juju's side and not by the charm. That means we now have two labels, the juju label and our new custom label. So, is it really necessary to have an upgrade test since the old label hasn't been removed? The ingress and service definition/update takes place only when the config or relations are changed, not in an upgrade event. I tested an upgrade and the ingress worked just fine.

I was more thinking that during an upgrade the new custom label may not be present when the charm code assumes it is there - hence the upgrade test. It would be good to see the test methodology and the outcome just to see if anyone has any feedback

@mthaddon
Copy link
Contributor

I'm considering the idea of using the same label "app.juju.is/created-by". So will be applied even if is not done by Juju.

I think this is a great idea. And thanks for finding the issue with my other suggestion. I'd switch my vote to this approach.

@weiiwang01
Copy link
Contributor

Another approach is to create a new label prefix for the Nginx ingress integrator charm. The advantage of this option is that we can create as many labels as we want without having to worry about conflicts.

For example:

nginx-ingress-integrator.charm.canonical.com/managed-by=<ingress-app-name>
nginx-ingress-integrator.charm.canonical.com/created-for=<app-name>

@amandahla
Copy link
Contributor

Another approach is to create a new label prefix for the Nginx ingress integrator charm. The advantage of this option is that we can create as many labels as we want without having to worry about conflicts.

For example:

nginx-ingress-integrator.charm.canonical.com/managed-by=<ingress-app-name>
nginx-ingress-integrator.charm.canonical.com/created-for=<app-name>

I'm afraid that in this case would be redundant (and pretty close to the limit of label size)
Also, I guess that a valid DNS should be used like juju.is

@weiiwang01
Copy link
Contributor

Another approach is to create a new label prefix for the Nginx ingress integrator charm. The advantage of this option is that we can create as many labels as we want without having to worry about conflicts.
For example:

nginx-ingress-integrator.charm.canonical.com/managed-by=<ingress-app-name>
nginx-ingress-integrator.charm.canonical.com/created-for=<app-name>

I'm afraid that in this case would be redundant (and pretty close to the limit of label size) Also, I guess that a valid DNS should be used like juju.is

The limit of 63 characters only applies to the name segment i.e. the segment after /, the prefix segment can have another 253 characters.

And yes, we can change the prefix to nginx-ingress-integrator.charm.juju.is, the exact prefix value is still up to debate.

@weiiwang01
Copy link
Contributor

Another approach is to create a new label prefix for the Nginx ingress integrator charm. The advantage of this option is that we can create as many labels as we want without having to worry about conflicts.
For example:

nginx-ingress-integrator.charm.canonical.com/managed-by=<ingress-app-name>
nginx-ingress-integrator.charm.canonical.com/created-for=<app-name>

I'm afraid that in this case would be redundant (and pretty close to the limit of label size) Also, I guess that a valid DNS should be used like juju.is

The limit of 63 characters only applies to the name segment i.e. the segment after /, the prefix segment can have another 253 characters.

And yes, we can change the prefix to nginx-ingress-integrator.charm.juju.is, the exact prefix value is still up to debate.

I think if we choose the customized prefix solution here, we will create a new pattern / convention. Other charm that manages the Kubernetes resources can all have similar label names like this: <charm-name>.charm.juju.is/<name> if they want to add labels to the resources.

@mthaddon
Copy link
Contributor

There have been a number of comments about this on the discourse thread, but let's go ahead with nginx-ingress-integrator.charm.juju.is/managed-by for now and we can easily update this if changed later.

@github-actions
Copy link
Contributor

Test coverage for e912e7e

Name           Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------
src/charm.py     414     25    166      7    93%   342->344, 439-441, 445-450, 454-455, 459-460, 464-469, 484-486, 591->616, 820->exit, 871, 897->928, 915-926
----------------------------------------------------------
TOTAL            414     25    166      7    93%

Static code analysis report

Run started:2023-02-24 16:52:37.267652

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 3083
  Total lines skipped (#nosec): 3
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 1

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

Copy link
Contributor

@mthaddon mthaddon left a comment

Choose a reason for hiding this comment

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

LGTM, thx

Copy link
Contributor

@amandahla amandahla left a comment

Choose a reason for hiding this comment

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

Nice :)

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.

6 participants