1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

New resource view: ValidatingWebhookConfigurations (#7552)

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-04-18 13:47:41 +03:00 committed by GitHub
parent e5eb709e66
commit 3baa42e17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 1200 additions and 152 deletions

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import validatingWebhookConfigurationsRouteInjectable from "./validating-webhook-configurations-route.injectable";
import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token";
const navigateToValidatingWebhookConfigurationsInjectable = getInjectable({
id: "navigate-to-validating-webhook-configurations",
instantiate: (di) => {
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const route = di.inject(validatingWebhookConfigurationsRouteInjectable);
return () => navigateToRoute(route);
},
});
export default navigateToValidatingWebhookConfigurationsInjectable;

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
import { getInjectable } from "@ogre-tools/injectable";
const validatingWebhookConfigurationsRouteInjectable = getInjectable({
id: "validatingwebhookconfigurations",
instantiate: (di) => ({
path: "/validatingwebhookconfigurations",
clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, {
apiName: "validatingwebhookconfigurations",
group: "admissionregistration.k8s.io",
}),
}),
injectionToken: frontEndRouteInjectionToken,
});
export default validatingWebhookConfigurationsRouteInjectable;

View File

@ -23,6 +23,7 @@ export * from "./job.api";
export * from "./lease.api";
export * from "./limit-range.api";
export * from "./mutating-webhook-configuration.api";
export * from "./validating-webhook-configuration.api";
export * from "./namespace.api";
export * from "./network-policy.api";
export * from "./node.api";

View File

@ -43,7 +43,7 @@ interface RuleWithOperations {
scope?: string;
}
interface MutatingWebhook {
export interface Webhook {
// The name of the webhook configuration.
name: string;
@ -94,6 +94,9 @@ interface MutatingWebhook {
reinvocationPolicy?: "Never" | "IfNeeded";
}
export interface MutatingWebhook extends Webhook {
}
interface ServiceReference {
// `namespace` is the namespace of the service.
namespace: string;

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import assert from "assert";
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
import loggerInjectable from "../../logger.injectable";
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
import { ValidatingWebhookConfigurationApi } from "./validating-webhook-configuration.api";
const validatingWebhookConfigurationApiInjectable = getInjectable({
id: "validating-webhook-configuration",
instantiate: (di) => {
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "validatingWebhookApi is only available in certain environments");
return new ValidatingWebhookConfigurationApi({
logger: di.inject(loggerInjectable),
maybeKubeApi: di.inject(maybeKubeApiInjectable),
});
},
injectionToken: kubeApiInjectionToken,
});
export default validatingWebhookConfigurationApiInjectable;

View File

@ -0,0 +1,47 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { NamespaceScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { Webhook } from "./mutating-webhook-configuration.api";
export interface ValidatingWebhook extends Webhook {
}
interface ValidatingWebhookConfigurationData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
webhooks?: ValidatingWebhook[];
}
export class ValidatingWebhookConfiguration extends KubeObject<
NamespaceScopedMetadata,
void,
void
> {
static kind = "ValidatingWebhookConfiguration";
static namespaced = false;
static apiBase = "/apis/admissionregistration.k8s.io/v1/validatingwebhookconfigurations";
webhooks?: ValidatingWebhook[];
constructor({ webhooks, ...rest }: ValidatingWebhookConfigurationData) {
super(rest);
this.webhooks = webhooks;
}
getWebhooks(): ValidatingWebhook[] {
return this.webhooks ?? [];
}
}
export class ValidatingWebhookConfigurationApi extends KubeApi<ValidatingWebhookConfiguration> {
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: ValidatingWebhookConfiguration,
});
}
}

View File

