Voltha stacks on same node

Change-Id: Ide97ca9ed76c206e51d424dcb427854e119efa24
diff --git a/voltha-adapter-openolt/Chart.yaml b/voltha-adapter-openolt/Chart.yaml
index ab05d1d..4f02794 100644
--- a/voltha-adapter-openolt/Chart.yaml
+++ b/voltha-adapter-openolt/Chart.yaml
@@ -14,7 +14,7 @@
 ---
 apiVersion: "v1"
 name: "voltha-adapter-openolt"
-version: "2.10.1"
+version: "2.10.3"
 description: "A Helm chart for Voltha OpenOLT Adapter"
 keywords:
   - "onf"
diff --git a/voltha-adapter-openolt/templates/openolt-deploy.yaml b/voltha-adapter-openolt/templates/openolt-deploy.yaml
index 623c280..3eb979f 100644
--- a/voltha-adapter-openolt/templates/openolt-deploy.yaml
+++ b/voltha-adapter-openolt/templates/openolt-deploy.yaml
@@ -66,8 +66,8 @@
         runAsGroup: {{ .Values.securityContext.runAsGroup }}
         fsGroup: {{ .Values.securityContext.fsGroup }}
       {{- end }}
-      {{- if .Values.nodeAffinityConfig.enabled }}
       affinity:
+        {{- if .Values.nodeAffinityConfig.enabled }}
         nodeAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
             nodeSelectorTerms:
@@ -76,7 +76,33 @@
                 operator: In
                 values:
                 - "{{ .Values.nodeAffinityConfig.node_label_value }}"
-      {{- end }}
+        {{- end }}
+        podAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStackPodsOnSameNode }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/stack
+                      operator: In
+                      values:
+                        - {{ .Values.global.stack_name }}
+              weight: 100
+            {{- end }}
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStacksOnDifferentNodes }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/name
+                      operator: In
+                      values:
+                        - adapter-open-olt
+              weight: 100
+            {{- end }}
       containers:
         - name: adapter-open-olt
           image: '{{ tpl .Values.images.adapter_open_olt.registry . }}{{ tpl .Values.images.adapter_open_olt.repository . }}:{{ tpl ( tpl .Values.images.adapter_open_olt.tag . ) . }}'
diff --git a/voltha-adapter-openolt/values.yaml b/voltha-adapter-openolt/values.yaml
index 431bbfd..b5224b5 100644
--- a/voltha-adapter-openolt/values.yaml
+++ b/voltha-adapter-openolt/values.yaml
@@ -106,3 +106,8 @@
   limits:
     cpu: ~
     memory: ~
+
+# Define scheduling rules for stack pods
+scheduleRules:
+  preferStackPodsOnSameNode: false
+  preferStacksOnDifferentNodes: false
diff --git a/voltha-adapter-openonu/Chart.yaml b/voltha-adapter-openonu/Chart.yaml
index dd43fc5..82ed385 100644
--- a/voltha-adapter-openonu/Chart.yaml
+++ b/voltha-adapter-openonu/Chart.yaml
@@ -14,7 +14,7 @@
 ---
 apiVersion: "v1"
 name: "voltha-adapter-openonu"
-version: "2.9.3"
+version: "2.9.4"
 description: "A Helm chart for Voltha OpenONU Adapter"
 keywords:
   - "onf"
diff --git a/voltha-adapter-openonu/templates/openonu-go-deploy.yaml b/voltha-adapter-openonu/templates/openonu-go-deploy.yaml
index ccf984e..72c2771 100644
--- a/voltha-adapter-openonu/templates/openonu-go-deploy.yaml
+++ b/voltha-adapter-openonu/templates/openonu-go-deploy.yaml
@@ -134,3 +134,30 @@
               {{- if .Values.resources.limits.cpu }}
               cpu: {{ .Values.resources.limits.cpu }}
               {{- end }}
