1
0
mirror of https://github.com/lensapp/lens.git synced 2024-09-11 09:25:26 +03:00

Restart deployment (#1175)

Signed-off-by: Pavel Ashevskii <pashevskii@mirantis.com>
This commit is contained in:
pashevskii 2020-11-05 11:23:14 +04:00 committed by GitHub
parent f9578ba407
commit d074e0499f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 7 deletions

View File

@ -549,6 +549,14 @@ msgstr "Condition"
msgid "Conditions"
msgstr "Conditions"
#: src/renderer/components/+workloads-deployments/deployments.tsx: 118
msgid "Restart"
msgstr "Restart"
#: src/renderer/components/+workloads-deployments/deployments.tsx: 121
msgid "Are you sure you want to restart deployment <0>{0}</0>?"
msgstr "Are you sure you want to restart deployment <0>{0}</0>?"
#: src/renderer/components/+config-maps/config-maps.tsx:33
msgid "Config Maps"
msgstr "Config Maps"

View File

@ -545,6 +545,14 @@ msgstr ""
msgid "Conditions"
msgstr ""
#: src/renderer/components/+workloads-deployments/deployments.tsx: 118
msgid "Restart"
msgstr ""
#: src/renderer/components/+workloads-deployments/deployments.tsx: 121
msgid "Are you sure you want to restart deployment <0>{0}</0>?"
msgstr ""
#: src/renderer/components/+config-maps/config-maps.tsx:33
msgid "Config Maps"
msgstr ""

View File

@ -550,6 +550,14 @@ msgstr "Состояние"
msgid "Conditions"
msgstr "Состояния"
#: src/renderer/components/+workloads-deployments/deployments.tsx: 118
msgid "Restart"
msgstr "Перезагрузка"
#: src/renderer/components/+workloads-deployments/deployments.tsx: 121
msgid "Are you sure you want to restart deployment <0>{0}</0>?"
msgstr "Выполнить перезагрузку деплоймента <0>{0}</0>?"
#: src/renderer/components/+config-maps/config-maps.tsx:33
msgid "Config Maps"
msgstr ""

View File

@ -1,3 +1,5 @@
import moment from "moment";
import { IAffinity, WorkloadKubeObject } from "../workload-kube-object";
import { autobind } from "../../utils";
import { KubeApi } from "../kube-api";
@ -23,6 +25,25 @@ export class DeploymentApi extends KubeApi<Deployment> {
}
})
}
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'
}
})
}
}
@autobind()
@ -38,6 +59,7 @@ export class Deployment extends WorkloadKubeObject {
metadata: {
creationTimestamp?: string;
labels: { [app: string]: string };
annotations?: { [app: string]: string };
};
spec: {
containers: {

View File

@ -64,7 +64,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
}
patch<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
return this.request<T>(path, params, { ...reqInit, method: "patch" });
return this.request<T>(path, params, { ...reqInit, method: "PATCH" });
}
del<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {

View File

@ -4,11 +4,12 @@ import React from "react";
import { observer } from "mobx-react";
import { RouteComponentProps } from "react-router";
import { t, Trans } from "@lingui/macro";
import { Deployment } from "../../api/endpoints";
import { Deployment, deploymentApi } from "../../api/endpoints";
import { KubeObjectMenuProps } from "../kube-object/kube-object-menu";
import { MenuItem } from "../menu";
import { Icon } from "../icon";
import { DeploymentScaleDialog } from "./deployment-scale-dialog";
import { ConfirmDialog } from "../confirm-dialog";
import { deploymentStore } from "./deployments.store";
import { replicaSetStore } from "../+workloads-replicasets/replicasets.store";
import { podsStore } from "../+workloads-pods/pods.store";
@ -22,6 +23,8 @@ import kebabCase from "lodash/kebabCase";
import orderBy from "lodash/orderBy";
import { KubeEventIcon } from "../+events/kube-event-icon";
import { kubeObjectMenuRegistry } from "../../../extensions/registries/kube-object-menu-registry";
import { apiManager } from "../../api/api-manager";
import { Notifications } from "../notifications";
enum sortBy {
name = "name",
@ -96,10 +99,34 @@ export class Deployments extends React.Component<Props> {
export function DeploymentMenu(props: KubeObjectMenuProps<Deployment>) {
const { object, toolbar } = props;
return (
<MenuItem onClick={() => DeploymentScaleDialog.open(object)}>
<Icon material="open_with" title={_i18n._(t`Scale`)} interactive={toolbar}/>
<span className="title"><Trans>Scale</Trans></span>
</MenuItem>
<>
<MenuItem onClick={() => DeploymentScaleDialog.open(object)}>
<Icon material="open_with" title={_i18n._(t`Scale`)} interactive={toolbar}/>
<span className="title"><Trans>Scale</Trans></span>
</MenuItem>
<MenuItem onClick={() => ConfirmDialog.open({
ok: async () =>
{
try {
await deploymentApi.restart({
namespace: object.getNs(),
name: object.getName(),
})
} catch (err) {
Notifications.error(err);
}
},
labelOk: _i18n._(t`Restart`),
message: (
<p>
<Trans>Are you sure you want to restart deployment <b>{object.getName()}</b>?</Trans>
</p>
),
})}>
<Icon material="autorenew" title={_i18n._(t`Restart`)} interactive={toolbar}/>
<span className="title"><Trans>Restart</Trans></span>
</MenuItem>
</>
)
}
@ -110,4 +137,3 @@ kubeObjectMenuRegistry.add({
MenuItem: DeploymentMenu
}
})