Skip to content

Commit

Permalink
cleanup: remove remaining references to assets/
Browse files Browse the repository at this point in the history
  • Loading branch information
chrboe committed May 5, 2020
1 parent 80c57bb commit 58da930
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 59 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ RUN apk update \
WORKDIR /go/src/virter
COPY . .

RUN make && mv ./virter / && mv ./assets /
RUN make && mv ./virter /

FROM alpine:latest

COPY --from=builder /virter /opt/virter/
COPY --from=builder /assets /opt/virter/assets

RUN apk update \
&& apk add rsync \
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ By default, virter uses the libvirt network named `default`.

## Usage

Virter uses some templates and an image registry file. It is simplest just to
run it from a checkout of this repository.

For usage just run `virter help`.

## Architecture
Expand Down
8 changes: 0 additions & 8 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ pool = "{{ get "libvirt.pool" }}"
# Default value: "{{ get "libvirt.network" }}"
network = "{{ get "libvirt.network" }}"
# template_dir is the directory where virters libvirt template files are stored.
# These are static and normally do not have to be touched by the user.
# Relative paths will be interpreted as relative to the current working directory
# when executing virter.
# Default value: "{{ get "libvirt.template_dir" }}"
template_dir = "{{ get "libvirt.template_dir" }}"
[time]
# ssh_ping_count is the number of times virter will try to connect to a VM's
# ssh port after starting it.
Expand Down Expand Up @@ -85,7 +78,6 @@ virter_private_key_path = "{{ get "auth.virter_private_key_path" }}"
func initConfig() {
viper.SetDefault("libvirt.pool", "default")
viper.SetDefault("libvirt.network", "default")
viper.SetDefault("libvirt.template_dir", "assets/libvirt-templates")
viper.SetDefault("time.ssh_ping_count", 60)
viper.SetDefault("time.ssh_ping_period", time.Second)
viper.SetDefault("time.shutdown_timeout", 20*time.Second)
Expand Down
5 changes: 1 addition & 4 deletions cmd/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import (
"github.com/spf13/viper"

"github.com/LINBIT/virter/internal/virter"
"github.com/LINBIT/virter/pkg/directory"
)

// VirterConnect connects to a local libvirt instance
func VirterConnect() (*virter.Virter, error) {
var templates directory.Directory = directory.Directory(viper.GetString("libvirt.template_dir"))

c, err := net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", 2*time.Second)
if err != nil {
return nil, fmt.Errorf("failed to dial libvirt: %w", err)
Expand All @@ -29,5 +26,5 @@ func VirterConnect() (*virter.Virter, error) {
pool := viper.GetString("libvirt.pool")
network := viper.GetString("libvirt.network")

return virter.New(l, pool, network, templates), nil
return virter.New(l, pool, network), nil
}
4 changes: 2 additions & 2 deletions internal/virter/cloudconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (v *Virter) metaData(vmName string) (string, error) {
"VMName": vmName,
}

return v.renderTemplate("meta-data", templateMetaData, templateData)
return renderTemplate("meta-data", templateMetaData, templateData)
}

func (v *Virter) userData(vmName string, sshPublicKeys []string) (string, error) {
Expand All @@ -36,7 +36,7 @@ func (v *Virter) userData(vmName string, sshPublicKeys []string) (string, error)
"SSHPublicKeys": sshPublicKeys,
}

return v.renderTemplate("user-data", templateUserData, templateData)
return renderTemplate("user-data", templateUserData, templateData)
}

func (v *Virter) createCIData(sp libvirt.StoragePool, g ISOGenerator, vmConfig VMConfig) error {
Expand Down
2 changes: 0 additions & 2 deletions internal/virter/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,3 @@ func (v *Virter) ImageBuild(ctx context.Context, tools ImageBuildTools, vmConfig

return nil
}

const templateVolumeImage = "volume-image.xml"
6 changes: 3 additions & 3 deletions internal/virter/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestImagePull(t *testing.T) {

l := newFakeLibvirtConnection()

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

err := v.ImagePull(client, nopReaderProxy{}, imageURL, imageName)
assert.NoError(t, err)
Expand All @@ -42,7 +42,7 @@ func TestImagePullBadStatus(t *testing.T) {

l := newFakeLibvirtConnection()

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

err := v.ImagePull(client, nopReaderProxy{}, imageURL, imageName)
assert.Error(t, err)
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestImageBuild(t *testing.T) {
l.vols[imageName] = &FakeLibvirtStorageVol{}
l.lifecycleEvents = makeShutdownEvents()

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

tools := virter.ImageBuildTools{
ISOGenerator: g,
Expand Down
12 changes: 2 additions & 10 deletions internal/virter/virter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (
libvirt "github.com/digitalocean/go-libvirt"
)

// FileReader is the interface for reading whole files.
type FileReader interface {
ReadFile(subpath string) ([]byte, error)
}

// LibvirtConnection contains required libvirt connection methods.
type LibvirtConnection interface {
StoragePoolLookupByName(Name string) (rPool libvirt.StoragePool, err error)
Expand Down Expand Up @@ -47,19 +42,16 @@ type Virter struct {
libvirt LibvirtConnection
storagePoolName string
networkName string
templates FileReader
}

// New configures a new Virter.
func New(libvirtConnection LibvirtConnection,
storagePoolName string,
networkName string,
fileReader FileReader) *Virter {
networkName string) *Virter {
return &Virter{
libvirt: libvirtConnection,
storagePoolName: storagePoolName,
networkName: networkName,
templates: fileReader,
}
}

Expand Down Expand Up @@ -122,7 +114,7 @@ type NetworkCopier interface {
Copy(host string, source []string, destination string) error
}

func (v *Virter) renderTemplate(name, content string, data interface{}) (string, error) {
func renderTemplate(name, content string, data interface{}) (string, error) {
t, err := template.New(name).Parse(content)
if err != nil {
return "", fmt.Errorf("invalid template %v: %w", name, err)
Expand Down
6 changes: 0 additions & 6 deletions internal/virter/virter_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package virter_test

import "github.com/LINBIT/virter/pkg/directory"

//go:generate mockery -name=ISOGenerator
//go:generate mockery -name=PortWaiter
//go:generate mockery -name=AfterNotifier
//go:generate mockery -name=NetworkCopier

func testDirectory() directory.Directory {
return directory.Directory("../../assets/libvirt-templates")
}

const poolName = "some-pool"
const networkName = "some-network"
const imageName = "some-image"
10 changes: 5 additions & 5 deletions internal/virter/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestVMRun(t *testing.T) {

l.vols[imageName] = &FakeLibvirtStorageVol{}

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

c := virter.VMConfig{
ImageName: imageName,
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestVMRm(t *testing.T) {
fakeNetworkAddHost(l.network, vmMAC, vmIP)
}

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

err := v.VMRm(vmName)
assert.NoError(t, err)
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestVMCommit(t *testing.T) {

}

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

err := v.VMCommit(an, vmName, r[commitShutdown], shutdownTimeout)
if expectOk {
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestVMExecDocker(t *testing.T) {
docker := new(mocks.DockerClient)
mockDockerRun(docker)

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

dockercfg := virter.DockerContainerConfig{ImageName: dockerImageName}
err := v.VMExecDocker(context.Background(), docker, []string{vmName}, dockercfg, []byte(sshPrivateKey))
Expand All @@ -285,7 +285,7 @@ func TestVMExecRsync(t *testing.T) {

fakeNetworkAddHost(l.network, vmMAC, vmIP)

v := virter.New(l, poolName, networkName, testDirectory())
v := virter.New(l, poolName, networkName)

dir, err := createFakeDirectory()
assert.NoError(t, err)
Expand Down
14 changes: 0 additions & 14 deletions pkg/directory/directory.go

This file was deleted.

0 comments on commit 58da930

Please sign in to comment.