+      affinity:
+        podAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStackPodsOnSameNode }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/stack
+                      operator: In
+                      values:
+                        - {{ .Values.global.stack_name }}
+              weight: 100
+            {{- end }}
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStacksOnDifferentNodes }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/name
+                      operator: In
+                      values:
+                        - adapter-open-onu
+              weight: 100
+            {{- end }}
diff --git a/voltha-adapter-openonu/values.yaml b/voltha-adapter-openonu/values.yaml
index 2ac4f8c..0d4b7f5 100644
--- a/voltha-adapter-openonu/values.yaml
+++ b/voltha-adapter-openonu/values.yaml
@@ -132,3 +132,8 @@
   limits:
     cpu: ~
     memory: ~
+
+# Define scheduling rules for stack pods
+scheduleRules:
+  preferStackPodsOnSameNode: false
+  preferStacksOnDifferentNodes: false
diff --git a/voltha-stack/Chart.yaml b/voltha-stack/Chart.yaml
index 32af320..a654739 100644
--- a/voltha-stack/Chart.yaml
+++ b/voltha-stack/Chart.yaml
@@ -28,18 +28,18 @@
 name: voltha-stack
 
 appVersion: "2.9-dev"
-version: 2.9.4
+version: 2.9.5
 
 dependencies:
   - name: voltha
     repository: file://../voltha
-    version: 2.10.2
+    version: 2.10.4
     condition: voltha.enabled
   - name: voltha-adapter-openonu
     repository: file://../voltha-adapter-openonu
-    version: 2.9.2
+    version: 2.9.4
     condition: voltha-adapter-openonu.enabled
   - name: voltha-adapter-openolt
     repository: file://../voltha-adapter-openolt
-    version: 2.10.0
+    version: 2.10.3
     condition: voltha-adapter-openolt.enabled
diff --git a/voltha/Chart.yaml b/voltha/Chart.yaml
index 60088be..394da55 100644
--- a/voltha/Chart.yaml
+++ b/voltha/Chart.yaml
@@ -14,7 +14,7 @@
 ---
 apiVersion: "v1"
 name: "voltha"
-version: "2.10.3"
+version: "2.10.4"
 description: "A Helm chart for Voltha based on K8S resources in Voltha project"
 keywords:
   - "onf"
diff --git a/voltha/templates/core-deploy.yaml b/voltha/templates/core-deploy.yaml
index 7134aca..84f13e4 100644
--- a/voltha/templates/core-deploy.yaml
+++ b/voltha/templates/core-deploy.yaml
@@ -137,3 +137,30 @@
               {{- if .Values.resources.rw_core.limits.cpu }}
               cpu: {{ .Values.resources.rw_core.limits.cpu }}
               {{- end }}
+      affinity:
+        podAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStackPodsOnSameNode }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/stack
+                      operator: In
+                      values:
+                        - {{ .Values.global.stack_name }}
+              weight: 100
+            {{- end }}
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStacksOnDifferentNodes }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/name
+                      operator: In
+                      values:
+                        - read-write-core
+              weight: 100
+            {{- end }}
diff --git a/voltha/templates/ofagent-deploy.yaml b/voltha/templates/ofagent-deploy.yaml
index 112b348..2aac00c 100644
--- a/voltha/templates/ofagent-deploy.yaml
+++ b/voltha/templates/ofagent-deploy.yaml
@@ -137,3 +137,30 @@
               {{- if .Values.resources.ofagent.limits.cpu }}
               cpu: {{ .Values.resources.ofagent.limits.cpu }}
               {{- end }}
+      affinity:
+        podAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStackPodsOnSameNode }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/stack
+                      operator: In
+                      values:
+                        - {{ .Values.global.stack_name }}
+              weight: 100
+            {{- end }}
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+            {{- if .Values.scheduleRules.preferStacksOnDifferentNodes }}
+            - podAffinityTerm:
+                topologyKey: kubernetes.io/hostname
+                labelSelector:
+                  matchExpressions:
+                    - key: app.kubernetes.io/name
+                      operator: In
+                      values:
+                        - open-flow-agent
+              weight: 100
+            {{- end }}
diff --git a/voltha/values.yaml b/voltha/values.yaml
index 2bc6ea6..b25670b 100644
--- a/voltha/values.yaml
+++ b/voltha/values.yaml
@@ -141,3 +141,8 @@
     limits:
       cpu: ~
       memory: ~
+
+# Define scheduling rules for stack pods
+scheduleRules:
+  preferStackPodsOnSameNode: false
+  preferStacksOnDifferentNodes: false