From 162eb0aee2851030231f654d26be1e71375b402e Mon Sep 17 00:00:00 2001 From: Ojas M Date: Mon, 14 Jan 2019 17:37:58 -0800 Subject: [PATCH 1/2] Check if vip interface exists --- apis/validation.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apis/validation.go b/apis/validation.go index 4f41e55..7c08a30 100644 --- a/apis/validation.go +++ b/apis/validation.go @@ -2,6 +2,7 @@ package apis import ( "fmt" + "os/exec" "github.com/platform9/nodeadm/constants" ) @@ -23,7 +24,7 @@ func ValidateInit(config *InitConfiguration) []error { } else { // Pod subnet was set through MasterConfiguration.Networking.PodSubnet if config.MasterConfiguration.Networking.PodSubnet != config.Networking.PodSubnet { - errorList = append(errorList, fmt.Errorf("Configuration conflict: Networking.PodSubnet=%q, MasterConfiguration.Networking.PodSubnet=%q. Values should be identical, or MasterConfiguration.Networking.PodSubnet omitted.", + errorList = append(errorList, fmt.Errorf("configuration conflict: Networking.PodSubnet=%q, MasterConfiguration.Networking.PodSubnet=%q. Values should be identical, or MasterConfiguration.Networking.PodSubnet omitted", config.Networking.PodSubnet, config.MasterConfiguration.Networking.PodSubnet)) } } @@ -31,5 +32,12 @@ func ValidateInit(config *InitConfiguration) []error { errorList = append(errorList, fmt.Errorf("configuration conflict: Networking.DNSDomain=%q, MasterConfiguration.Networking.DNSDomain=%q. Values should be identical, or MasterConfiguration.Networking.DNSDomain omitted", config.Networking.DNSDomain, config.MasterConfiguration.Networking.DNSDomain)) } + if config.VIPConfiguration.RouterID != -1 { + iface := config.VIPConfiguration.NetworkInterface + err := exec.Command("ifconfig", "-a", iface).Run() + if err != nil { + errorList = append(errorList, fmt.Errorf("configuration conflict: VIPConfiguration.NetworkInterface=%q. Interface does not exist", iface)) + } + } return errorList } From e02717fa65afd558ce6b40690c8c8ed9660f474a Mon Sep 17 00:00:00 2001 From: Ojas M Date: Thu, 17 Jan 2019 15:37:34 -0800 Subject: [PATCH 2/2] Use package net to check interface --- apis/validation.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apis/validation.go b/apis/validation.go index 7c08a30..dc81b96 100644 --- a/apis/validation.go +++ b/apis/validation.go @@ -2,7 +2,7 @@ package apis import ( "fmt" - "os/exec" + "net" "github.com/platform9/nodeadm/constants" ) @@ -34,9 +34,9 @@ func ValidateInit(config *InitConfiguration) []error { } if config.VIPConfiguration.RouterID != -1 { iface := config.VIPConfiguration.NetworkInterface - err := exec.Command("ifconfig", "-a", iface).Run() + _, err := net.InterfaceByName(iface) if err != nil { - errorList = append(errorList, fmt.Errorf("configuration conflict: VIPConfiguration.NetworkInterface=%q. Interface does not exist", iface)) + errorList = append(errorList, fmt.Errorf("configuration conflict: VIPConfiguration.NetworkInterface=%q. %v", iface, err)) } } return errorList