forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.vue
187 lines (161 loc) · 4.39 KB
/
node.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<script>
import ResourceTable from '@/components/ResourceTable';
import Loading from '@/components/Loading';
import Tag from '@/components/Tag';
import Banner from '@/components/Banner';
import {
STATE, NAME, ROLES, VERSION, INTERNAL_EXTERNAL_IP, CPU, RAM, PODS, AGE, KUBE_NODE_OS
} from '@/config/table-headers';
import metricPoller from '@/mixins/metric-poller';
import {
CAPI,
MANAGEMENT, METRIC, NODE, NORMAN, POD
} from '@/config/types';
import { allHash } from '@/utils/promise';
import { get } from '@/utils/object';
import { GROUP_RESOURCES, mapPref } from '@/store/prefs';
import { COLUMN_BREAKPOINTS } from '@/components/SortableTable/index.vue';
export default {
name: 'ListNode',
components: {
Loading,
ResourceTable,
Tag,
Banner
},
mixins: [metricPoller],
props: {
schema: {
type: Object,
required: true,
},
},
async fetch() {
const hash = { kubeNodes: this.$store.dispatch('cluster/findAll', { type: NODE }) };
this.canViewPods = this.$store.getters[`cluster/schemaFor`](POD);
if (this.$store.getters[`management/schemaFor`](MANAGEMENT.NODE)) {
// Required for Drain/Cordon action
hash.normanNodes = this.$store.dispatch('rancher/findAll', { type: NORMAN.NODE });
}
if (this.$store.getters[`rancher/schemaFor`](NORMAN.NODE)) {
hash.mgmtNodes = this.$store.dispatch('management/findAll', { type: MANAGEMENT.NODE });
}
if (this.$store.getters[`management/schemaFor`](CAPI.MACHINE)) {
// Required for ssh / download key actions
hash.machines = this.$store.dispatch('management/findAll', { type: CAPI.MACHINE });
}
if (this.canViewPods) {
// Used for running pods metrics
hash.pods = this.$store.dispatch('cluster/findAll', { type: POD });
}
const res = await allHash(hash);
this.kubeNodes = res.kubeNodes;
},
data() {
return {
kubeNodes: null,
canViewPods: false,
};
},
computed: {
hasWindowsNodes() {
return this.kubeNodes.some(node => node.status.nodeInfo.operatingSystem === 'windows');
},
tableGroup: mapPref(GROUP_RESOURCES),
headers() {
const headers = [
STATE,
NAME,
ROLES,
VERSION,
INTERNAL_EXTERNAL_IP,
{
...KUBE_NODE_OS,
breakpoint: COLUMN_BREAKPOINTS.LAPTOP
},
{
...CPU,
breakpoint: COLUMN_BREAKPOINTS.LAPTOP
}, {
...RAM,
breakpoint: COLUMN_BREAKPOINTS.LAPTOP
}];
if (this.canViewPods) {
headers.push({
...PODS,
breakpoint: COLUMN_BREAKPOINTS.DESKTOP
});
}
headers.push(AGE);
return headers;
},
},
methods: {
async loadMetrics() {
const schema = this.$store.getters['cluster/schemaFor'](METRIC.NODE);
if (schema) {
await this.$store.dispatch('cluster/findAll', {
type: METRIC.NODE,
opt: { force: true }
});
this.$forceUpdate();
}
},
get,
}
};
</script>
<template>
<Loading v-if="$fetchState.pending" />
<div v-else>
<Banner
v-if="hasWindowsNodes"
color="info"
:label="t('cluster.custom.registrationCommand.windowsWarning')"
/>
<ResourceTable
v-bind="$attrs"
:schema="schema"
:headers="headers"
:rows="kubeNodes"
:sub-rows="true"
v-on="$listeners"
>
<template #sub-row="{fullColspan, row}">
<tr class="taints sub-row" :class="{'empty-taints': !row.spec.taints || !row.spec.taints.length}">
<template v-if="row.spec.taints && row.spec.taints.length">
<td> </td>
<td> </td>
<td :colspan="fullColspan-2">
{{ t('node.list.nodeTaint') }}:
<Tag v-for="taint in row.spec.taints" :key="taint.key + taint.value + taint.effect" class="mr-5">
{{ taint.key }}={{ taint.value }}:{{ taint.effect }}
</Tag>
</td>
</template>
<td v-else :colspan="fullColspan">
</td>
</tr>
</template>
</ResourceTable>
</div>
</template>
<style lang='scss' scoped>
.taints {
td {
padding-top:0;
.tag {
margin-right: 5px
}
}
&.empty-taints {
// No taints... so hide sub-row (but not bottom-border)
height: 0;
line-height: 0;
td {
padding: 0;
}
}
}
</style>