mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
fix(apps): update associated resources on deletion [r8s-124] (#75)
This commit is contained in:
parent
d418784346
commit
c1316532eb
15 changed files with 281 additions and 90 deletions
|
@ -1,5 +1,8 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { HorizontalPodAutoscalerList } from 'kubernetes-types/autoscaling/v1';
|
||||
import {
|
||||
HorizontalPodAutoscaler,
|
||||
HorizontalPodAutoscalerList,
|
||||
} from 'kubernetes-types/autoscaling/v1';
|
||||
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
@ -27,23 +30,15 @@ export function useApplicationHorizontalPodAutoscaler(
|
|||
if (!app) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const horizontalPodAutoscalers =
|
||||
await getNamespaceHorizontalPodAutoscalers(environmentId, namespace);
|
||||
const matchingHorizontalPodAutoscaler =
|
||||
horizontalPodAutoscalers.find((horizontalPodAutoscaler) => {
|
||||
const scaleTargetRef = horizontalPodAutoscaler.spec?.scaleTargetRef;
|
||||
if (scaleTargetRef) {
|
||||
const scaleTargetRefName = scaleTargetRef.name;
|
||||
const scaleTargetRefKind = scaleTargetRef.kind;
|
||||
// include the horizontal pod autoscaler if the scale target ref name and kind match the application name and kind
|
||||
return (
|
||||
scaleTargetRefName === app.metadata?.name &&
|
||||
scaleTargetRefKind === app.kind
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}) || null;
|
||||
getMatchingHorizontalPodAutoscaler(
|
||||
horizontalPodAutoscalers,
|
||||
namespace,
|
||||
appName,
|
||||
app.kind || ''
|
||||
);
|
||||
return matchingHorizontalPodAutoscaler;
|
||||
},
|
||||
{
|
||||
|
@ -57,6 +52,29 @@ export function useApplicationHorizontalPodAutoscaler(
|
|||
);
|
||||
}
|
||||
|
||||
export function getMatchingHorizontalPodAutoscaler(
|
||||
horizontalPodAutoscalers: HorizontalPodAutoscaler[],
|
||||
appNamespace: string,
|
||||
appName: string,
|
||||
appKind: string
|
||||
) {
|
||||
const matchingHorizontalPodAutoscaler =
|
||||
horizontalPodAutoscalers.find((horizontalPodAutoscaler) => {
|
||||
if (horizontalPodAutoscaler.metadata?.namespace !== appNamespace) {
|
||||
return false;
|
||||
}
|
||||
const scaleTargetRef = horizontalPodAutoscaler.spec?.scaleTargetRef;
|
||||
if (scaleTargetRef) {
|
||||
const scaleTargetRefName = scaleTargetRef.name;
|
||||
const scaleTargetRefKind = scaleTargetRef.kind;
|
||||
// include the horizontal pod autoscaler if the scale target ref name and kind match the application name and kind
|
||||
return scaleTargetRefName === appName && scaleTargetRefKind === appKind;
|
||||
}
|
||||
return false;
|
||||
}) || null;
|
||||
return matchingHorizontalPodAutoscaler;
|
||||
}
|
||||
|
||||
async function getNamespaceHorizontalPodAutoscalers(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue