Fix: service selector preview does not consider namespace

This fixes the selector preview box on the service create and edit form to only show selected pods from the same namespace

Fixes https://github.com/rancher/dashboard/issues/6984

Signed-off-by: Bastian Hofmann <bashofmann@gmail.com>
This commit is contained in:
Bastian Hofmann 2022-09-23 16:32:50 +02:00
parent c965cf9921
commit 2b7cc32cda
1 changed files with 7 additions and 5 deletions

View File

@ -198,7 +198,8 @@ export default {
},
watch: {
'value.spec.selector': 'updateMatchingPods',
'value.metadata.namespace': 'updateMatchingPods',
'value.spec.selector': 'updateMatchingPods',
'value.spec.sessionAffinity'(val) {
if (val === 'ClientIP') {
this.value.spec.sessionAffinityConfig = { clientIP: { timeoutSeconds: null } };
@ -240,21 +241,22 @@ export default {
methods: {
updateMatchingPods: throttle(function() {
const { allPods, value: { spec: { selector = { } } } } = this;
const { value: { spec: { selector = { } } } } = this;
const allInNamespace = this.allPods.filter(pod => pod.metadata.namespace === this.value?.metadata?.namespace);
if (isEmpty(selector)) {
this.matchingPods = {
matched: 0,
total: allPods.length,
total: allInNamespace.length,
none: true,
sample: null,
};
} else {
const match = matching(allPods, selector);
const match = matching(allInNamespace, selector);
this.matchingPods = {
matched: match.length,
total: allPods.length,
total: allInNamespace.length,
none: match.length === 0,
sample: match[0] ? match[0].nameDisplay : null,
};