Skip to content

Commit b3baa21

Browse files
Merge pull request 1Panel-dev#79 from eagle9527/master
Deployment 历史版本列表展示
2 parents 49729de + b7dbbe4 commit b3baa21

File tree

6 files changed

+156
-1
lines changed

6 files changed

+156
-1
lines changed

web/dashboard/src/api/replicasets.js

+8
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ export function listReplicaSets (cluster_name, search, keywords, pageNum, pageSi
2727
export function listNsReplicaSets (cluster_name, namespace) {
2828
return get(`${replicaSetNamespaceUrl(cluster_name, namespace)}`)
2929
}
30+
31+
const replicaWorkloadSetNamespaceUrl = (cluster_name, namespace, selector) => {
32+
return `/api/v1/proxy/${cluster_name}/k8s/apis/apps/v1/namespaces/${namespace}/replicasets?labelSelector=${selector}`
33+
}
34+
35+
export function listNsReplicaSetsWorkload (cluster_name, namespace, selector) {
36+
return get(`${replicaWorkloadSetNamespaceUrl(cluster_name, namespace, selector)}`)
37+
}

web/dashboard/src/business/workloads/deployments/detail/index.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
<ko-detail-pods :cluster="clusterName" :namespace="namespace" :selector="selectors" />
5252
</el-card>
5353
</el-row>
54+
<el-row style="margin-top:20px" class="row-box">
55+
<el-card class="el-card">
56+
<h3>History</h3>
57+
<Ko-detail-replicasets :cluster="clusterName" :namespace="namespace" :name="name" :selector="selectors" />
58+
</el-card>
59+
</el-row>
5460
</div>
5561
<div v-if="yamlShow">
5662
<yaml-editor :value="form" :read-only="true" />
@@ -73,10 +79,11 @@ import KoDetailIngress from "@/components/detail/detail-ingress"
7379
import KoDetailPause from "@/components/detail/detail-pause"
7480
import KoDetailUpdate from "@/components/detail/detail-update"
7581
import KoDetailImage from "@/components/detail/detail-image"
82+
import KoDetailReplicasets from "@/components/detail/detail-replicasets"
7683
7784
export default {
7885
name: "DeploymentDetail",
79-
components: { KoDetailPods, KoDetailBasic, KoDetailConditions, KoDetailService, KoDetailIngress, KoDetailPause, KoDetailUpdate, KoDetailImage, LayoutContent, YamlEditor },
86+
components: { KoDetailPods, KoDetailBasic, KoDetailConditions, KoDetailService, KoDetailIngress, KoDetailPause, KoDetailUpdate, KoDetailImage, LayoutContent, YamlEditor, KoDetailReplicasets},
8087
props: {
8188
name: String,
8289
namespace: String,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<template>
2+
<div>
3+
<complex-table :data="pods" v-loading="loading" @search="search">
4+
<el-table-column :label="$t('commons.table.version')" prop="name" min-width="80" show-overflow-tooltip>
5+
<template v-slot:default="{row}">
6+
<span>{{ row.metadata.annotations["deployment.kubernetes.io/revision"] }}</span>
7+
</template>
8+
</el-table-column>
9+
<el-table-column :label="$t('commons.table.image')" prop="image" min-width="80" show-overflow-tooltip>
10+
<template v-slot:default="{row}">
11+
<span v-for="(k, index) in row.spec.template.spec.containers" :key="index">
12+
<span class="label-custom wd" type="info">{{ k.image }}</span>
13+
</span>
14+
</template>
15+
</el-table-column>
16+
<el-table-column :label="$t('commons.table.time')" prop="time" min-width="80" show-overflow-tooltip>
17+
<template v-slot:default="{row}">
18+
<span>{{ row.metadata.creationTimestamp | age }}</span>
19+
</template>
20+
</el-table-column>
21+
<ko-table-operations :buttons="buttons" :label="$t('commons.table.action')"></ko-table-operations>
22+
</complex-table>
23+
</div>
24+
</template>
25+
26+
<script>
27+
import ComplexTable from "@/components/complex-table"
28+
import KoTableOperations from "@/components/ko-table-operations"
29+
import {checkPermissions} from "@/utils/permission"
30+
import {listNsReplicaSetsWorkload} from "@/api/replicasets"
31+
import { patchDeployment } from "@/api/deployments"
32+
33+
34+
export default {
35+
name: "KoDetailReplicasets",
36+
components: { ComplexTable, KoTableOperations },
37+
props: {
38+
cluster: String,
39+
namespace: String,
40+
selector: String,
41+
fieldSelector: String,
42+
name: String,
43+
},
44+
watch: {
45+
selector: {
46+
handler (newSelector) {
47+
if (newSelector) {
48+
this.search()
49+
}
50+
},
51+
immediate: true,
52+
},
53+
fieldSelector: {
54+
handler (newSelector) {
55+
if (newSelector) {
56+
this.search()
57+
}
58+
},
59+
immediate: true,
60+
},
61+
},
62+
data () {
63+
return {
64+
buttons: [
65+
{
66+
label: this.$t("commons.button.rollback"),
67+
icon: "el-icon-back",
68+
click: (row) => {
69+
this.OptionRollback(row)
70+
},
71+
disabled: () => {
72+
return !checkPermissions({ scope: "namespace", apiGroup: "", resource: "pods/log", verb: "*" })
73+
},
74+
},
75+
],
76+
loading: false,
77+
pods: [],
78+
podUsage: [],
79+
}
80+
},
81+
methods: {
82+
search (resetPage) {
83+
this.loading = true
84+
if (resetPage) {
85+
this.paginationConfig.currentPage = 1
86+
}
87+
if (!checkPermissions({ scope: "namespace", apiGroup: "", resource: "pods", verb: "list" })) {
88+
return
89+
}
90+
listNsReplicaSetsWorkload(this.cluster, this.namespace, this.selector, this.fieldSelector).then((res) => {
91+
this.loading = false
92+
res.items.sort((a, b) => b.metadata.annotations["deployment.kubernetes.io/revision"] - a.metadata.annotations["deployment.kubernetes.io/revision"])
93+
for (var i = 0; i < res.items.length; i++) {
94+
this.pods.push(res.items[i])
95+
}
96+
})
97+
98+
},
99+
OptionRollback (row) {
100+
this.$confirm(
101+
this.$t("commons.confirm_message.rollback"),
102+
this.$t("commons.message_box.prompt"), {
103+
confirmButtonText: this.$t("commons.button.confirm"),
104+
cancelButtonText: this.$t("commons.button.cancel"),
105+
type: "warning",
106+
}).then(() => {
107+
patchDeployment(this.cluster, row.metadata.namespace, this.name, {"spec": {"template": row.spec.template}})
108+
.then(() => {
109+
this.dialogModifyVersionVisible = false
110+
this.loading = true
111+
this.$message({
112+
type: "success",
113+
message: this.$t("commons.msg.operation_success"),
114+
})
115+
})
116+
.finally(() => {
117+
this.loading = false
118+
})
119+
})
120+
},
121+
},
122+
mounted() {
123+
this.clusterName = this.$route.query.cluster
124+
},
125+
}
126+
</script>
127+
128+
<style scoped>
129+
.btnSize {
130+
width: 28px;
131+
height: 28px;
132+
}
133+
</style>

web/dashboard/src/i18n/lang/en-US.js

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const message = {
5454
restart: "Restart",
5555
modifying_version: "Modifying version",
5656
sync: "Sync"
57+
rollback: "Roll Back"
5758
},
5859
table: {
5960
name: "Name",
@@ -67,6 +68,8 @@ const message = {
6768
type: "Type",
6869
resourceInformation: "Resource Information",
6970
empty_text: "There are no rows to show.",
71+
version: "Version",
72+
image: "Image",
7073
},
7174
status: {
7275
Running: "Running",

web/dashboard/src/i18n/lang/zh-CN.js

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const message = {
5555
restart: "重启",
5656
modifying_version: "修改镜像版本",
5757
sync: "同步"
58+
rollback: "回滚到该版本"
5859
},
5960
table: {
6061
name: "名称",
@@ -68,6 +69,8 @@ const message = {
6869
type: "类型",
6970
resourceInformation: "资源信息",
7071
empty_text: "没有内容显示",
72+
version: "版本",
73+
image: "镜像",
7174
},
7275
status: {
7376
Running: "运行中",

web/dashboard/src/plugins/request.js

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const del = (url, loading) => {
120120

121121
export const patch = (url, data, headers, loading) => {
122122
if (headers) {
123+
headers["Content-type"] = "application/merge-patch+json"
123124
return promise(request({url: url, headers: headers, method: "patch", data}), loading)
124125
}
125126
return promise(request({url: url, method: "patch", data}), loading)

0 commit comments

Comments
 (0)