From 3da4135901b4d397c7b2854a432063f47b62cdf5 Mon Sep 17 00:00:00 2001
From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com>
Date: Mon, 17 Apr 2023 07:18:02 -0700
Subject: [PATCH] pod affinity/antiaffinity preferred/required dropdowns
---
.../components/form-affinity-k8s/component.js | 107 ++++++++-
.../components/form-affinity-k8s/template.hbs | 10 +-
.../components/form-agent-config/component.js | 3 +-
.../form-pod-affinity-k8s/component.js | 220 +++++++++++++++++-
.../form-pod-affinity-k8s/template.hbs | 34 +--
.../form-pod-affinity-term-k8s/component.js | 65 +++++-
.../form-pod-affinity-term-k8s/template.hbs | 28 +++
translations/en-us.yaml | 9 +-
8 files changed, 421 insertions(+), 55 deletions(-)
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 @@