Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart deployment #1175

Merged
merged 1 commit into from Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions locales/en/messages.po
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions locales/fi/messages.po
Expand Up @@ -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 ""
Expand Down
8 changes: 8 additions & 0 deletions locales/ru/messages.po
Expand Up @@ -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 ""
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/api/endpoints/deployment.api.ts
@@ -1,3 +1,5 @@
import moment from "moment";

import { IAffinity, WorkloadKubeObject } from "../workload-kube-object";
import { autobind } from "../../utils";
import { KubeApi } from "../kube-api";
Expand All @@ -23,6 +25,25 @@ export class DeploymentApi extends KubeApi<Deployment> {
}
})
}

restart(params: { namespace: string; name: string }) {
pashevskii marked this conversation as resolved.
Show resolved Hide resolved
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()
Expand All @@ -38,6 +59,7 @@ export class Deployment extends WorkloadKubeObject {
metadata: {
creationTimestamp?: string;
labels: { [app: string]: string };
annotations?: { [app: string]: string };
};
spec: {
containers: {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/json-api.ts
Expand Up @@ -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" });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

del<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
Expand Down
38 changes: 32 additions & 6 deletions src/renderer/components/+workloads-deployments/deployments.tsx
Expand Up @@ -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";
Expand All @@ -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",
Expand Down Expand Up @@ -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>
</>
)
}

Expand All @@ -110,4 +137,3 @@ kubeObjectMenuRegistry.add({
MenuItem: DeploymentMenu
}
})