Skip to content

Commit bb0c690

Browse files
authored
Merge pull request #9521 from mook-as/ui/containers/uptime
UI: Containers: Fix uptime
2 parents ed0faf5 + 2712cf2 commit bb0c690

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

pkg/rancher-desktop/pages/Containers.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134

135135
<script>
136136
import { BadgeState, Banner } from '@rancher/components';
137+
import dayjs from 'dayjs';
137138
import { shell } from 'electron';
138139
import merge from 'lodash/merge';
139140
import { defineComponent } from 'vue';
@@ -205,7 +206,7 @@ export default defineComponent({
205206
sort: ['ports', 'containerName', 'imageName'],
206207
},
207208
{
208-
name: 'started',
209+
name: 'uptime',
209210
label: this.t('containers.manage.table.header.started'),
210211
sort: ['si', 'containerName', 'imageName'],
211212
width: 120,
@@ -237,6 +238,7 @@ export default defineComponent({
237238
return a.state.localeCompare(b.state) || a.id.localeCompare(b.id);
238239
})
239240
.map(container => merge({}, container, {
241+
uptime: container.started && dayjs(container.started).toNow(true),
240242
availableActions: [
241243
{
242244
label: 'Info',

pkg/rancher-desktop/preload/extensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ export class RDXClient implements v1.DockerDesktopClient {
545545
...pick(details.State, ['Status', 'State'] as const),
546546
Names: typeof c.Names === 'string' ? c.Names.split(/\s+/g) : Array.from(c.Names),
547547
Created: Date.parse(c.CreatedAt).valueOf(),
548+
Started: Date.parse(details.State.StartedAt).valueOf(),
548549
};
549550
});
550551
},

pkg/rancher-desktop/store/container-engine.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ApiContainer {
1717
Id: string;
1818
Command: string;
1919
Created: number;
20+
Started: number;
2021
Image: string;
2122
ImageID: string;
2223
Status: string;
@@ -64,7 +65,7 @@ export interface Container {
6465
containerName: string;
6566
imageName: string;
6667
state: MobyContainer['State'] | NerdctlContainer['State'];
67-
uptime: string;
68+
started: Date | undefined;
6869
projectGroup: string;
6970
labels: Record<string, string>;
7071
ports: Record<string, { HostIp: string, HostPort: string }[] | null>;
@@ -326,16 +327,14 @@ export const actions = {
326327
containerName: container.Names[0].replace(/_[a-z0-9-]{36}_[0-9]+/, ''),
327328
imageName: container.Image,
328329
state,
329-
uptime: '',
330+
started: undefined,
330331
labels: container.Labels ?? {},
331332
ports: container.Ports,
332333
projectGroup,
333334
};
334335

335-
if (!isContainerd(container)) {
336-
if (container.State === 'running') {
337-
info.uptime = container.Status;
338-
}
336+
if (container.State === 'running' && container.Started) {
337+
info.started = new Date(container.Started);
339338
}
340339
containers[container.Id] = merge(containers[container.Id] ?? {}, info);
341340
ids.add(container.Id);

0 commit comments

Comments
 (0)