Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #296 from twelho/start-time
Browse files Browse the repository at this point in the history
 Add `vm.status.startTime` to track the VM's uptime externally
  • Loading branch information
luxas committed Aug 8, 2019
2 parents 0b216e1 + aaf127f commit 28f3a40
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/ignite-spawn/ignite-spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func patchStopped(vm *api.VM) error {
patchVM.Status.Running = false
patchVM.Status.IPAddresses = nil
patchVM.Status.Runtime = nil
patchVM.Status.StartTime = nil
return nil
})
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/ignite/run/ps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package run

import (
"fmt"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/filter"
"github.com/weaveworks/ignite/pkg/providers"
Expand All @@ -26,12 +28,22 @@ func Ps(po *psOptions) error {
o := util.NewOutput()
defer o.Flush()

o.Write("VM ID", "IMAGE", "KERNEL", "CREATED", "SIZE", "CPUS", "MEMORY", "RUNNING", "IPS", "PORTS", "NAME")
o.Write("VM ID", "IMAGE", "KERNEL", "SIZE", "CPUS", "MEMORY", "CREATED", "STATUS", "IPS", "PORTS", "NAME")
for _, vm := range po.allVMs {
o.Write(vm.GetUID(), vm.Spec.Image.OCIClaim.Ref, vm.Spec.Kernel.OCIClaim.Ref, vm.GetCreated(),
vm.Spec.DiskSize, vm.Spec.CPUs, vm.Spec.Memory, vm.Running(), vm.Status.IPAddresses,
o.Write(vm.GetUID(), vm.Spec.Image.OCIClaim.Ref, vm.Spec.Kernel.OCIClaim.Ref,
vm.Spec.DiskSize, vm.Spec.CPUs, vm.Spec.Memory, vm.GetCreated(), formatStatus(vm), vm.Status.IPAddresses,
vm.Spec.Network.Ports, vm.GetName())
}

return nil
}

func formatStatus(vm *api.VM) (s string) {
if vm.Running() {
s = fmt.Sprintf("Up %s", vm.Status.StartTime)
} else {
s = "Stopped"
}

return
}
3 changes: 2 additions & 1 deletion docs/api/ignite_v1alpha2.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ type VMSpec struct {

VMSpec describes the configuration of a VM

## <a name="VMStatus">type</a> [VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9422:9702#L266)
## <a name="VMStatus">type</a> [VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/types.go?s=9422:9761#L266)

``` go
type VMStatus struct {
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *meta.Time `json:"startTime,omitempty"`
IPAddresses meta.IPAddresses `json:"ipAddresses,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/ignite/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ type Runtime struct {
type VMStatus struct {
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *meta.Time `json:"startTime,omitempty"`
IPAddresses meta.IPAddresses `json:"ipAddresses,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/ignite/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apis/ignite/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ type Runtime struct {
type VMStatus struct {
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *meta.Time `json:"startTime,omitempty"`
IPAddresses meta.IPAddresses `json:"ipAddresses,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/ignite/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/ignite/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/ignite/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/operations/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

log "github.com/sirupsen/logrus"
api "github.com/weaveworks/ignite/pkg/apis/ignite"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/dmlegacy"
"github.com/weaveworks/ignite/pkg/logs"
Expand Down Expand Up @@ -110,6 +111,10 @@ func StartVM(vm *api.VM, debug bool) error {
// Set the container ID for the VM
vm.Status.Runtime = &api.Runtime{ID: containerID}

// Set the start time for the VM
startTime := meta.Timestamp()
vm.Status.StartTime = &startTime

if vm.Spec.Network.Mode == api.NetworkModeCNI {
if err := providers.NetworkPlugin.SetupContainerNetwork(containerID); err != nil {
return err
Expand Down

0 comments on commit 28f3a40

Please sign in to comment.