Skip to content

Commit

Permalink
Use consts for default values
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Oct 19, 2017
1 parent 1b5ebbb commit 9f62dd9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/virt-handler/virt-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import (
watchdog "kubevirt.io/kubevirt/pkg/watchdog"
)

const defaultWatchdogTimeout = 30 * time.Second

type virtHandlerApp struct {
Service *service.Service
HostOverride string
Expand Down Expand Up @@ -218,8 +220,6 @@ func (app *virtHandlerApp) Run() {
}

func main() {
defaultExpires := 30 * time.Second

logging.InitializeLogging("virt-handler")
libvirt.EventRegisterDefaultImpl()
libvirtUri := flag.String("libvirt-uri", "qemu:///system", "Libvirt connection string.")
Expand All @@ -228,7 +228,7 @@ func main() {
hostOverride := flag.String("hostname-override", "", "Kubernetes Pod to monitor for changes")
virtShareDir := flag.String("kubevirt-share-dir", "/var/run/kubevirt", "Shared directory between virt-handler and virt-launcher")
ephemeralDiskDir := flag.String("ephemeral-disk-dir", "/var/run/libvirt/kubevirt-ephemeral-disk", "Base directory for ephemeral disk data")
watchdogTimeoutDuration := flag.Duration("watchdog-timeout", defaultExpires, "Watchdog file timeout.")
watchdogTimeoutDuration := flag.Duration("watchdog-timeout", defaultWatchdogTimeout, "Watchdog file timeout.")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

Expand Down
10 changes: 5 additions & 5 deletions cmd/virt-launcher/virt-launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
watchdog "kubevirt.io/kubevirt/pkg/watchdog"
)

const defaultStartTimeout = 3 * time.Minute
const defaultWatchdogInterval = 10 * time.Second

func markReady(readinessFile string) {
f, err := os.OpenFile(readinessFile, os.O_RDONLY|os.O_CREATE, 0666)
if err != nil {
Expand Down Expand Up @@ -67,15 +70,12 @@ func createSocket(virtShareDir string, namespace string, name string) net.Listen
}

func main() {
startTimeout := 0 * time.Second
defaultInterval := 10 * time.Second

logging.InitializeLogging("virt-launcher")
qemuTimeout := flag.Duration("qemu-timeout", startTimeout, "Amount of time to wait for qemu")
qemuTimeout := flag.Duration("qemu-timeout", defaultStartTimeout, "Amount of time to wait for qemu")
virtShareDir := flag.String("kubevirt-share-dir", "/var/run/kubevirt", "Shared directory between virt-handler and virt-launcher")
name := flag.String("name", "", "Name of the VM")
namespace := flag.String("namespace", "", "Namespace of the VM")
watchdogInterval := flag.Duration("watchdog-update-interval", defaultInterval, "Interval at which watchdog file should be updated")
watchdogInterval := flag.Duration("watchdog-update-interval", defaultWatchdogInterval, "Interval at which watchdog file should be updated")
readinessFile := flag.String("readiness-file", "/tmp/health", "Pod looks for tihs file to determine when virt-launcher is initialized")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
Expand Down
3 changes: 2 additions & 1 deletion pkg/virt-handler/virtwrap/isolation/isolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func NewSocketBasedIsolationDetector(virtShareDir string) PodIsolationDetector {
}

func SocketFromNamespaceName(baseDir string, namespace string, name string) string {
return filepath.Clean(baseDir) + "/sockets/" + namespace + "_" + name + "_sock"
sockFile := namespace + "_" + name + "_sock"
return filepath.Join(baseDir, "sockets", sockFile)
}

// This function is only used by unit test suite
Expand Down
7 changes: 5 additions & 2 deletions pkg/watchdog/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ func NewWatchdogListWatchFromClient(virtShareDir string, watchdogTimeout int) ca
}

func WatchdogFileDirectory(baseDir string) string {
return filepath.Clean(baseDir) + "/watchdog-files"
return filepath.Join(baseDir, "watchdog-files")
}

func WatchdogFileFromNamespaceName(baseDir string, namespace string, name string) string {
return filepath.Clean(baseDir) + "/watchdog-files/" + namespace + "_" + name
watchdogFile := namespace + "_" + name
return filepath.Join(baseDir, "watchdog-files", watchdogFile)
}

func WatchdogFileRemove(baseDir string, vm *v1.VirtualMachine) error {
Expand Down Expand Up @@ -84,6 +85,8 @@ func WatchdogFileExists(baseDir string, vm *v1.VirtualMachine) (bool, error) {
filePath := WatchdogFileFromNamespaceName(baseDir, namespace, domain)
exists, err := diskutils.FileExists(filePath)
if err != nil {
logging.DefaultLogger().Error().Reason(err).Msgf("Error encountered while attempting to verify if watchdog file at path %s exists.", filePath)

return false, err
}
return exists, nil
Expand Down

0 comments on commit 9f62dd9

Please sign in to comment.