@ -9,7 +9,7 @@ export type KubeResource =
"pods" | "daemonsets" | "deployments" | "statefulsets" | "replicasets" | "replicationcontrollers" | "jobs" | "cronjobs" |
"endpoints" | "customresourcedefinitions" | "horizontalpodautoscalers" | "verticalpodautoscalers" | "podsecuritypolicies" | "poddisruptionbudgets" |
"priorityclasses" | "runtimeclasses" |
"roles" | "clusterroles" | "rolebindings" | "clusterrolebindings" | "serviceaccounts" | "mutatingwebhookconfigurations";
"roles" | "clusterroles" | "rolebindings" | "clusterrolebindings" | "serviceaccounts" | "mutatingwebhookconfigurations" | "validatingwebhookconfigurations";
export interface KubeApiResource {
kind: string;
@ -119,7 +119,12 @@ export const apiResourceRecord: Record<KubeResource, KubeApiResourceData> = {
mutatingwebhookconfigurations: {
kind: "MutatingWebhookConfiguration",
group: "admissionregistration.k8s.io/v1",
namespaced: true,
namespaced: false,
},
validatingwebhookconfigurations: {
kind: "ValidatingWebhookConfiguration",
group: "admissionregistration.k8s.io/v1",
namespaced: false,
},
networkpolicies: {
kind: "NetworkPolicy",

View File

@ -0,0 +1,232 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`MutatingWebhookConfigsDetails renders 1`] = `
<body>
<div>
<div
class="MutatingWebhookDetails"
>
<div
class="DrawerItem"
>
<span
class="name"
>
API version
</span>
<span
class="value"
>
admissionregistration.k8s.io/v1
</span>
</div>
<div
class="DrawerTitle title"
>
Webhooks
</div>
<div
class="DrawerItem firstItem"
>
<span
class="name"
>
Name
</span>
<span
class="value"
>
<strong>
pod-policy.example.com
</strong>
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Client Config
</span>
<span
class="value"
>
<div>
<div>
Name:
service-name
</div>
<div>
Namespace:
service-namespace
</div>
</div>
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Match Policy
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Failure Policy
</span>
<span
class="value"
>
Fail
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Admission Review Versions
</span>
<span
class="value"
>
v1, v1beta1
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Side Effects
</span>
<span
class="value"
>
None
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Timeout Seconds
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Namespace Selector
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Object Selector
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem lastItem"
>
<span
class="name"
>
Rules
</span>
<span
class="value"
>
<div>
<div>
API Groups:
, apps, extensions
</div>
<div>
API Versions:
v1, v1beta1
</div>
<div>
Operations:
CREATE, UPDATE
</div>
<div>
Resources:
pods, deployments
</div>
</div>
</span>
</div>
</div>
</div>
</body>
`;
exports[`MutatingWebhookConfigsDetails renders with no webhooks 1`] = `
<body>
<div>
<div
class="MutatingWebhookDetails"
>
<div
class="DrawerItem"
>
<span
class="name"
>
API version
</span>
<span
class="value"
>
admissionregistration.k8s.io/v1
</span>
</div>
<div
class="DrawerTitle title"
>
Webhooks
</div>
<div
style="opacity: 0.6;"
>
No webhooks set
</div>
</div>
</div>
</body>
`;

View File

@ -0,0 +1,82 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RenderResult } from "@testing-library/react";
import React from "react";
import {
MutatingWebhookConfiguration,
} from "../../../common/k8s-api/endpoints";
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import type { DiRender } from "../test-utils/renderFor";
import { renderFor } from "../test-utils/renderFor";
import { MutatingWebhookDetails } from "./mutating-webhook-configurations-details";
const mutatingWebhookConfig = {
apiVersion: "admissionregistration.k8s.io/v1",
kind: "MutatingWebhookConfiguration",
metadata: {
name: "pod-policy.example.com",
resourceVersion: "1",
uid: "pod-policy.example.com",
namespace: "default",
selfLink: "/apis/admissionregistration.k8s.io/v1/pod-policy.example.com",
},
webhooks: [
{
name: "pod-policy.example.com",
rules: [
{
apiGroups: ["", "apps", "extensions"],
apiVersions: ["v1", "v1beta1"],
operations: ["CREATE", "UPDATE"],
resources: ["pods", "deployments"],
},
],
failurePolicy: "Fail",
admissionReviewVersions: ["v1", "v1beta1"],
sideEffects: "None",
clientConfig: {
service: {
namespace: "service-namespace",
name: "service-name",
},
caBundle: "Cg==",
},
},
],
};
describe("MutatingWebhookConfigsDetails", () => {
let result: RenderResult;
let render: DiRender;
beforeEach(async () => {
const di = getDiForUnitTesting();
render = renderFor(di);
});
it("renders", () => {
const webhookConfig = new MutatingWebhookConfiguration(mutatingWebhookConfig);
result = render(
<MutatingWebhookDetails object={webhookConfig} />,
);
expect(result.baseElement).toMatchSnapshot();
});
it("renders with no webhooks", () => {
const webhookConfig = new MutatingWebhookConfiguration({
...mutatingWebhookConfig,
webhooks: [],
});
result = render(
<MutatingWebhookDetails object={webhookConfig} />,
);
expect(result.baseElement).toMatchSnapshot();
});
});

View File

@ -2,14 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import styles from "./mutating-webhook-configs-details.module.css";
import React from "react";
import { observer } from "mobx-react";
import { DrawerItem, DrawerTitle } from "../drawer";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import type { MutatingWebhookConfiguration } from "../../../common/k8s-api/endpoints";
import { Badge } from "../badge";
import { WebhookConfig } from "./webhook-config";
export interface MutatingWebhookDetailsProps extends KubeObjectDetailsProps<MutatingWebhookConfiguration> {
}
@ -29,152 +27,7 @@ export class MutatingWebhookDetails extends React.Component<MutatingWebhookDetai
<div style={{ opacity: 0.6 }}>No webhooks set</div>
)}
{webhookConfig.getWebhooks()?.map((webhook) => (
<React.Fragment key={webhook.name}>
<DrawerItem name="Name" className={styles.firstItem}>
<strong>{webhook.name}</strong>
</DrawerItem>
<DrawerItem name="Client Config">
{webhook.clientConfig?.service?.name && (
<div>
<div>
Name:
{" "}
{webhook.clientConfig.service.name}
</div>
<div>
Namespace:
{" "}
{webhook.clientConfig.service.namespace}
</div>
</div>
)}
</DrawerItem>
<DrawerItem name="Match Policy">
{webhook.matchPolicy}
</DrawerItem>
<DrawerItem name="Failure Policy">
{webhook.failurePolicy}
</DrawerItem>
<DrawerItem name="Admission Review Versions">
{webhook.admissionReviewVersions?.join(", ")}
</DrawerItem>
<DrawerItem name="Reinvocation Policy">
{webhook.reinvocationPolicy}
</DrawerItem>
<DrawerItem name="Side Effects">
{webhook.sideEffects}
</DrawerItem>
<DrawerItem name="Timeout Seconds">
{webhook.timeoutSeconds}
</DrawerItem>
<DrawerItem name="Namespace Selector">
{webhook.namespaceSelector && (
<div>
<div>Match Expressions:</div>
{webhook.namespaceSelector.matchExpressions?.map((expression, index) => (
<div key={index}>
<div>
Key:
{" "}
{expression.key}
</div>
<div>
Operator:
{" "}
{expression.operator}
</div>
<div>
Values:
{" "}
{expression.values?.join(", ")}
</div>
</div>
))}
{webhook.namespaceSelector.matchLabels && (
<div>
<div>Match Labels:</div>
<div className={styles.matchLabels}>
{Object.entries(webhook.namespaceSelector.matchLabels).map(([key, value], index) => (
<Badge label={`${key}=${value}`} key={index} />
))}
</div>
</div>
)}
</div>
)}
</DrawerItem>
<DrawerItem name="Object Selector">
{webhook.objectSelector && (
<div>
<div>Match Expressions:</div>
{webhook.objectSelector.matchExpressions?.map((expression, index) => (
<div key={index}>
<div>
Key:
{" "}
{expression.key}
</div>
<div>
Operator:
{" "}
{expression.operator}
</div>
<div>
Values:
{" "}
{expression.values?.join(", ")}
</div>
</div>
))}
{webhook.objectSelector.matchLabels && (
<div>
<div>Match Labels:</div>
<div className={styles.matchLabels}>
{Object.entries(webhook.objectSelector.matchLabels).map(([key, value], index) => (
<Badge label={`${key}=${value}`} key={index} />
))}
</div>
</div>
)}
</div>
)}
</DrawerItem>
<DrawerItem name="Rules" className={styles.lastItem}>
{webhook.rules?.map((rule, index) => (
<div key={index}>
<div>
API Groups:
{" "}
{rule.apiGroups.join(", ")}
</div>
<div>
API Versions:
{" "}
{rule.apiVersions?.join(", ")}
</div>
<div>
Operations:
{" "}
{rule.operations.join(", ")}
</div>
{rule.resources && (
<div>
Resources:
{" "}
{rule.resources.join(", ")}
</div>
)}
{rule.scope && (
<div>
Scope:
{" "}
{rule.scope}
</div>
)}
</div>
))}
</DrawerItem>
</React.Fragment>
<WebhookConfig webhook={webhook} key={webhook.name} />
))}
</div >
);

