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

Commit

Permalink
pkg/preflight: add check for bin dependencies and socket
Browse files Browse the repository at this point in the history
  • Loading branch information
najeal committed Aug 30, 2019
1 parent 3f742ce commit 6a28bcc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
49 changes: 26 additions & 23 deletions pkg/preflight/checks.go → pkg/preflight/checkers/checks.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package preflight
package checkers

import (
"bytes"
"fmt"
"log"
"net"
"os"
"path"
"path/filepath"
"os/exec"
"strings"

"k8s.io/apimachinery/pkg/util/sets"

api "github.com/weaveworks/ignite/pkg/apis/ignite"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/operations/lookup"
"github.com/weaveworks/ignite/pkg/providers"
)

Expand Down Expand Up @@ -57,6 +54,12 @@ type ExistingFileChecker struct {
filePath string
}

func NewExistingFileChecker(filePath string) ExistingFileChecker {
return ExistingFileChecker{
filePath: filePath,
}
}

func (efc ExistingFileChecker) Check() error {
if _, err := os.Stat(efc.filePath); os.IsNotExist(err) {
return fmt.Errorf("File %s, does not exist", efc.filePath)
Expand All @@ -72,42 +75,42 @@ func (efc ExistingFileChecker) Type() string {
return "ExistingFile"
}

type AvailablePathChecker struct {
path string
type BinInPathChecker struct {
bin string
}

func (apc AvailablePathChecker) Check() error {
if _, err := os.Stat(apc.path); !os.IsExist(err) {
return fmt.Errorf("Path %s, already exist", apc.path)
func (bipc BinInPathChecker) Check() error {
_, err := exec.LookPath(bipc.bin)
if err != nil {
return fmt.Errorf("Bin %s is not in your PATH", bipc.bin)
}
return nil
}

func (apc AvailablePathChecker) Name() string {
return fmt.Sprintf("AvailablePath-%s", strings.Replace(apc.path, oldPathString, newPathString, noReplaceLimit))
func (bipc BinInPathChecker) Name() string {
return ""
}

func (apc AvailablePathChecker) Type() string {
return "AvailablePath"
func (bipc BinInPathChecker) Type() string {
return ""
}

type AvailablePathChecker struct {
path string
}

func StartCmdChecks(vm *api.VM, ignoredPreflightErrors sets.String) error {
checks := []Checker{}
kernelUID, err := lookup.KernelUIDForVM(vm, providers.Client)
if err != nil {
return err
}
vmDir := filepath.Join(constants.VM_DIR, vm.GetUID().String())
kernelDir := filepath.Join(constants.KERNEL_DIR, kernelUID.String())
log.Println(vm.GetUID().String())
checks = append(checks, ExistingFileChecker{filePath: path.Join(vmDir, constants.METADATA)})
checks = append(checks, ExistingFileChecker{filePath: path.Join(kernelDir, constants.KERNEL_FILE)})
checks = append(checks, ExistingFileChecker{filePath: "/dev/mapper/control"})
checks = append(checks, ExistingFileChecker{filePath: "/dev/net/tun"})
checks = append(checks, ExistingFileChecker{filePath: "/dev/kvm"})
checks = append(checks, providers.Runtime.PreflightChecker())
for _, port := range vm.Spec.Network.Ports {
checks = append(checks, PortOpenChecker{port: port.HostPort})
}
for _, dependency := range constants.Dependencies {
checks = append(checks, BinInPathChecker{bin: dependency})
}
return runChecks(checks, ignoredPreflightErrors)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package preflight
package checkers

import (
"fmt"
Expand Down
7 changes: 7 additions & 0 deletions pkg/preflight/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package preflight

type Checker interface {
Check() error
Name() string
Type() string
}

0 comments on commit 6a28bcc

Please sign in to comment.