-
Couldn't load subscription status.
- Fork 99
Add Node affinity #1003
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
Merged
Merged
Add Node affinity #1003
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aeac8af
Refactor pod/deployment lookup logic so that it can be reused
bdunne f030f70
Use values from the operator to set Arch NodeAffinities on deployments
bdunne 7d0c8f1
Add NodeAffinities to the operator deployment
bdunne 70cad9d
default to amd64 only
bdunne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package miqutils | ||
|
|
||
| import ( | ||
| "context" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| func FindPodByName(client client.Client, namespace string, name string) *corev1.Pod { | ||
| podKey := types.NamespacedName{Namespace: namespace, Name: name} | ||
| pod := &corev1.Pod{} | ||
| client.Get(context.TODO(), podKey, pod) | ||
|
|
||
| return pod | ||
| } | ||
|
|
||
| func FindReplicaSetByName(client client.Client, namespace string, name string) *appsv1.ReplicaSet { | ||
| replicaSetKey := types.NamespacedName{Namespace: namespace, Name: name} | ||
| replicaSet := &appsv1.ReplicaSet{} | ||
| client.Get(context.TODO(), replicaSetKey, replicaSet) | ||
|
|
||
| return replicaSet | ||
| } | ||
|
|
||
| func FindDeploymentByName(client client.Client, namespace string, name string) *appsv1.Deployment { | ||
| deploymentKey := types.NamespacedName{Namespace: namespace, Name: name} | ||
| deployment := &appsv1.Deployment{} | ||
| client.Get(context.TODO(), deploymentKey, deployment) | ||
|
|
||
| return deployment | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package miqutils | ||
|
|
||
| import ( | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "os" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| func OperatorNodeAffinityArchValues(deployment *appsv1.Deployment, client client.Client) []string { | ||
| podName := os.Getenv("POD_NAME") | ||
| pod := FindPodByName(client, deployment.ObjectMeta.Namespace, podName) | ||
|
|
||
| if pod.Spec.Affinity == nil { | ||
| // In case we don't find the operator pod (local testing) or it doesn't have affinities | ||
| return []string{} | ||
| } | ||
| nodeSelectorTerms := pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms | ||
|
|
||
| for _, selector := range nodeSelectorTerms { | ||
| for _, matchExpression := range selector.MatchExpressions { | ||
| if matchExpression.Key == "kubernetes.io/arch" { | ||
| return matchExpression.Values | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // We should never get here, but the compiler requires it | ||
| return []string{} | ||
| } | ||
|
|
||
| func SetDeploymentNodeAffinity(deployment *appsv1.Deployment, client client.Client) { | ||
| operatorNodeAffinityArchValues := OperatorNodeAffinityArchValues(deployment, client) | ||
| if len(operatorNodeAffinityArchValues) == 0 { | ||
| // We're running local, can't find the operator pod, or it doesn't have any affinities to use as a template. Skip it. | ||
| return | ||
| } | ||
|
|
||
| matchExpression := corev1.NodeSelectorRequirement{ | ||
| Key: "kubernetes.io/arch", | ||
| Operator: corev1.NodeSelectorOpIn, | ||
| Values: operatorNodeAffinityArchValues, | ||
| } | ||
|
|
||
| matchExpressions := []corev1.NodeSelectorRequirement{matchExpression} | ||
|
|
||
| nodeSelectorTerm := corev1.NodeSelectorTerm{ | ||
| MatchExpressions: matchExpressions, | ||
| } | ||
|
|
||
| nodeSelectionTerms := []corev1.NodeSelectorTerm{nodeSelectorTerm} | ||
|
|
||
| deployment.Spec.Template.Spec.Affinity = &corev1.Affinity{ | ||
| NodeAffinity: &corev1.NodeAffinity{ | ||
| RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{ | ||
| NodeSelectorTerms: nodeSelectionTerms, | ||
| }, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we also want
s390xandppc64lelike in downstream?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.
We don't build those targets in upstream, so no? I'm not sure how this will work in downstream though if we have additional arches.
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.
In downstream we have a separate setNodeAffinity function that adds the other arches to the Kafka CR
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, we only build x86_64 upstream
We don't use this file downstream. The downstream operator will deploy the manageiq operator with the correct values.