Skip to content

Commit

Permalink
Workspace bumped, image source and save changed, old versions retracted
Browse files Browse the repository at this point in the history
  • Loading branch information
rajch committed Jun 20, 2021
1 parent 5e16230 commit 8c263e6
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 21 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ kutti driver for Oracle VirtualBox
[![Go Report Card](https://goreportcard.com/badge/github.com/kuttiproject/driver-vbox)](https://goreportcard.com/report/github.com/kuttiproject/driver-vbox)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/kuttiproject/driver-vbox)](https://pkg.go.dev/github.com/kuttiproject/driver-vbox)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/kuttiproject/driver-vbox?include_prereleases)

## Images
This driver depends on VirtualBox VM images published via the [kuttiproject/driver-vbox-images](https://github.com/kuttiproject/driver-vbox-images) repository. The details of the driver-to-VM interface are documented there.

The releases of that repository are the default source for this driver. The mater list of available/deprecated images and the images themselves are published there. The releases match the major and minor versions of this repository, and vice versa.
14 changes: 14 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
// Package drivervbox implements a kutti driver for Oracle VirtualBox.
// It uses the VBoxManage tool to talk to VirtualBox.
//
// For cluster networking, it uses VirtualBox NAT networks. It allows
// port forwarding for host access to nodes.
// For nodes, it creates virtual machines by importing pre-packaged
// OVA files, maintained by the companion driver-vbox-images project.
// For images, it uses the aforesaid OVA files, downloading the list
// from the URL pointed to by the ImagesSourceURL variable.
//
// The details of individual operations can be found in the online
// documentation. Details about the interface between the driver and
// a running VM can be found at the driver-vbox-images project:
// https://github.com/kuttiproject/driver-vbox-images
package drivervbox
2 changes: 1 addition & 1 deletion driver-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (vd *Driver) K8sVersions() []string {
result := make([]string, len(imagedata.images))
index := 0
for _, value := range imagedata.images {
result[index] = value.ImageK8sVersion
result[index] = value.imageK8sVersion
index++
}

Expand Down
1 change: 1 addition & 0 deletions drivervbox-findvboxmanage_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package drivervbox

import (
"errors"
"os"
"os/exec"
"path"
Expand Down
12 changes: 6 additions & 6 deletions drivervbox-imagemanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/kuttiproject/workspace"
)

const imagesConfigFile = "vboximages.json"
const imagesConfigFile = "driver-vbox-images.json"

// ImagesSourceURL is the location where the master list of images can be found
var ImagesSourceURL = "https://github.com/rajch/kutti-images/releases/download/v0.1.13-beta/kutti-images.json"
var ImagesSourceURL = "https://github.com/kuttiproject/driver-vbox-images/releases/download/v0.2/driver-vbox-images.json"

var (
imagedata = &imageconfigdata{}
Expand Down Expand Up @@ -133,11 +133,11 @@ func fetchimagelist() error {
for key, newimage := range tempimagedata.images {
oldimage := imagedata.images[key]
if oldimage != nil &&
newimage.ImageChecksum == oldimage.ImageChecksum &&
newimage.ImageSourceURL == oldimage.ImageSourceURL &&
oldimage.ImageStatus == drivercore.ImageStatusDownloaded {
newimage.imageChecksum == oldimage.imageChecksum &&
newimage.imageSourceURL == oldimage.imageSourceURL &&
oldimage.imageStatus == drivercore.ImageStatusDownloaded {

newimage.ImageStatus = drivercore.ImageStatusDownloaded
newimage.imageStatus = drivercore.ImageStatusDownloaded
}
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ go 1.16
require (
github.com/kuttiproject/drivercore v0.1.2
github.com/kuttiproject/kuttilog v0.1.2
github.com/kuttiproject/workspace v0.2.1
github.com/kuttiproject/workspace v0.2.2
)

retract [v0.1.0, v0.1.2] // Image source changed to kuttiproject/[email protected]
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ github.com/kuttiproject/drivercore v0.1.2 h1:t/AKAh48130SgOGi2kNmuoi3KkaIpHZx+vL
github.com/kuttiproject/drivercore v0.1.2/go.mod h1:1C1TMGfQ4u/5ltHUtl4hL7gYzXZyZQVhkOha4GuOzk0=
github.com/kuttiproject/kuttilog v0.1.2 h1:VEqVWrR3M6RME6aoUuVwXNO3bRpHKNp0ISAP/vqncpg=
github.com/kuttiproject/kuttilog v0.1.2/go.mod h1:OO3dHpXm1/Pjlc57R4c0e/C+ZWkYlY3Fd9Ikn8xPXi4=
github.com/kuttiproject/workspace v0.2.1 h1:T7deidWcCWiNh800ZRnXih/gRO+RFDuiD0BydvvAlC0=
github.com/kuttiproject/workspace v0.2.1/go.mod h1:Z4wwYslirpVHP4TTqrEX3yh/sGdinHSWa3lcMdAVPt8=
github.com/kuttiproject/workspace v0.2.2 h1:1eNdMooB6Oq7jq2wodbuaY+IVZSYcEuXnqY3e00s64Y=
github.com/kuttiproject/workspace v0.2.2/go.mod h1:Z4wwYslirpVHP4TTqrEX3yh/sGdinHSWa3lcMdAVPt8=
65 changes: 54 additions & 11 deletions image.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
package drivervbox

import (
"encoding/json"
"fmt"
"path"

"github.com/kuttiproject/drivercore"
"github.com/kuttiproject/workspace"
)

// Image implements the drivercore.Image interface for VirtualBox.
type Image struct {
// vboximagedata is a data-only representation of the Cluster type,
// used for serialization and output.
type vboximagedata struct {
ImageK8sVersion string
ImageChecksum string
ImageSourceURL string
ImageStatus drivercore.ImageStatus
ImageDeprecated bool
}

// Image implements the drivercore.Image interface for VirtualBox.
type Image struct {
imageK8sVersion string
imageChecksum string
imageSourceURL string
imageStatus drivercore.ImageStatus
imageDeprecated bool
}

// K8sVersion returns the version of Kubernetes present in the image.
func (i *Image) K8sVersion() string {
return i.ImageK8sVersion
return i.imageK8sVersion
}

// Status returns the status of the image.
// Status can be Downloaded, meaning the image exists in the local cache and can
// be used to create Machines, or Notdownloaded, meaning it has to be downloaded
// using Fetch.
func (i *Image) Status() drivercore.ImageStatus {
return i.ImageStatus
return i.imageStatus
}

// Deprecated returns true if the image's version of Kubenetes is deprecated.
// New Macines should not be created from such an image.
func (i *Image) Deprecated() bool {
return i.ImageDeprecated
return i.imageDeprecated
}

// Fetch downloads the image from its source URL.
Expand All @@ -43,11 +54,11 @@ func (i *Image) Fetch() error {
return err
}

tempfilename := fmt.Sprintf("kutti-k8s-%s.ovadownload", i.ImageK8sVersion)
tempfilename := fmt.Sprintf("kutti-k8s-%s.ovadownload", i.imageK8sVersion)
tempfilepath := path.Join(cachedir, tempfilename)

// Download file
err = workspace.DownloadFile(i.ImageSourceURL, tempfilepath)
err = workspace.DownloadFile(i.imageSourceURL, tempfilepath)
if err != nil {
return err
}
Expand All @@ -59,21 +70,21 @@ func (i *Image) Fetch() error {

// FromFile verifies an image file on a local path and copies it to the cache.
func (i *Image) FromFile(filepath string) error {
err := addfromfile(i.ImageK8sVersion, filepath, i.ImageChecksum)
err := addfromfile(i.imageK8sVersion, filepath, i.imageChecksum)
if err != nil {
return err
}

i.ImageStatus = drivercore.ImageStatusDownloaded
i.imageStatus = drivercore.ImageStatusDownloaded
return imageconfigmanager.Save()
}

// PurgeLocal removes the local cached copy of an image.
func (i *Image) PurgeLocal() error {
if i.ImageStatus == drivercore.ImageStatusDownloaded {
if i.imageStatus == drivercore.ImageStatusDownloaded {
err := removefile(i.K8sVersion())
if err == nil {
i.ImageStatus = drivercore.ImageStatusNotDownloaded
i.imageStatus = drivercore.ImageStatusNotDownloaded

return imageconfigmanager.Save()
}
Expand All @@ -82,3 +93,35 @@ func (i *Image) PurgeLocal() error {

return nil
}

// MarshalJSON returns the JSON encoding of the cluster.
func (i *Image) MarshalJSON() ([]byte, error) {
savedata := vboximagedata{
ImageK8sVersion: i.imageK8sVersion,
ImageChecksum: i.imageChecksum,
ImageSourceURL: i.imageSourceURL,
ImageStatus: i.imageStatus,
ImageDeprecated: i.imageDeprecated,
}

return json.Marshal(savedata)
}

// UnmarshalJSON parses and restores a JSON-encoded
// cluster.
func (i *Image) UnmarshalJSON(b []byte) error {
var loaddata vboximagedata

err := json.Unmarshal(b, &loaddata)
if err != nil {
return err
}

i.imageK8sVersion = loaddata.ImageK8sVersion
i.imageChecksum = loaddata.ImageChecksum
i.imageSourceURL = loaddata.ImageSourceURL
i.imageStatus = loaddata.ImageStatus
i.imageDeprecated = loaddata.ImageDeprecated

return nil
}

0 comments on commit 8c263e6

Please sign in to comment.