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

Include labelSelector for affinity and topologySpreadConstraints #4666

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pvickery-ParamountCommerce

Description

The labelSelector is used to track the pods that are used for the topologySpreadConstraints calculation. matchLabelKeys is used to only use the pods in the current version of the deployments replicaset.

I believe the following message isn't true before this PR.

# -- Topology spread constraints for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). If an explicit label selector is not provided one will be created from the pod selector labels.
topologySpreadConstraints: []

More details about matchLabelKeys can be found here:

Checklist

  • Unit tests updated
  • End user documentation updated

Copy link

linux-foundation-easycla bot commented Aug 8, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: pvickery-ParamountCommerce / name: Patrick Vickery (844bab3)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 8, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @pvickery-ParamountCommerce!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 8, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @pvickery-ParamountCommerce. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 8, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 12, 2024
Copy link
Contributor

@stevehipwell stevehipwell 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 the PR @pvickery-ParamountCommerce. The comments in values.yaml were incorrectly copied from a chart where this had been implemented. Did you also see that the same comment was present for affinity? I think we have the following 3 options:

  1. Change the comments and don't add default label selectors
  2. Implement your pattern for affinity
  3. Implement the other pattern

FYI you also need to add a chart CHANGELOG entry under [UNRELEASED].

charts/external-dns/Chart.yaml Outdated Show resolved Hide resolved
charts/external-dns/templates/deployment.yaml Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 11, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from stevehipwell. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 30, 2024
@pvickery-ParamountCommerce pvickery-ParamountCommerce changed the title Include labelSelector and matchLabelKeys for topologySpreadConstraints Include labelSelector for affinity and topologySpreadConstraints Sep 30, 2024
@pvickery-ParamountCommerce
Copy link
Author

pvickery-ParamountCommerce commented Sep 30, 2024

Thanks for the PR @pvickery-ParamountCommerce. The comments in values.yaml were incorrectly copied from a chart where this had been implemented. Did you also see that the same comment was present for affinity? I think we have the following 3 options:

1. Change the comments and don't add default label selectors

2. Implement your pattern for `affinity`

3. Implement the other pattern

FYI you also need to add a chart CHANGELOG entry under [UNRELEASED].

Thanks for the feedback @stevehipwell!
I have implemented the default label selectors in all blocks for podaffinity. I found it to be rather repetitive so let me know if you have any suggestions to simplify it.

I used these values to test affinity when automatically adding the labelSelector, and uncommented the rest to test when the user supplied values should be used.

affinity:
  podAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          topologyKey : "kubernetes.io/hostname"
        # labelSelector:
        #   matchExpressions:
        #     - key: app.kubernetes.io/name
        #       operator: In
        #       values:
        #         - test
    requiredDuringSchedulingIgnoredDuringExecution:
      - topologyKey : "kubernetes.io/hostname"
        # labelSelector:
        #   matchExpressions:
        #     - key: app.kubernetes.io/name
        #       operator: In
        #       values:
        #         - test
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          topologyKey : "kubernetes.io/hostname"
          # labelSelector:
          #   matchExpressions:
          #     - key: app.kubernetes.io/name
          #       operator: In
          #       values:
          #         - test
    requiredDuringSchedulingIgnoredDuringExecution:
      - topologyKey : "kubernetes.io/hostname"
        # labelSelector:
        #   matchExpressions:
        #     - key: app.kubernetes.io/name
        #       operator: In
        #       values:
        #         - test

Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Could you move the basic structure out into the deployment template, use smaller template functions and make use of with? Something like below (untested).

    {{- with .Values.affinity }}
      affinity:
      {{- with .podAffinity }}
        podAffinity:
        {{- with preferredDuringSchedulingIgnoredDuringExecution }}
        {{- range . }}
        {{- if dig "podAffinityTerm" "labelSelector" nil . }}
          {{- toYaml (list .) | nindent 10 }}
        {{- else }}
          {{ include "external-dns.podAffinityPreferred" . }}
        {{- end }}
        {{- end }}
        {{- end }}
      {{- end }}
      {{- end }}

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 29, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 1, 2024
@k8s-ci-robot k8s-ci-robot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 1, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 1, 2024
@pvickery-ParamountCommerce
Copy link
Author

Thanks @stevehipwell, that is a good idea! I've updated it with your suggestion and have tested it locally

Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Could you also look at updating the charts/ci/ci-values.yaml to include coverage for these changes? FYI CI uses a standard Kind cluster .

If this isn't possible we could look at adding a kubconform step to validate the templates.

charts/external-dns/templates/_helpers.tpl Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 2, 2024
@pvickery-ParamountCommerce
Copy link
Author

Thanks @stevehipwell and sorry for the delay!
I have added my test values to the ci values to setup pod (anti-)affinity and topologySpreadConstraints

@stevehipwell
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2024
@stevehipwell
Copy link
Contributor

@pvickery-ParamountCommerce this looks to be failing the lint.

@pvickery-ParamountCommerce
Copy link
Author

Ah shoot! I've updated it again to pass the linting checks. preferredDuringSchedulingIgnoredDuringExecution and requiredDuringSchedulingIgnoredDuringExecution values need to be in an array and was just in an object before

Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Just a couple of comments.

charts/external-dns/templates/_helpers.tpl Outdated Show resolved Hide resolved
charts/external-dns/templates/deployment.yaml Outdated Show resolved Hide resolved
charts/external-dns/templates/deployment.yaml Outdated Show resolved Hide resolved
@pvickery-ParamountCommerce
Copy link
Author

pvickery-ParamountCommerce commented Dec 11, 2024

One more push to fix those findings. I also updatee how the labelSelector is added to remove a useless newline. Thanks again for all the help @stevehipwell!

{{- if dig "labelSelector" nil . }}
-   - {{- toYaml . | nindent 16 }}
+   - {{ toYaml . | indent 16 | trim }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants