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:
Sebastian Malton authored and GitHub committed 2023-01-25 09:47:31 -05:00
1 parent 9b001adb07
commit 591d9f30f3
5 files changed
+84 -69

No files matched your search

@@ -18,6 +18,14 @@ const podDisruptionBudgetApiInjectable = getInjectable({
return new PodDisruptionBudgetApi({
logger: di.inject(loggerInjectable),
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 type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { Condition } from "./types/condition";
export interface PodDisruptionBudgetSpec {
export interface V1Beta1PodDisruptionBudgetSpec {
minAvailable: string;
maxUnavailable: string;
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;
desiredHealthy: number;
disruptionsAllowed: 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<
NamespaceScopedMetadata,
PodDisruptionBudgetStatus,
@@ -31,7 +56,7 @@ export class PodDisruptionBudget extends KubeObject<
static readonly apiBase = "/apis/policy/v1beta1/poddisruptionbudgets";
getSelectors() {
return KubeObject.stringifyLabels(this.spec.selector.matchLabels);
return KubeObject.stringifyLabels(this.spec.selector?.matchLabels);
}
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;
}