-
Notifications
You must be signed in to change notification settings - 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
Add Node affinity #1003
Changes from all commits
aeac8af
f030f70
7d0c8f1
70cad9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| 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) | ||
| values := []string{"amd64"} | ||
|
|
||
| if pod.Spec.Affinity == nil { | ||
| // In case we don't find the operator pod (local testing) or it doesn't have affinities | ||
| return values | ||
| } | ||
|
|
||
| nodeSelectorTerms := pod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms | ||
|
|
||
| for _, selector := range nodeSelectorTerms { | ||
| for _, matchExpression := range selector.MatchExpressions { | ||
| if matchExpression.Key == "kubernetes.io/arch" { | ||
| values = matchExpression.Values | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return values | ||
| } | ||
|
|
||
| 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, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,15 @@ spec: | |
| labels: | ||
| name: manageiq-operator | ||
| spec: | ||
| affinity: | ||
| nodeAffinity: | ||
| requiredDuringSchedulingIgnoredDuringExecution: | ||
| nodeSelectorTerms: | ||
| - matchExpressions: | ||
| - key: kubernetes.io/arch | ||
| operator: In | ||
| values: | ||
| - amd64 | ||
|
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also want There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||
| serviceAccountName: manageiq-operator | ||
| containers: | ||
| - name: manageiq-operator | ||
|
|
||
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.
I added a commit to default to
amd64