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 #651 from darkowlzz/status-runtime-network
Browse files Browse the repository at this point in the history
  • Loading branch information
stealthybox authored Aug 10, 2020
2 parents 806f013 + 226c3fa commit 14e515f
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 108 deletions.
2 changes: 1 addition & 1 deletion cmd/ignite/run/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func CP(co *cpOptions) error {
return fmt.Errorf("VM %q is not running", co.vm.GetUID())
}

ipAddrs := co.vm.Status.IPAddresses
ipAddrs := co.vm.Status.Network.IPAddresses
if len(ipAddrs) == 0 {
return fmt.Errorf("VM %q has no usable IP addresses", co.vm.GetUID())
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/ignite/run/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInspect(t *testing.T) {

err = Inspect(iop)
if (err != nil) != rt.err {
t.Errorf("expected error %t, actual: %v", rt.err, err)
t.Fatalf("expected error %t, actual: %v", rt.err, err)
}

w.Close()
Expand All @@ -79,7 +79,7 @@ func TestInspect(t *testing.T) {
goldenFilePath := fmt.Sprintf("testdata%c%s", filepath.Separator, rt.golden)

// Update the golden file if needed.
if *update {
if !rt.err && *update {
t.Log("update inspect golden files")
if err := ioutil.WriteFile(goldenFilePath, buf.Bytes(), 0644); err != nil {
t.Fatalf("failed to update inspect golden file: %s: %v", goldenFilePath, err)
Expand All @@ -95,7 +95,7 @@ func TestInspect(t *testing.T) {
}

if !bytes.Equal(buf.Bytes(), wantOutput) {
t.Errorf("expected output to be:\n%v\ngot output:\n%v", wantOutput, buf.Bytes())
t.Errorf("expected output to be:\n%v\ngot output:\n%v", string(wantOutput), buf.String())
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Ps(po *psOptions) error {
o.Write("VM ID", "IMAGE", "KERNEL", "SIZE", "CPUS", "MEMORY", "CREATED", "STATUS", "IPS", "PORTS", "NAME")
for _, vm := range filteredVMs {
o.Write(vm.GetUID(), vm.Spec.Image.OCI, vm.Spec.Kernel.OCI,
vm.Spec.DiskSize, vm.Spec.CPUs, vm.Spec.Memory, formatCreated(vm), formatStatus(vm), vm.Status.IPAddresses,
vm.Spec.DiskSize, vm.Spec.CPUs, vm.Spec.Memory, formatCreated(vm), formatStatus(vm), vm.Status.Network.IPAddresses,
vm.Spec.Network.Ports, vm.GetName())
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/ignite/run/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func createTestVM(name, id string) (*api.VM, error) {
}
vm.Spec.Sandbox.OCI = ociRefSandbox

// Initialize network.
vm.Status.Network = &api.Network{}

return vm, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ignite/run/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func runSSH(vm *api.VM, privKeyFile string, command []string, tty bool, timeout
}

// Get the IP address.
ipAddrs := vm.Status.IPAddresses
ipAddrs := vm.Status.Network.IPAddresses
if len(ipAddrs) == 0 {
return fmt.Errorf("VM %q has no usable IP addresses", vm.GetUID())
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/ignite/run/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Start(so *startOptions) error {
}

// When --ssh is enabled, wait until SSH service started on port 22 at most N seconds
if ssh := so.vm.Spec.SSH; ssh != nil && ssh.Generate && len(so.vm.Status.IPAddresses) > 0 {
if ssh := so.vm.Spec.SSH; ssh != nil && ssh.Generate && len(so.vm.Status.Network.IPAddresses) > 0 {
if err := waitForSSH(so.vm, constants.SSH_DEFAULT_TIMEOUT_SECONDS, 5); err != nil {
return err
}
Expand All @@ -69,7 +69,7 @@ func Start(so *startOptions) error {
}

func dialSuccess(vm *ignite.VM, seconds int) error {
addr := vm.Status.IPAddresses[0].String() + ":22"
addr := vm.Status.Network.IPAddresses[0].String() + ":22"
perSecond := 10
delay := time.Second / time.Duration(perSecond)
var err error
Expand Down Expand Up @@ -119,7 +119,7 @@ func waitForSSH(vm *ignite.VM, dialSeconds, sshTimeout int) error {
Timeout: time.Duration(sshTimeout) * time.Second,
}

addr := vm.Status.IPAddresses[0].String() + ":22"
addr := vm.Status.Network.IPAddresses[0].String() + ":22"
sshConn, err := ssh.Dial("tcp", addr, config)
if err != nil {
if strings.Contains(err.Error(), "unable to authenticate") {
Expand Down
4 changes: 4 additions & 0 deletions cmd/ignite/run/testdata/output/inspect-json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
},
"status": {
"running": false,
"network": {
"plugin": "",
"ipAddresses": null
},
"image": {
"id": null,
"size": "0B"
Expand Down
3 changes: 3 additions & 0 deletions cmd/ignite/run/testdata/output/inspect-yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ status:
kernel:
id: null
size: 0B
network:
ipAddresses: null
plugin: ""
running: false
37 changes: 37 additions & 0 deletions docs/api/ignite_v1alpha2.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

- [Constants](#pkg-constants)
- [Variables](#pkg-variables)
- [func Convert\_ignite\_Runtime\_To\_v1alpha2\_Runtime(in
*ignite.Runtime, out *Runtime, s conversion.Scope)
error](#Convert_ignite_Runtime_To_v1alpha2_Runtime)
- [func Convert\_ignite\_VMStatus\_To\_v1alpha2\_VMStatus(in
*ignite.VMStatus, out *VMStatus, s conversion.Scope)
error](#Convert_ignite_VMStatus_To_v1alpha2_VMStatus)
- [func Convert\_v1alpha2\_VMStatus\_To\_ignite\_VMStatus(in
*VMStatus, out *ignite.VMStatus, s conversion.Scope)
error](#Convert_v1alpha2_VMStatus_To_ignite_VMStatus)
- [func SetDefaults\_PoolSpec(obj \*PoolSpec)](#SetDefaults_PoolSpec)
- [func SetDefaults\_VMKernelSpec(obj
\*VMKernelSpec)](#SetDefaults_VMKernelSpec)
Expand Down Expand Up @@ -54,6 +63,7 @@

#### <a name="pkg-files">Package files</a>

[conversion.go](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/conversion.go)
[defaults.go](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/defaults.go)
[doc.go](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/doc.go)
[json.go](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/json.go)
Expand Down Expand Up @@ -100,6 +110,33 @@ var SchemeGroupVersion = schema.GroupVersion{

SchemeGroupVersion is group version used to register these objects

## <a name="Convert_ignite_Runtime_To_v1alpha2_Runtime">func</a> [Convert\_ignite\_Runtime\_To\_v1alpha2\_Runtime](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/conversion.go?s=241:348#L9)

``` go
func Convert_ignite_Runtime_To_v1alpha2_Runtime(in *ignite.Runtime, out *Runtime, s conversion.Scope) error
```

Convert\_ignite\_Runtime\_To\_v1alpha2\_Runtime calls the autogenerated
conversion function along with custom conversion logic

## <a name="Convert_ignite_VMStatus_To_v1alpha2_VMStatus">func</a> [Convert\_ignite\_VMStatus\_To\_v1alpha2\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/conversion.go?s=1012:1123#L26)

``` go
func Convert_ignite_VMStatus_To_v1alpha2_VMStatus(in *ignite.VMStatus, out *VMStatus, s conversion.Scope) error
```

Convert\_ignite\_VMStatus\_To\_v1alpha2\_VMStatus calls the
autogenerated conversion function along with custom conversion logic

## <a name="Convert_v1alpha2_VMStatus_To_ignite_VMStatus">func</a> [Convert\_v1alpha2\_VMStatus\_To\_ignite\_VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/conversion.go?s=548:659#L14)

``` go
func Convert_v1alpha2_VMStatus_To_ignite_VMStatus(in *VMStatus, out *ignite.VMStatus, s conversion.Scope) error
```

Convert\_v1alpha2\_VMStatus\_To\_ignite\_VMStatus calls the
autogenerated conversion function along with custom conversion logic

## <a name="SetDefaults_PoolSpec">func</a> [SetDefaults\_PoolSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha2/defaults.go?s=308:348#L15)

``` go
Expand Down
35 changes: 24 additions & 11 deletions docs/api/ignite_v1alpha3.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [type Kernel](#Kernel)
- [type KernelSpec](#KernelSpec)
- [type KernelStatus](#KernelStatus)
- [type Network](#Network)
- [type OCIImageSource](#OCIImageSource)
- [type Pool](#Pool)
- [type PoolDevice](#PoolDevice)
Expand Down Expand Up @@ -144,7 +145,7 @@ type BlockDeviceVolume struct {

BlockDeviceVolume defines a block device on the host

## <a name="Configuration">type</a> [Configuration](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=9017:9160#L245)
## <a name="Configuration">type</a> [Configuration](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=9231:9374#L252)

``` go
type Configuration struct {
Expand All @@ -158,7 +159,7 @@ type Configuration struct {
Configuration represents the ignite runtime configuration.
+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

## <a name="ConfigurationSpec">type</a> [ConfigurationSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=9217:9460#L253)
## <a name="ConfigurationSpec">type</a> [ConfigurationSpec](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=9431:9674#L260)

``` go
type ConfigurationSpec struct {
Expand Down Expand Up @@ -261,6 +262,17 @@ type KernelStatus struct {

KernelStatus describes the status of a kernel

## <a name="Network">type</a> [Network](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=8608:8744#L235)

``` go
type Network struct {
Plugin igniteNetwork.PluginName `json:"plugin"`
IPAddresses meta.IPAddresses `json:"ipAddresses"`
}
```

Network specifies the VM’s network information.

## <a name="OCIImageSource">type</a> [OCIImageSource](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=1194:1426#L36)

``` go
Expand Down Expand Up @@ -355,11 +367,12 @@ type PoolStatus struct {

PoolStatus defines the Pool’s current status

## <a name="Runtime">type</a> [Runtime](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=8456:8502#L229)
## <a name="Runtime">type</a> [Runtime](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=8456:8555#L229)

``` go
type Runtime struct {
ID string `json:"id"`
ID string `json:"id"`
Name igniteRuntime.Name `json:"name"`
}
```

Expand Down Expand Up @@ -475,16 +488,16 @@ 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/v1alpha3/types.go?s=8543:8882#L234)
## <a name="VMStatus">type</a> [VMStatus](https://github.com/weaveworks/ignite/tree/master/pkg/apis/ignite/v1alpha3/types.go?s=8785:9096#L241)

``` go
type VMStatus struct {
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *runtime.Time `json:"startTime,omitempty"`
IPAddresses meta.IPAddresses `json:"ipAddresses,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *runtime.Time `json:"startTime,omitempty"`
Network *Network `json:"network,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
}
```

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ require (
golang.org/x/sys v0.0.0-20200610111108-226ff32320da
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.18.3
k8s.io/kube-openapi v0.0.0-20200615155156-dffdd1682719
k8s.io/kube-openapi v0.0.0-20200727223308-4c7aaf529f79
sigs.k8s.io/yaml v1.2.0
)
21 changes: 14 additions & 7 deletions pkg/apis/ignite/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,24 @@ type SSH struct {

// Runtime specifies the VM's runtime information
type Runtime struct {
ID string `json:"id"`
ID string `json:"id"`
Name igniteRuntime.Name `json:"name"`
}

// Network specifies the VM's network information.
type Network struct {
Plugin igniteNetwork.PluginName `json:"plugin"`
IPAddresses meta.IPAddresses `json:"ipAddresses"`
}

// VMStatus defines the status of a VM
type VMStatus struct {
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *runtime.Time `json:"startTime,omitempty"`
IPAddresses meta.IPAddresses `json:"ipAddresses,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
Running bool `json:"running"`
Runtime *Runtime `json:"runtime,omitempty"`
StartTime *runtime.Time `json:"startTime,omitempty"`
Network *Network `json:"network,omitempty"`
Image OCIImageSource `json:"image"`
Kernel OCIImageSource `json:"kernel"`
}

// Configuration represents the ignite runtime configuration.
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/ignite/v1alpha2/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package v1alpha2

import (
"github.com/weaveworks/ignite/pkg/apis/ignite"
"k8s.io/apimachinery/pkg/conversion"
)

// Convert_ignite_Runtime_To_v1alpha2_Runtime calls the autogenerated conversion function along with custom conversion logic
func Convert_ignite_Runtime_To_v1alpha2_Runtime(in *ignite.Runtime, out *Runtime, s conversion.Scope) error {
return autoConvert_ignite_Runtime_To_v1alpha2_Runtime(in, out, s)
}

// Convert_v1alpha2_VMStatus_To_ignite_VMStatus calls the autogenerated conversion function along with custom conversion logic
func Convert_v1alpha2_VMStatus_To_ignite_VMStatus(in *VMStatus, out *ignite.VMStatus, s conversion.Scope) error {
if err := autoConvert_v1alpha2_VMStatus_To_ignite_VMStatus(in, out, s); err != nil {
return err
}

// Set IPAddresses to the new position, under Network block.
out.Network.IPAddresses = in.IPAddresses

return nil
}

// Convert_ignite_VMStatus_To_v1alpha2_VMStatus calls the autogenerated conversion function along with custom conversion logic
func Convert_ignite_VMStatus_To_v1alpha2_VMStatus(in *ignite.VMStatus, out *VMStatus, s conversion.Scope) error {
if err := autoConvert_ignite_VMStatus_To_v1alpha2_VMStatus(in, out, s); err != nil {
return err
}

// Set IPAddresses to the status root.
out.IPAddresses = in.Network.IPAddresses

return nil
}
Loading

0 comments on commit 14e515f

Please sign in to comment.