Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.6] Bug 1932967: Allow baremetal-runtimecfg to function when the node isn't attached to the VIP network #123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions cmd/runtimecfg/node-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var nodeIPCmd = &cobra.Command{
var nodeIPShowCmd = &cobra.Command{
Use: "show [Virtual IP...]",
DisableFlagsInUseLine: true,
Short: "Show a configured IP address that directly routes to the given Virtual IPs. If no Virtual IPs are provided it will pick an IP associated with the default route.",
Short: "Show a configured IP address that directly routes to the given Virtual IPs. If no Virtual IPs are provided or if the node isn't attached to the VIP subnet, it will pick an IP associated with the default route.",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
err := show(cmd, args)
Expand All @@ -44,7 +44,7 @@ var nodeIPShowCmd = &cobra.Command{
var nodeIPSetCmd = &cobra.Command{
Use: "set [Virtual IP...]",
DisableFlagsInUseLine: true,
Short: "Sets container runtime services to bind to a configured IP address that directly routes to the given virtual IPs. If no Virtual IPs are provided it will pick an IP associated with the default route.",
Short: "Sets container runtime services to bind to a configured IP address that directly routes to the given virtual IPs. If no Virtual IPs are provided or if the node isn't attached to the VIP subnet, it will pick an IP associated with the default route.",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
err := set(cmd, args)
Expand Down Expand Up @@ -139,13 +139,16 @@ func getSuitableIP(retry bool, vips []net.IP) (chosen net.IP, err error) {

if len(vips) > 0 {
nodeAddrs, err = utils.AddressesRouting(vips, utils.ValidNodeAddress)
} else {
nodeAddrs, err = utils.AddressesDefault(utils.ValidNodeAddress)
if err != nil {
return nil, err
}
}
if err != nil {
return nil, err
if len(nodeAddrs) == 0 {
nodeAddrs, err = utils.AddressesDefault(utils.ValidNodeAddress)
if err != nil {
return nil, err
}
}

if len(nodeAddrs) > 0 {
chosen = nodeAddrs[0]
break
Expand Down
34 changes: 31 additions & 3 deletions pkg/config/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"net"
"strings"

"github.com/openshift/baremetal-runtimecfg/pkg/utils"
)

func GetInterfaceAndNonVIPAddr(vips []net.IP) (vipIface net.Interface, nonVipAddr *net.IPNet, err error) {
func getInterfaceAndNonVIPAddr(vips []net.IP) (vipIface net.Interface, nonVipAddr *net.IPNet, err error) {
if len(vips) < 1 {
return vipIface, nonVipAddr, fmt.Errorf("At least one VIP needs to be fed to this function")
}
Expand All @@ -22,6 +24,9 @@ func GetInterfaceAndNonVIPAddr(vips []net.IP) (vipIface net.Interface, nonVipAdd

for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return vipIface, nonVipAddr, err
}
for _, addr := range addrs {
switch n := addr.(type) {
case *net.IPNet:
Expand All @@ -34,13 +39,36 @@ func GetInterfaceAndNonVIPAddr(vips []net.IP) (vipIface net.Interface, nonVipAdd
_, nn, _ := net.ParseCIDR(strings.Replace(addr.String(), "/128", "/64", 1))

if nn.Contains(vips[0]) {
return iface, n, err
return iface, n, nil
}
default:
fmt.Println("not supported addr")
}
}
}

return vipIface, nonVipAddr, fmt.Errorf("No interface nor address found for the given VIPs")
nodeAddrs, err := utils.AddressesDefault(utils.ValidNodeAddress)
if err != nil {
return vipIface, nonVipAddr, err
}
if len(nodeAddrs) == 0 {
return vipIface, nonVipAddr, fmt.Errorf("No interface nor address found")
}
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return vipIface, nonVipAddr, err
}
for _, addr := range addrs {
switch n := addr.(type) {
case *net.IPNet:
if n.IP.String() == nodeAddrs[0].String() {
return iface, n, nil
}
default:
fmt.Println("not supported addr")
}
}
}
return vipIface, nonVipAddr, fmt.Errorf("No interface nor address found")
}
2 changes: 1 addition & 1 deletion pkg/config/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func GetVRRPConfig(apiVip, ingressVip, dnsVip net.IP) (vipIface net.Interface, n
if dnsVip != nil {
vips = append(vips, dnsVip)
}
return GetInterfaceAndNonVIPAddr(vips)
return getInterfaceAndNonVIPAddr(vips)
}

func IsUpgradeStillRunning(kubeconfigPath string) (error, bool) {
Expand Down