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

[grafana] Use .Values.podLabels in service definition. #3105

Closed
wants to merge 3 commits into from

Conversation

ikogan
Copy link

@ikogan ikogan commented Apr 29, 2024

Currently, if you set .Values.podLabels in your values.yaml, they are not reflected in the service selectors so traffic does not reach Grafana pods.

This simply adds .Values.podLabels to the service selectors.

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@Sheikh-Abubaker Sheikh-Abubaker left a comment

Choose a reason for hiding this comment

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

@ikogan Could you please sign the DCO ? Thanks!

@zanhsieh zanhsieh changed the title Grafana: Use .Values.podLabels in service definition. [grafana] Use .Values.podLabels in service definition. Aug 18, 2024
Copy link
Collaborator

@jkroepke jkroepke left a comment

Choose a reason for hiding this comment

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

grafana.selectorLabels should still sufficient for matching pods

@Sheikh-Abubaker
Copy link
Collaborator

Sheikh-Abubaker commented Aug 19, 2024

grafana.selectorLabels should still sufficient for matching pods

@jkroepke That's right! but what if the some users find it more convinient to include the labels directly from the values.yaml instead of _helpers.tpl ?

@jkroepke
Copy link
Collaborator

No. .Values.podLabels is designed to put additional labels on a pod.

The helper grafana.selectorLabels is used on deploy.spec.selector.matchLabels which is an immutable field.

If .Values.podLabels would be part of grafana.selectorLabels, the end-user always needs to manually delete the grafana deployment before changing .Values.podLabels.

The currently implementation is fine and should not be changed in my opinion.

@ikogan
Copy link
Author

ikogan commented Aug 19, 2024

For the DCO, do you just want an empty commit with the sign-off or to amend the one commit I made for this?

@ikogan
Copy link
Author

ikogan commented Aug 19, 2024

No. .Values.podLabels is designed to put additional labels on a pod.

The helper grafana.selectorLabels is used on deploy.spec.selector.matchLabels which is an immutable field.

If .Values.podLabels would be part of grafana.selectorLabels, the end-user always needs to manually delete the grafana deployment before changing .Values.podLabels.

The currently implementation is fine and should not be changed in my opinion.

By "the current implementation" do you mean in the PR or in main?

@jkroepke
Copy link
Collaborator

jkroepke commented Aug 19, 2024

current implementation in main. You can add additional pod labels on your choice, however not all labels must be defined in a selector on a service.

@Sheikh-Abubaker
Copy link
Collaborator

No. .Values.podLabels is designed to put additional labels on a pod.

The helper grafana.selectorLabels is used on deploy.spec.selector.matchLabels which is an immutable field.

If .Values.podLabels would be part of grafana.selectorLabels, the end-user always needs to manually delete the grafana deployment before changing .Values.podLabels.

The currently implementation is fine and should not be changed in my opinion.

That's correct! seems like I mistaken it for something else.

@Sheikh-Abubaker
Copy link
Collaborator

current implementation in main. You can add additional pod labels on your choice, however not all labels must be defined in a selector on a service.

@jkroepke guess we're closing this then ?

@jkroepke jkroepke closed this Aug 21, 2024
@ikogan
Copy link
Author

ikogan commented Aug 24, 2024

current implementation in main. You can add additional pod labels on your choice, however not all labels must be defined in a selector on a service.

But doesn't this mean that if you use .Values.podLabels then there's no way for the service generated by the helm chart to actually ever work? What's the point of generating a knowingly broken service?

@jkroepke
Copy link
Collaborator

Please, explain, why the service would be broken? The service selector based on grafana.selectorLabels template and the pod has the labels from grafana.selectorLabels template. With Values.podLabels, you could define additional labels, but the selector still matches, even just a sub-set of labels matched.

@ikogan
Copy link
Author

ikogan commented Aug 24, 2024

Please, explain, why the service would be broken? The service selector based on grafana.selectorLabels template and the pod has the labels from grafana.selectorLabels template. With Values.podLabels, you could define additional labels, but the selector still matches, even just a sub-set of labels matched.

Sorry, it's been a minute since I had the issue and I had my issue wrong. Since I'm deploying Grafana as a subchart of another chart, the selectorLabels generated match all of the pods generated by that chart, including non-Grafana pods. So, in fact, the service ends up matching more than it should.

I don't see a way in the helm chart to impact the selector labels that the service uses. Right now my only recourse is to disable the service entirely and generate my own.

@jkroepke
Copy link
Collaborator

jkroepke commented Aug 24, 2024

Since I'm deploying Grafana as a subchart of another chart, the selectorLabels generated match all of the pods generated by that chart, including non-Grafana pods. So, in fact, the service ends up matching more than it should.

This case happens if your umbralla chart contains multiple charts named grafana?

Because of part of the grafana selector labels named app.kubernetes.io/name: grafana where the app.kubernetes.io/name is the name of the chart.

For such scenarios, nameOverride can be used to etablish an unique selector

So, in fact, the service ends up matching more than it should.

That case, you current deployment strategy is broken. If grafana.selectorLabels matches more pod than it should, the selector at Deployment level is affected from that issue, too.

selector:
matchLabels:
{{- include "grafana.selectorLabels" . | nindent 6 }}

If we are merging this PR, this issue would more hidden and lead to undefined behavior in Kubernetes.

Note

You should not create other Pods whose labels match this selector, either directly, by creating another Deployment, or by creating another controller such as a ReplicaSet or a ReplicationController. If you do so, the first Deployment thinks that it created these other Pods. Kubernetes does not stop you from doing this.

Ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#selector


To address that kind of issue, .Values.podLabels must be also part of the Deployment.spec.selector configuration. The issue here is that this field is immutable and could not update after initial deployment.

@ikogan
Copy link
Author

ikogan commented Aug 30, 2024

It contains a single chart named Grafana but I'm also adding oncall as a subchart. This causes all of the oncall deployments to have the same pod labels. In my values, I simply have fullnameOverride under the grafana key set to grafana and fullnameOverride under the oncall key set to oncall. Nevertheless, I end up with, for example, the RabbitMQ service that comes with oncall targeting these selectors:

app.kubernetes.io/name: grafana
app.kubernetes.io/instance: grafana

You're right that this all runs deeper than the podLabels thing posted earlier. I suppose I'll have to dig more into why these selectors are being generated this way.

@jkroepke
Copy link
Collaborator

This causes all of the oncall deployments to have the same pod labels.

But that is strange. Is the sub-chart name of oncall, grafana too?

Did you define nameOverride somewhere? Normally, the name of the chart is used as selector. Even for sub chart components, the name of the sub chart it used unless nameOverride is set.

fullnameOverride has no effect for selectorLabels.

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.

5 participants