mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix PodDistruptionBudgets not displaying on newer Kube versions (#6989)
* Add ability for KubeApi to filter server versions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update error message Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Check preferred version for PodDistruptionBudgets Signed-off-by: Sebastian Malton <sebastian@malton.name> * Limit which versions can be used Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make sure that details are show for all versions - Remove duplicate versioning checks since everything must go through the API anyway Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary logger as dep Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
9b001adb07
commit
591d9f30f3
@ -18,6 +18,14 @@ const podDisruptionBudgetApiInjectable = getInjectable({
|
|||||||
return new PodDisruptionBudgetApi({
|
return new PodDisruptionBudgetApi({
|
||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||||
|
}, {
|
||||||
|
checkPreferredVersion: true,
|
||||||
|
allowedUsableVersions: {
|
||||||
|
policy: [
|
||||||
|
"v1",
|
||||||
|
"v1beta1",
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -7,20 +7,45 @@ import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
|||||||
import { KubeObject } from "../kube-object";
|
import { KubeObject } from "../kube-object";
|
||||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||||
import { KubeApi } from "../kube-api";
|
import { KubeApi } from "../kube-api";
|
||||||
|
import type { Condition } from "./types/condition";
|
||||||
|
|
||||||
export interface PodDisruptionBudgetSpec {
|
export interface V1Beta1PodDisruptionBudgetSpec {
|
||||||
minAvailable: string;
|
minAvailable: string;
|
||||||
maxUnavailable: string;
|
maxUnavailable: string;
|
||||||
selector: LabelSelector;
|
selector: LabelSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PodDisruptionBudgetStatus {
|
export interface V1PodDisruptionBudgetSpec {
|
||||||
|
maxUnavailable?: string | number;
|
||||||
|
minAvailable?: string | number;
|
||||||
|
selector?: LabelSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PodDisruptionBudgetSpec =
|
||||||
|
| V1Beta1PodDisruptionBudgetSpec
|
||||||
|
| V1PodDisruptionBudgetSpec;
|
||||||
|
|
||||||
|
export interface V1Beta1PodDisruptionBudgetStatus {
|
||||||
currentHealthy: number;
|
currentHealthy: number;
|
||||||
desiredHealthy: number;
|
desiredHealthy: number;
|
||||||
disruptionsAllowed: number;
|
disruptionsAllowed: number;
|
||||||
expectedPods: number;
|
expectedPods: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface V1PodDisruptionBudgetStatus {
|
||||||
|
conditions?: Condition[];
|
||||||
|
currentHealthy: number;
|
||||||
|
desiredHealthy: number;
|
||||||
|
disruptedPods?: Partial<Record<string, string>>;
|
||||||
|
disruptionsAllowed: number;
|
||||||
|
expectedPods: number;
|
||||||
|
observedGeneration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PodDisruptionBudgetStatus =
|
||||||
|
| V1Beta1PodDisruptionBudgetStatus
|
||||||
|
| V1PodDisruptionBudgetStatus;
|
||||||
|
|
||||||
export class PodDisruptionBudget extends KubeObject<
|
export class PodDisruptionBudget extends KubeObject<
|
||||||
NamespaceScopedMetadata,
|
NamespaceScopedMetadata,
|
||||||
PodDisruptionBudgetStatus,
|
PodDisruptionBudgetStatus,
|
||||||
@ -31,7 +56,7 @@ export class PodDisruptionBudget extends KubeObject<
|
|||||||
static readonly apiBase = "/apis/policy/v1beta1/poddisruptionbudgets";
|
static readonly apiBase = "/apis/policy/v1beta1/poddisruptionbudgets";
|
||||||
|
|
||||||
getSelectors() {
|
getSelectors() {
|
||||||
return KubeObject.stringifyLabels(this.spec.selector.matchLabels);
|
return KubeObject.stringifyLabels(this.spec.selector?.matchLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMinAvailable() {
|
getMinAvailable() {
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface Condition {
|
||||||
|
lastTransitionTime: string;
|
||||||
|
message: string;
|
||||||
|
observedGeneration?: number;
|
||||||
|
reason: string;
|
||||||
|
status: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
@ -10,43 +10,25 @@ import { observer } from "mobx-react";
|
|||||||
import { DrawerItem } from "../drawer";
|
import { DrawerItem } from "../drawer";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
import { PodDisruptionBudget } from "../../../common/k8s-api/endpoints";
|
import type { PodDisruptionBudget } from "../../../common/k8s-api/endpoints";
|
||||||
import type { Logger } from "../../../common/logger";
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
|
||||||
import loggerInjectable from "../../../common/logger.injectable";
|
|
||||||
|
|
||||||
export interface PodDisruptionBudgetDetailsProps extends KubeObjectDetailsProps<PodDisruptionBudget> {
|
export interface PodDisruptionBudgetDetailsProps extends KubeObjectDetailsProps<PodDisruptionBudget> {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dependencies {
|
export const PodDisruptionBudgetDetails = observer((props: PodDisruptionBudgetDetailsProps) => {
|
||||||
logger: Logger;
|
const { object: pdb } = props;
|
||||||
}
|
|
||||||
|
|
||||||
@observer
|
|
||||||
class NonInjectedPodDisruptionBudgetDetails extends React.Component<PodDisruptionBudgetDetailsProps & Dependencies> {
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { object: pdb } = this.props;
|
|
||||||
|
|
||||||
if (!pdb) {
|
if (!pdb) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pdb instanceof PodDisruptionBudget)) {
|
|
||||||
this.props.logger.error("[PodDisruptionBudgetDetails]: passed object that is not an instanceof PodDisruptionBudget", pdb);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectors = pdb.getSelectors();
|
const selectors = pdb.getSelectors();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="PdbDetails">
|
<div className="PdbDetails">
|
||||||
{selectors.length > 0 && (
|
{selectors.length > 0 && (
|
||||||
<DrawerItem name="Selector" labelsOnly>
|
<DrawerItem name="Selector" labelsOnly>
|
||||||
{
|
{selectors.map(label => <Badge key={label} label={label}/>)}
|
||||||
selectors.map(label => <Badge key={label} label={label}/>)
|
|
||||||
}
|
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -68,12 +50,4 @@ class NonInjectedPodDisruptionBudgetDetails extends React.Component<PodDisruptio
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PodDisruptionBudgetDetails = withInjectables<Dependencies, PodDisruptionBudgetDetailsProps>(NonInjectedPodDisruptionBudgetDetails, {
|
|
||||||
getProps: (di, props) => ({
|
|
||||||
...props,
|
|
||||||
logger: di.inject(loggerInjectable),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { kubeObjectDetailItemInjectionToken } from "../kube-object-detail-item-injection-token";
|
import { kubeObjectDetailItemInjectionToken } from "../kube-object-detail-item-injection-token";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import { PodDisruptionBudgetDetails } from "../../../+config-pod-disruption-budgets";
|
import { PodDisruptionBudgetDetails } from "../../../+config-pod-disruption-budgets";
|
||||||
import { kubeObjectMatchesToKindAndApiVersion } from "../kube-object-matches-to-kind-and-api-version";
|
|
||||||
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
|
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
|
||||||
|
import { PodDisruptionBudget } from "../../../../../common/k8s-api/endpoints";
|
||||||
|
|
||||||
const podDisruptionBudgetDetailItemInjectable = getInjectable({
|
const podDisruptionBudgetDetailItemInjectable = getInjectable({
|
||||||
id: "pod-disruption-budget-detail-item",
|
id: "pod-disruption-budget-detail-item",
|
||||||
@ -17,7 +17,7 @@ const podDisruptionBudgetDetailItemInjectable = getInjectable({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
Component: PodDisruptionBudgetDetails,
|
Component: PodDisruptionBudgetDetails,
|
||||||
enabled: computed(() => isPodDisruptionBudget(kubeObject.value.get()?.object)),
|
enabled: computed(() => kubeObject.value.get()?.object instanceof PodDisruptionBudget),
|
||||||
orderNumber: 10,
|
orderNumber: 10,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -25,9 +25,4 @@ const podDisruptionBudgetDetailItemInjectable = getInjectable({
|
|||||||
injectionToken: kubeObjectDetailItemInjectionToken,
|
injectionToken: kubeObjectDetailItemInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isPodDisruptionBudget = kubeObjectMatchesToKindAndApiVersion(
|
|
||||||
"PodDisruptionBudget",
|
|
||||||
["policy/v1beta1"],
|
|
||||||
);
|
|
||||||
|
|
||||||
export default podDisruptionBudgetDetailItemInjectable;
|
export default podDisruptionBudgetDetailItemInjectable;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user