View File

@ -0,0 +1,166 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import React from "react";
import styles from "./webhook-config.module.css";
import type { MutatingWebhook, ValidatingWebhook } from "../../../common/k8s-api/endpoints";
import { DrawerItem } from "../drawer";
import { Badge } from "../badge";
interface WebhookProps {
webhook: ValidatingWebhook | MutatingWebhook;
}
export const WebhookConfig: React.FC<WebhookProps> = ({ webhook }) => {
return (
<>
<DrawerItem name="Name" className={styles.firstItem}>
<strong>{webhook.name}</strong>
</DrawerItem>
<DrawerItem name="Client Config">
{webhook.clientConfig?.service?.name && (
<div>
<div>
Name:
{" "}
{webhook.clientConfig.service.name}
</div>
<div>
Namespace:
{" "}
{webhook.clientConfig.service.namespace}
</div>
</div>
)}
</DrawerItem>
<DrawerItem name="Match Policy">
{webhook.matchPolicy}
</DrawerItem>
<DrawerItem name="Failure Policy">
{webhook.failurePolicy}
</DrawerItem>
<DrawerItem name="Admission Review Versions">
{webhook.admissionReviewVersions?.join(", ")}
</DrawerItem>
{ webhook.reinvocationPolicy && (
<DrawerItem name="Reinvocation Policy">
{webhook.reinvocationPolicy}
</DrawerItem>
)}
<DrawerItem name="Side Effects">
{webhook.sideEffects}
</DrawerItem>
<DrawerItem name="Timeout Seconds">
{webhook.timeoutSeconds}
</DrawerItem>
<DrawerItem name="Namespace Selector">
{webhook.namespaceSelector && (
<div>
<div>Match Expressions:</div>
{webhook.namespaceSelector.matchExpressions?.map((expression, index) => (
<div key={index}>
<div>
Key:
{" "}
{expression.key}
</div>
<div>
Operator:
{" "}
{expression.operator}
</div>
<div>
Values:
{" "}
{expression.values?.join(", ")}
</div>
</div>
))}
{webhook.namespaceSelector.matchLabels && (
<div>
<div>Match Labels:</div>
<div className={styles.matchLabels}>
{Object.entries(webhook.namespaceSelector.matchLabels).map(([key, value], index) => (
<Badge label={`${key}=${value}`} key={index} />
))}
</div>
</div>
)}
</div>
)}
</DrawerItem>
<DrawerItem name="Object Selector">
{webhook.objectSelector && (
<div>
<div>Match Expressions:</div>
{webhook.objectSelector.matchExpressions?.map((expression, index) => (
<div key={index}>
<div>
Key:
{" "}
{expression.key}
</div>
<div>
Operator:
{" "}
{expression.operator}
</div>
<div>
Values:
{" "}
{expression.values?.join(", ")}
</div>
</div>
))}
{webhook.objectSelector.matchLabels && (
<div>
<div>Match Labels:</div>
<div className={styles.matchLabels}>
{Object.entries(webhook.objectSelector.matchLabels).map(([key, value], index) => (
<Badge label={`${key}=${value}`} key={index} />
))}
</div>
</div>
)}
</div>
)}
</DrawerItem>
<DrawerItem name="Rules" className={styles.lastItem}>
{webhook.rules?.map((rule, index) => (
<div key={index}>
<div>
API Groups:
{" "}
{rule.apiGroups.join(", ")}
</div>
<div>
API Versions:
{" "}
{rule.apiVersions?.join(", ")}
</div>
<div>
Operations:
{" "}
{rule.operations.join(", ")}
</div>
{rule.resources && (
<div>
Resources:
{" "}
{rule.resources.join(", ")}
</div>
)}
{rule.scope && (
<div>
Scope:
{" "}
{rule.scope}
</div>
)}
</div>
))}
</DrawerItem>
</>
);
};

