Merge pull request #7364 from richard-cox/hpa-target

Ensure HPA cannot be associated with workloads owned by others
This commit is contained in:
Richard Cox 2022-11-10 09:43:36 +00:00 committed by GitHub
commit 31d97ef460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View File

@ -156,7 +156,7 @@ export default {
workloadRows() {
const params = this.$route.params;
const { id } = params;
const rows = flatten(compact(this.allWorkloads)).filter(row => row.showAsWorkload);
const rows = flatten(compact(this.allWorkloads)).filter(row => !row.ownedByWorkload);
const namespacedRows = filter(rows, ({ metadata: { namespace } }) => namespace === id);
return namespacedRows;

View File

@ -70,7 +70,10 @@ export default {
Object.values(SCALABLE_WORKLOAD_TYPES)
.flatMap(type => this.$store.getters['cluster/all'](type))
.filter(
wl => wl.metadata.namespace === this.value.metadata.namespace
// Filter out anything that has an owner, which should probably be the one with the HPA
// For example ReplicaSets can be associated with a HPA (https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#replicaset-as-a-horizontal-pod-autoscaler-target)
// but wouldn't make sense if it's owned by a deployment
wl => wl.metadata.namespace === this.value.metadata.namespace && !wl.ownedByWorkload
)
);
},

View File

@ -85,7 +85,7 @@ export default {
}
for ( const row of typeRows ) {
if (!this.allTypes || row.showAsWorkload) {
if (!this.allTypes || !row.ownedByWorkload) {
out.push(row);
}
}

View File

@ -499,7 +499,7 @@ export default class Workload extends WorkloadService {
return ports;
}
get showAsWorkload() {
get ownedByWorkload() {
const types = Object.values(WORKLOAD_TYPES);
if (this.metadata?.ownerReferences) {
@ -507,12 +507,12 @@ export default class Workload extends WorkloadService {
const have = (`${ owner.apiVersion.replace(/\/.*/, '') }.${ owner.kind }`).toLowerCase();
if ( types.includes(have) ) {
return false;
return true;
}
}
}
return true;
return false;
}
get isFromNorman() {