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

Add Restart Button to StatefulSet Menu (#6868)

* add restart button to statefulsets

Signed-off-by: Dan Bryant <daniel.bryant@linux.com>

* use ShowCheckedErrorNotification

Signed-off-by: Dan Bryant <daniel.bryant@linux.com>

Signed-off-by: Dan Bryant <daniel.bryant@linux.com>
This commit is contained in:
Dan 2023-01-04 13:14:56 +00:00 committed by GitHub
parent 9522420f5b
commit b4d3a16470
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 119 additions and 0 deletions

View File

@ -3,6 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import moment from "moment";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api"; import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import { KubeApi } from "../kube-api"; import { KubeApi } from "../kube-api";
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object"; import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
@ -42,6 +44,25 @@ export class StatefulSetApi extends KubeApi<StatefulSet> {
}, },
}); });
} }
restart(params: { namespace: string; name: string }) {
return this.request.patch(this.getUrl(params), {
data: {
spec: {
template: {
metadata: {
annotations: { "kubectl.kubernetes.io/restartedAt" : moment.utc().format() },
},
},
},
},
},
{
headers: {
"content-type": "application/strategic-merge-patch+json",
},
});
}
} }
export interface StatefulSetSpec { export interface StatefulSetSpec {

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 type { KubeObjectMenuProps } from "../kube-object-menu";
import type { StatefulSet, StatefulSetApi } from "../../../common/k8s-api/endpoints";
import { MenuItem } from "../menu";
import { Icon } from "../icon";
import { withInjectables } from "@ogre-tools/injectable-react";
import statefulSetApiInjectable from "../../../common/k8s-api/endpoints/stateful-set.api.injectable";
import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable";
import openConfirmDialogInjectable from "../confirm-dialog/open.injectable";
import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable";
import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable";
export interface StatefulSetMenuProps extends KubeObjectMenuProps<StatefulSet> {}
interface Dependencies {
statefulsetApi: StatefulSetApi;
openConfirmDialog: OpenConfirmDialog;
showCheckedErrorNotification: ShowCheckedErrorNotification;
}
const NonInjectedStatefulSetMenu = ({
statefulsetApi,
object,
toolbar,
showCheckedErrorNotification,
openConfirmDialog,
}: Dependencies & StatefulSetMenuProps) => (
<>
<MenuItem
onClick={() => openConfirmDialog({
ok: async () =>
{
try {
await statefulsetApi.restart({
namespace: object.getNs(),
name: object.getName(),
});
} catch (err) {
showCheckedErrorNotification(err, "Unknown error occured while restarting statefulset");
}
},
labelOk: "Restart",
message: (
<p>
{"Are you sure you want to restart statefulset "}
<b>{object.getName()}</b>
?
</p>
),
})}
>
<Icon
material="autorenew"
tooltip="Restart"
interactive={toolbar}
/>
<span className="title">Restart</span>
</MenuItem>
</>
);
export const StatefulSetMenu = withInjectables<Dependencies, StatefulSetMenuProps>(NonInjectedStatefulSetMenu, {
getProps: (di, props) => ({
...props,
showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable),
statefulsetApi: di.inject(statefulSetApiInjectable),
openConfirmDialog: di.inject(openConfirmDialogInjectable),
}),
});

View File

@ -0,0 +1,25 @@
/**
* 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 type { KubeObjectMenuItemComponent } from "../kube-object-menu-item-injection-token";
import { kubeObjectMenuItemInjectionToken } from "../kube-object-menu-item-injection-token";
import { computed } from "mobx";
import { StatefulSetMenu } from "../../+workloads-statefulsets/statefulset-menu";
const statefulsetMenuInjectable = getInjectable({
id: "statefulset-menu-kube-object-menu",
instantiate: () => ({
kind: "StatefulSet",
apiVersions: ["apps/v1"],
Component: StatefulSetMenu as KubeObjectMenuItemComponent,
enabled: computed(() => true),
orderNumber: 30,
}),
injectionToken: kubeObjectMenuItemInjectionToken,
});
export default statefulsetMenuInjectable;