-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for preferredDuringSchedulingIgnoredDuringExecution #73
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: idgenchev <1568180+idgenchev@users.noreply.github.com>
Co-authored-by: idgenchev <1568180+idgenchev@users.noreply.github.com>
README.md
Outdated
| It is a replacement for the [PodNodeSelector](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podnodeselector) admission controller and it is useful when using a managed k8s control plane such as [GKE](https://cloud.google.com/kubernetes-engine) or [EKS](https://aws.amazon.com/eks) where you do not have the ability to enable additional admission controller plugins and the [PodNodeSelector](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podnodeselector) might not be available. The only admission controller plugin required to run the namespace-node-affinity mutating webhook is the `MutatingAdmissionWebhook` which is already enabled on most managed Kubernetes services such as [EKS](https://docs.aws.amazon.com/eks/latest/userguide/platform-versions.html). | ||
|
|
||
| It might still be useful on [AKS](https://azure.microsoft.com/en-gb/services/kubernetes-service/) where the [PodNodeSelector](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podnodeselector) admission controller is [readily available](https://docs.microsoft.com/en-us/azure/aks/faq#what-kubernetes-admission-controllers-does-aks-support-can-admission-controllers-be-added-or-removed) as using `namespace-node-affinity` allows a litte bit more flexibility than the node selector by allowing you to set node affinity (only `requiredDuringSchedulingIgnoredDuringExecution` is supported for now) for all pods in the namespace. | ||
| It might still be useful on [AKS](https://azure.microsoft.com/en-gb/services/kubernetes-service/) where the [PodNodeSelector](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podnodeselector) admission controller is [readily available](https://docs.microsoft.com/en-us/azure/aks/faq#what-kubernetes-admission-controllers-does-aks-support-can-admission-controllers-be-added-or-removed) as using `namespace-node-affinity` allows a litte bit more flexibility than the node selector by allowing you to set node affinity (both `requiredDuringSchedulingIgnoredDuringExecution` and `preferredDuringSchedulingIgnoredDuringExecution` are supported) for all pods in the namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to specify that requiredDuringSchedulingIgnoredDuringExecution and preferredDuringSchedulingIgnoredDuringExecution are supported anymore as these are the only two options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to remove the specific mention of the two types in commit 40b3f35.
examples/sample_configmap.yaml
Outdated
| operator: "Exists" | ||
| effect: "NoSchedule" | ||
| testing-ns-preferred: | | ||
| preferredDuringSchedulingIgnoredDuringExecution: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming here becomes inconsistent and confusing. Something like preferredNodeSelectorTerms will work better as we already have nodeSelectorTerms and I'd like to keep that as is for backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed from preferredDuringSchedulingIgnoredDuringExecution to preferredNodeSelectorTerms in commit 40b3f35 for naming consistency.
injector/injector.go
Outdated
| AddPreferredDuringScheduling = "/spec/affinity/nodeAffinity/preferredDuringSchedulingIgnoredDuringExecution" | ||
| AddToPreferredDuringScheduling = "/spec/affinity/nodeAffinity/preferredDuringSchedulingIgnoredDuringExecution/-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, with the naming. Maybe something like AddPreferredNodeSelectorTerms will work better here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed constants to AddPreferredNodeSelectorTerms and AddToPreferredNodeSelectorTerms in commit 40b3f35.
injector/injector.go
Outdated
| Tolerations []corev1.Toleration `json:"tolerations"` | ||
| ExcludedLabels map[string]string `json:"excludedLabels"` | ||
| NodeSelectorTerms []corev1.NodeSelectorTerm `json:"nodeSelectorTerms"` | ||
| PreferredDuringSchedulingIgnoredDuringExecution []corev1.PreferredSchedulingTerm `json:"preferredDuringSchedulingIgnoredDuringExecution"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well - PreferredNodeSelectorTerms will work better if the NodeSelectorTerms filed is kept as is for backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated struct field to PreferredNodeSelectorTerms in commit 40b3f35 to maintain consistency with NodeSelectorTerms.
Co-authored-by: idgenchev <1568180+idgenchev@users.noreply.github.com>
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #73 +/- ##
==========================================
+ Coverage 83.27% 84.65% +1.37%
==========================================
Files 3 3
Lines 305 365 +60
==========================================
+ Hits 254 309 +55
- Misses 48 52 +4
- Partials 3 4 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds soft node affinity constraints to complement the existing hard
requiredDuringSchedulingIgnoredDuringExecutionsupport. This enables prioritizing spot/preemptible nodes while falling back to regular nodes when unavailable.Changes
Core implementation:
NamespaceConfigwithPreferredNodeSelectorTermsfield (usespreferredNodeSelectorTermsin config for consistency withnodeSelectorTerms)buildPreferredAffinityPath,buildPreferredAffinityPatch,buildPreferredAffinityInitPatch)buildPatch()to handle preferred affinity alongside required affinitynodeSelectorTerms,preferredNodeSelectorTerms, ortolerationsDocumentation:
Naming convention:
preferredNodeSelectorTermsfor consistency with existingnodeSelectorTermsfield, maintaining backwards compatibilityExample Usage
Prefer spot nodes but allow fallback to any node:
Require dedicated nodes, prefer spot subset:
The implementation follows the same JSON patch approach as existing required affinity support, ensuring consistency and compatibility.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.