mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
allow to mark as default IngressClass from menu item
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
0f1cb787e8
commit
3fc5a0a81d
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeApi, ResourceDescriptor } from "../kube-api";
|
||||
|
||||
export class IngressClassApi extends KubeApi<IngressClass> {
|
||||
constructor() {
|
||||
@ -15,6 +15,25 @@ export class IngressClassApi extends KubeApi<IngressClass> {
|
||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingressclasses"],
|
||||
});
|
||||
}
|
||||
|
||||
setAsDefault({ name }: ResourceDescriptor, isDefault: boolean = true) {
|
||||
const reqUrl = this.formatUrlForNotListing({ name });
|
||||
|
||||
return this.request.patch(reqUrl, {
|
||||
data: {
|
||||
metadata: {
|
||||
annotations: {
|
||||
[IngressClass.ANNOTATION_IS_DEFAULT]: JSON.stringify(isDefault),
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
"content-type": "application/strategic-merge-patch+json",
|
||||
// "content-type": "application/merge-patch+json",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// API docs: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#ingressclass-v1-networking-k8s-io
|
||||
@ -50,6 +69,7 @@ export class IngressClass extends KubeObject<IngressClassMetadata, IngressClassS
|
||||
static readonly kind = "IngressClass";
|
||||
static readonly namespaced = false;
|
||||
static readonly apiBase = "/apis/networking.k8s.io/v1/ingressclasses";
|
||||
static readonly ANNOTATION_IS_DEFAULT = "ingressclass.kubernetes.io/is-default-class";
|
||||
|
||||
getController(): string {
|
||||
return this.spec.controller;
|
||||
@ -76,6 +96,6 @@ export class IngressClass extends KubeObject<IngressClassMetadata, IngressClassS
|
||||
}
|
||||
|
||||
get isDefault() {
|
||||
return this.metadata.annotations?.["ingressclass.kubernetes.io/is-default-class"] === "true";
|
||||
return this.metadata.annotations?.[IngressClass.ANNOTATION_IS_DEFAULT] === "true";
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,10 +7,11 @@ import styles from "./ingress-class-details.module.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||
import type { IngressClass } from "../../../common/k8s-api/endpoints";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { Badge } from "../badge";
|
||||
|
||||
export interface IngressClassDetailsProps extends KubeObjectDetailsProps<IngressClass> {
|
||||
}
|
||||
@ -50,7 +51,7 @@ class NonInjectedIngressDetails extends React.Component<IngressClassDetailsProps
|
||||
return (
|
||||
<div className={styles.IngressClassDetails}>
|
||||
<DrawerItem name="Controller">
|
||||
{ingressClass.getController()}
|
||||
<Badge label={ingressClass.getController()} />
|
||||
</DrawerItem>
|
||||
{this.renderParameters()}
|
||||
</div>
|
||||
|
||||
@ -4,13 +4,25 @@
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import type { IngressClass } from "../../../common/k8s-api/endpoints/ingress-class.api";
|
||||
import ingressClassApiInjectable
|
||||
from "../../../common/k8s-api/endpoints/ingress-class.api.injectable";
|
||||
import ingressClassStoreInjectable from "./ingress-class-store.injectable";
|
||||
|
||||
export const ingressClassSetDefaultInjectable = getInjectable({
|
||||
id: "ingressClassSetDefaultInjectable",
|
||||
|
||||
instantiate() {
|
||||
return (item: IngressClass) => {
|
||||
console.log(`TODO: implement set-default ingress-class api call(s)`, item);
|
||||
instantiate(di) {
|
||||
return async (currentItem: IngressClass) => {
|
||||
const api = di.inject(ingressClassApiInjectable);
|
||||
const store = di.inject(ingressClassStoreInjectable);
|
||||
|
||||
const defaultIngressClassesUpdate = store.items
|
||||
.filter((item: IngressClass) => item.isDefault && currentItem !== item)
|
||||
.map(item => api.setAsDefault({ name: item.getName() }, false));
|
||||
|
||||
await Promise.all(defaultIngressClassesUpdate);
|
||||
await api.setAsDefault({ name: currentItem.getName() });
|
||||
await store.reloadAll({ force: true });
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user