View File

@ -0,0 +1,234 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ValidatingWebhookConfigsDetails renders 1`] = `
<body>
<div>
<div
class="ValidatingWebhookDetails"
>
<div
class="DrawerItem"
>
<span
class="name"
>
API version
</span>
<span
class="value"
>
admissionregistration.k8s.io/v1
</span>
</div>
<div
class="DrawerTitle title"
>
Webhooks
</div>
<div
class="DrawerItem firstItem"
>
<span
class="name"
>
Name
</span>
<span
class="value"
>
<strong>
pod-policy.example.com
</strong>
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Client Config
</span>
<span
class="value"
>
<div>
<div>
Name:
service-name
</div>
<div>
Namespace:
service-namespace
</div>
</div>
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Match Policy
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Failure Policy
</span>
<span
class="value"
>
Fail
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Admission Review Versions
</span>
<span
class="value"
>
v1, v1beta1
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Side Effects
</span>
<span
class="value"
>
None
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Timeout Seconds
</span>
<span
class="value"
>
5
</span>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Namespace Selector
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem"
>
<span
class="name"
>
Object Selector
</span>
<span
class="value"
/>
</div>
<div
class="DrawerItem lastItem"
>
<span
class="name"
>
Rules
</span>
<span
class="value"
>
<div>
<div>
API Groups:
, apps, extensions
</div>
<div>
API Versions:
v1, v1beta1
</div>
<div>
Operations:
CREATE, UPDATE
</div>
<div>
Resources:
pods, deployments
</div>
</div>
</span>
</div>
</div>
</div>
</body>
`;
exports[`ValidatingWebhookConfigsDetails renders with no webhooks 1`] = `
<body>
<div>
<div
class="ValidatingWebhookDetails"
>
<div
class="DrawerItem"
>
<span
class="name"
>
API version
</span>
<span
class="value"
>
admissionregistration.k8s.io/v1
</span>
</div>
<div
class="DrawerTitle title"
>
Webhooks
</div>
<div
style="opacity: 0.6;"
>
No webhooks set
</div>
</div>
</div>
</body>
`;

View File

@ -0,0 +1,83 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RenderResult } from "@testing-library/react";
import React from "react";
import {
ValidatingWebhookConfiguration,
} from "../../../common/k8s-api/endpoints";
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import type { DiRender } from "../test-utils/renderFor";
import { renderFor } from "../test-utils/renderFor";
import { ValidatingWebhookDetails } from "./validating-webhook-configurations-details";
const validatingWebhookConfig = {
apiVersion: "admissionregistration.k8s.io/v1",
kind: "ValidatingWebhookConfiguration",
metadata: {
name: "pod-policy.example.com",
resourceVersion: "1",
uid: "pod-policy.example.com",
namespace: "default",
selfLink: "/apis/admissionregistration.k8s.io/v1/pod-policy.example.com",
},
webhooks: [
{
name: "pod-policy.example.com",
rules: [
{
apiGroups: ["", "apps", "extensions"],
apiVersions: ["v1", "v1beta1"],
operations: ["CREATE", "UPDATE"],
resources: ["pods", "deployments"],
},
],
failurePolicy: "Fail",
admissionReviewVersions: ["v1", "v1beta1"],
sideEffects: "None",
timeoutSeconds: 5,
clientConfig: {
service: {
namespace: "service-namespace",
name: "service-name",
},
caBundle: "Cg==",
},
},
],
};
describe("ValidatingWebhookConfigsDetails", () => {
let result: RenderResult;
let render: DiRender;
beforeEach(async () => {
const di = getDiForUnitTesting();
render = renderFor(di);
});
it("renders", () => {
const webhookConfig = new ValidatingWebhookConfiguration(validatingWebhookConfig);
result = render(
<ValidatingWebhookDetails object={webhookConfig} />,
);
expect(result.baseElement).toMatchSnapshot();
});
it("renders with no webhooks", () => {
const webhookConfig = new ValidatingWebhookConfiguration({
...validatingWebhookConfig,
webhooks: [],
});
result = render(
<ValidatingWebhookDetails object={webhookConfig} />,
);
expect(result.baseElement).toMatchSnapshot();
});
});

View File

@ -0,0 +1,6 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export * from "./validating-webhook-configurations";
export * from "./validating-webhook-configurations-details";

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { kubeObjectStoreInjectionToken } from "../../../common/k8s-api/api-manager/kube-object-store-token";
import { ValidatingWebhookConfigurationStore } from "./validating-webhook-configuration-store";
import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable";
import loggerInjectable from "../../../common/logger.injectable";
import validatingWebhookConfigurationApiInjectable
from "../../../common/k8s-api/endpoints/validating-webhook-configuration-api.injectable";
const validatingWebhookConfigurationStoreInjectable = getInjectable({
id: "validating-webhook-configuration-store",
instantiate: (di) => {
const api = di.inject(validatingWebhookConfigurationApiInjectable);
return new ValidatingWebhookConfigurationStore({
context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
logger: di.inject(loggerInjectable),
}, api);
},
injectionToken: kubeObjectStoreInjectionToken,
});
export default validatingWebhookConfigurationStoreInjectable;

View File

@ -0,0 +1,22 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type {
ValidatingWebhookConfiguration,
ValidatingWebhookConfigurationApi,
} from "../../../common/k8s-api/endpoints";
import type {
KubeObjectStoreDependencies,
KubeObjectStoreOptions,
} from "../../../common/k8s-api/kube-object.store";
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
export interface ValidatingWebhookConfigurationStoreDependencies extends KubeObjectStoreDependencies {
}
export class ValidatingWebhookConfigurationStore extends KubeObjectStore<ValidatingWebhookConfiguration, ValidatingWebhookConfigurationApi> {
constructor(protected readonly dependencies: ValidatingWebhookConfigurationStoreDependencies, api: ValidatingWebhookConfigurationApi, opts?: KubeObjectStoreOptions) {
super(dependencies, api, opts);
}
}

View File

@ -0,0 +1,35 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import React from "react";
import { observer } from "mobx-react";
import { DrawerItem, DrawerTitle } from "../drawer";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { WebhookConfig } from "../+config-mutating-webhook-configurations/webhook-config";
import type { ValidatingWebhookConfiguration } from "../../../common/k8s-api/endpoints";
export interface ValidatingWebhookProps extends KubeObjectDetailsProps<ValidatingWebhookConfiguration> {
}
@observer
export class ValidatingWebhookDetails extends React.Component<ValidatingWebhookProps> {
render() {
const { object: webhookConfig } = this.props;
return (
<div className="ValidatingWebhookDetails">
<DrawerItem name="API version">
{webhookConfig.apiVersion}
</DrawerItem>
<DrawerTitle>Webhooks</DrawerTitle>
{webhookConfig.getWebhooks()?.length == 0 && (
<div style={{ opacity: 0.6 }}>No webhooks set</div>
)}
{webhookConfig.getWebhooks()?.map((webhook) => (
<WebhookConfig webhook={webhook} key={webhook.name} />
))}
</div >
);
}
}

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import {
routeSpecificComponentInjectionToken,
} from "../../routes/route-specific-component-injection-token";
import validatingWebhookConfigurationsRouteInjectable
from "../../../common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable";
import { ValidatingWebhookConfigurations } from "./validating-webhook-configurations";
const validatingWebhookConfigurationsRouteComponentInjectable = getInjectable({
id: "validating-webhook-configuration-route-component",
instantiate: (di) => ({
route: di.inject(validatingWebhookConfigurationsRouteInjectable),
Component: ValidatingWebhookConfigurations,
}),
injectionToken: routeSpecificComponentInjectionToken,
});
export default validatingWebhookConfigurationsRouteComponentInjectable;

View File

@ -0,0 +1,39 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import { sidebarItemsInjectionToken } from "../layout/sidebar-items.injectable";
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
import validatingWebhookConfigurationsRouteInjectable
from "../../../common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable";
import navigateToValidatingWebhookConfigurationsInjectable
from "../../../common/front-end-routing/routes/cluster/config/validating-webhook-configurations/navigate-to-validating-webhook-configurations.injectable";
import { configSidebarItemId } from "../+config/config-sidebar-items.injectable";
const validatingWebhookConfigurationsSidebarItemsInjectable = getInjectable({
id: "validating-webhook-configurations-sidebar-items",
instantiate: (di) => {
const route = di.inject(validatingWebhookConfigurationsRouteInjectable);
const navigateToPage = di.inject(navigateToValidatingWebhookConfigurationsInjectable);
const routeIsActive = di.inject(routeIsActiveInjectable, route);
return computed(() => [
{
id: "validating-webhook-configurations",
parentId: configSidebarItemId,
title: "Validating Webhook Configs",
onClick: navigateToPage,
isActive: routeIsActive,
isVisible: route.isEnabled,
orderNumber: 100,
},
]);
},
injectionToken: sidebarItemsInjectionToken,
});
export default validatingWebhookConfigurationsSidebarItemsInjectable;

View File

@ -0,0 +1,73 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import React from "react";
import { observer } from "mobx-react";
import { KubeObjectListLayout } from "../kube-object-list-layout";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import type { ValidatingWebhookConfigurationStore } from "./validating-webhook-configuration-store";
import { withInjectables } from "@ogre-tools/injectable-react";
import validatingWebhookConfigurationsStoreInjectable from "./validating-webhook-configuration-store.injectable";
import { KubeObjectAge } from "../kube-object/age";
enum columnId {
name = "name",
webhooks = "webhooks",
age = "age",
}
interface Dependencies {
store: ValidatingWebhookConfigurationStore;
}
const NonInjectedValidatingWebhookConfigurations = observer((props: Dependencies) => {
return (
<SiblingsInTabLayout>
<KubeObjectListLayout
isConfigurable
customizeHeader={({ searchProps, ...rest }) => ({
...rest,
searchProps: {
...searchProps,
placeholder: "Search...",
},
})}
tableId="config_validating_webhook_configurations"
className={"ValidatingWebhookConfigurations"}
store={props.store}
sortingCallbacks={{
[columnId.name]: item => item.getName(),
[columnId.webhooks]: item => item.getWebhooks().length,
[columnId.age]: item => -item.getCreationTimestamp(),
}}
searchFilters={[
item => item.getSearchFields(),
item => item.getLabels(),
]}
renderHeaderTitle="Validating Webhook Configs"
renderTableHeader={[
{ title: "Name", className: "name", sortBy: columnId.name, id: columnId.name },
{
title: "Webhooks",
sortBy: columnId.webhooks,
id: columnId.webhooks,
},
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
]}
renderTableContents={item => [
item.getName(),
item.getWebhooks().length,
<KubeObjectAge key="age" object={item} />,
]}
/>
</SiblingsInTabLayout>
);
});
export const ValidatingWebhookConfigurations = withInjectables<Dependencies>(NonInjectedValidatingWebhookConfigurations, {
getProps: (di, props) => ({
...props,
store: di.inject(validatingWebhookConfigurationsStoreInjectable),
}),
});

View File

@ -0,0 +1,33 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { kubeObjectDetailItemInjectionToken } from "../kube-object-detail-item-injection-token";
import { computed } from "mobx";
import { kubeObjectMatchesToKindAndApiVersion } from "../kube-object-matches-to-kind-and-api-version";
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
import { ValidatingWebhookDetails } from "../../../+config-validating-webhook-configurations";
const validatingWebhookConfigurationDetailItemInjectable = getInjectable({
id: "validating-webhook-configuration-detail-item",
instantiate(di) {
const kubeObject = di.inject(currentKubeObjectInDetailsInjectable);
return {
Component: ValidatingWebhookDetails,
enabled: computed(() => isValidatingWebhookConfiguration(kubeObject.value.get()?.object)),
orderNumber: 10,
};
},
injectionToken: kubeObjectDetailItemInjectionToken,
});
export const isValidatingWebhookConfiguration = kubeObjectMatchesToKindAndApiVersion(
"ValidatingWebhookConfiguration",
["v1", "admissionregistration.k8s.io/v1beta1", "admissionregistration.k8s.io/v1"],
);
export default validatingWebhookConfigurationDetailItemInjectable;

View File

@ -45,6 +45,7 @@ export const ResourceNames: Record<KubeResource, string> = {
"serviceaccounts": "Service Accounts",
"verticalpodautoscalers": "Vertical Pod Autoscalers",
"mutatingwebhookconfigurations": "Mutating Webhook Configurations",
"validatingwebhookconfigurations": "Validating Webhook Configurations",
};
export const ResourceKindMap = object.fromEntries(

View File

@ -366,6 +366,18 @@ const scenarios = [
parentSidebarItemTestId: null,
sidebarItemTestId: "sidebar-item-link-for-custom-resources",
},
{
expectedSelector: "h5.title",
parentSidebarItemTestId: "sidebar-item-link-for-config",
sidebarItemTestId: "sidebar-item-link-for-validating-webhook-configurations",
},
{
expectedSelector: "h5.title",
parentSidebarItemTestId: "sidebar-item-link-for-config",
sidebarItemTestId: "sidebar-item-link-for-mutating-webhook-configurations",
},
];
const navigateToPods = async (frame: Frame) => {