diff --git a/lib/shared/addon/components/form-affinity-k8s/component.js b/lib/shared/addon/components/form-affinity-k8s/component.js
index 71fa03515..642c0e904 100644
--- a/lib/shared/addon/components/form-affinity-k8s/component.js
+++ b/lib/shared/addon/components/form-affinity-k8s/component.js
@@ -86,15 +86,110 @@ export default Component.extend({
value: null,
mode: 'new',
- podAffinity: computed('value.podAffinity', function(){
- return get(this.value, 'podAffinity') || {}
+ actions: {
+ affinityChanged(key, val){
+ // TODO nb update affinity
+ console.log('affinity ', key, ' changed to: ', val)
+ }
+ },
+
+ podAffinity: computed('value.podAffinity.{preferredDuringSchedulingIgnoredDuringExecution,requiredDuringSchedulingIgnoredDuringExecution}', {
+ get(){
+ if (!this.value?.podAffinity){
+ set(this.value, 'podAffinity', {})
+ }
+ this.initPreferredRequired(this.value.podAffinity)
+
+ return get(this.value, 'podAffinity')
+ },
+ set(key, val){
+ // TODO nb move withoutId to own function
+ const withoutId = {
+ preferredDuringSchedulingIgnoredDuringExecution: (val.preferredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ }),
+ requiredDuringSchedulingIgnoredDuringExecution: (val.requiredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ })
+ }
+
+ set(this.value, 'podAffinity', withoutId)
+ this.notifyPropertyChange('value')
+
+ return val
+ }
}),
- podAntiAffinity: computed('value.podAntiAffinity', function(){
- return get(this.value, 'podAntiAffinity') || {}
+ podAntiAffinity: computed('value.podAntiAffinity.{preferredDuringSchedulingIgnoredDuringExecution,requiredDuringSchedulingIgnoredDuringExecution}', {
+ get(){
+ if (!this.value?.podAntiAffinity){
+ set(this.value, 'podAntiAffinity', {})
+ }
+ this.initPreferredRequired(this.value.podAntiAffinity)
+
+ return get(this.value, 'podAntiAffinity')
+ },
+ set(key, val){
+ const withoutId = {
+ preferredDuringSchedulingIgnoredDuringExecution: (val.preferredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ }),
+ requiredDuringSchedulingIgnoredDuringExecution: (val.requiredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ })
+ }
+
+ set(this.value, 'podAntiAffinity', withoutId)
+ this.notifyPropertyChange('value')
+
+ return val
+ }
}),
- nodeAffinity: computed('value.nodeAffinity', function(){
- return get(this.value, 'nodeAffinity') || {}
+ nodeAffinity: computed('value.nodeAffinity.{preferredDuringSchedulingIgnoredDuringExecution,requiredDuringSchedulingIgnoredDuringExecution}', {
+ get(){
+ if (!this.value?.nodeAffinity){
+ set(this.value, 'nodeAffinity', {})
+ }
+ this.initPreferredRequired(this.value.nodeAffinity)
+
+ return get(this.value, 'nodeAffinity')
+ },
+ set(key, val){
+ const withoutId = {
+ preferredDuringSchedulingIgnoredDuringExecution: (val.preferredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ }),
+ requiredDuringSchedulingIgnoredDuringExecution: (val.requiredDuringSchedulingIgnoredDuringExecution || []).map((term) => {
+ delete term._id;
+
+ return term
+ })
+ }
+
+ set(this.value, 'nodeAffinity', withoutId)
+ this.notifyPropertyChange('value')
+
+ return val
+ }
}),
+
+ initPreferredRequired: (val) => {
+ if (!val.preferredDuringSchedulingIgnoredDuringExecution){
+ set(val, 'preferredDuringSchedulingIgnoredDuringExecution', [])
+ }
+ if (!val.requiredDuringSchedulingIgnoredDuringExecution){
+ set(val, 'requiredDuringSchedulingIgnoredDuringExecution', [])
+ }
+ }
})
\ No newline at end of file
diff --git a/lib/shared/addon/components/form-affinity-k8s/template.hbs b/lib/shared/addon/components/form-affinity-k8s/template.hbs
index a690d74fa..537cde67f 100644
--- a/lib/shared/addon/components/form-affinity-k8s/template.hbs
+++ b/lib/shared/addon/components/form-affinity-k8s/template.hbs
@@ -9,13 +9,9 @@