-
Notifications
You must be signed in to change notification settings - Fork 1.5k
WIP: Configure Metal3 from the installer #2449
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,32 +6,54 @@ import ( | |
|
|
||
| "github.com/openshift/installer/pkg/types" | ||
| "github.com/openshift/installer/pkg/types/baremetal" | ||
|
|
||
| "github.com/apparentlymart/go-cidr/cidr" | ||
| ) | ||
|
|
||
| // Defaults for the baremetal platform. | ||
| const ( | ||
| LibvirtURI = "qemu:///system" | ||
| BootstrapProvisioningIP = "172.22.0.2" | ||
| ClusterProvisioningIP = "172.22.0.3" | ||
| ExternalBridge = "baremetal" | ||
| ProvisioningBridge = "provisioning" | ||
| HardwareProfile = "default" | ||
| APIVIP = "" | ||
| IngressVIP = "" | ||
| ProvisioningInterface = "ens3" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should there be an interface name default? |
||
| ProvisioningNetworkCIDR = "172.22.0.0/24" | ||
| CachedImageURL = "http://192.168.111.1/images" | ||
|
||
| ) | ||
|
|
||
| // Wrapper for net.LookupHost so we can override in the test | ||
| var lookupHost = func(host string) (addrs []string, err error) { | ||
| return net.LookupHost(host) | ||
| } | ||
|
|
||
| // SetPlatformDefaults sets the defaults for the platform. | ||
| func SetPlatformDefaults(p *baremetal.Platform, c *types.InstallConfig) { | ||
| if p.LibvirtURI == "" { | ||
| p.LibvirtURI = LibvirtURI | ||
| } | ||
|
|
||
| if p.ProvisioningNetworkCIDR == "" { | ||
| p.ProvisioningNetworkCIDR = ProvisioningNetworkCIDR | ||
| } | ||
|
|
||
| _, provNet, _ := net.ParseCIDR(p.ProvisioningNetworkCIDR) | ||
|
|
||
| if p.BootstrapProvisioningIP == "" { | ||
| p.BootstrapProvisioningIP = BootstrapProvisioningIP | ||
| // Default to .2 address for CIDR e.g 172.22.0.2 | ||
| ip, err := cidr.Host(provNet, 2) | ||
| if err == nil { | ||
| p.BootstrapProvisioningIP = ip.String() | ||
| } | ||
| } | ||
|
|
||
| if p.ClusterProvisioningIP == "" { | ||
| p.ClusterProvisioningIP = ClusterProvisioningIP | ||
| // Default to .3 address for CIDR e.g 172.22.0.3 | ||
| ip, err := cidr.Host(provNet, 3) | ||
| if err == nil { | ||
| p.ClusterProvisioningIP = ip.String() | ||
| } | ||
| } | ||
|
|
||
| if p.ExternalBridge == "" { | ||
|
|
@@ -50,7 +72,7 @@ func SetPlatformDefaults(p *baremetal.Platform, c *types.InstallConfig) { | |
|
|
||
| if p.APIVIP == APIVIP { | ||
| // This name should resolve to exactly one address | ||
| vip, err := net.LookupHost("api." + c.ClusterDomain()) | ||
| vip, err := lookupHost("api." + c.ClusterDomain()) | ||
| if err != nil { | ||
| // This will fail validation and abort the install | ||
| p.APIVIP = fmt.Sprintf("DNS lookup failure: %s", err.Error()) | ||
|
|
@@ -61,12 +83,36 @@ func SetPlatformDefaults(p *baremetal.Platform, c *types.InstallConfig) { | |
|
|
||
| if p.IngressVIP == IngressVIP { | ||
| // This name should resolve to exactly one address | ||
| vip, err := net.LookupHost("test.apps." + c.ClusterDomain()) | ||
| vip, err := lookupHost("test.apps." + c.ClusterDomain()) | ||
| if err != nil { | ||
| // This will fail validation and abort the install | ||
| p.IngressVIP = fmt.Sprintf("DNS lookup failure: %s", err.Error()) | ||
| } else { | ||
| p.IngressVIP = vip[0] | ||
| } | ||
| } | ||
|
|
||
| if p.ProvisioningInterface == "" { | ||
| p.ProvisioningInterface = ProvisioningInterface | ||
| } | ||
|
|
||
| if p.ProvisioningDHCPStart == "" { | ||
| // Default to .20 address for CIDR e.g 172.22.0.20 | ||
| ip, err := cidr.Host(provNet, 20) | ||
| if err == nil { | ||
| p.ProvisioningDHCPStart = ip.String() | ||
| } | ||
| } | ||
|
|
||
| if p.ProvisioningDHCPEnd == "" { | ||
| // Default to .200 address for CIDR e.g 172.22.0.200 | ||
| ip, err := cidr.Host(provNet, 200) | ||
| if err == nil { | ||
| p.ProvisioningDHCPEnd = ip.String() | ||
| } | ||
| } | ||
|
|
||
| if p.CachedImageURL == "" { | ||
| p.CachedImageURL = CachedImageURL | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package defaults | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "github.com/openshift/installer/pkg/types" | ||
| "github.com/openshift/installer/pkg/types/baremetal" | ||
| ) | ||
|
|
||
| const testClusterName = "test-cluster" | ||
|
|
||
| func TestSetPlatformDefaults(t *testing.T) { | ||
| // Stub the call to net.LookupHost | ||
| lookupHost = func (host string) (addrs []string, err error) { | ||
| if host == "api.test-cluster.test" { | ||
| ips := []string{"192.168.111.2",} | ||
| return ips, nil | ||
| } else if host == "test.apps.test-cluster.test" { | ||
| ips := []string{"192.168.111.3",} | ||
| return ips, nil | ||
| } else { | ||
| return nil, errors.New("Unknown Host " + host) | ||
| } | ||
| } | ||
| cases := []struct { | ||
| name string | ||
| platform *baremetal.Platform | ||
| expected *baremetal.Platform | ||
| }{ | ||
| { | ||
| name: "default_empty", | ||
| platform: &baremetal.Platform{}, | ||
| expected: &baremetal.Platform{ | ||
| LibvirtURI: "qemu:///system", | ||
| ClusterProvisioningIP: "172.22.0.3", | ||
| BootstrapProvisioningIP: "172.22.0.2", | ||
| ExternalBridge: "baremetal", | ||
| ProvisioningBridge: "provisioning", | ||
| APIVIP: "192.168.111.2", | ||
| IngressVIP: "192.168.111.3", | ||
| ProvisioningInterface: "ens3", | ||
| ProvisioningNetworkCIDR: "172.22.0.0/24", | ||
| ProvisioningDHCPStart: "172.22.0.20", | ||
| ProvisioningDHCPEnd: "172.22.0.200", | ||
| CachedImageURL: "http://192.168.111.1/images", | ||
| }, | ||
| }, | ||
| { | ||
| name: "alternate_cidr", | ||
| platform: &baremetal.Platform{ | ||
| ProvisioningNetworkCIDR: "172.23.0.0/24", | ||
| }, | ||
| expected: &baremetal.Platform{ | ||
| LibvirtURI: "qemu:///system", | ||
| ClusterProvisioningIP: "172.23.0.3", | ||
| BootstrapProvisioningIP: "172.23.0.2", | ||
| ExternalBridge: "baremetal", | ||
| ProvisioningBridge: "provisioning", | ||
| APIVIP: "192.168.111.2", | ||
| IngressVIP: "192.168.111.3", | ||
| ProvisioningInterface: "ens3", | ||
| ProvisioningNetworkCIDR: "172.23.0.0/24", | ||
| ProvisioningDHCPStart: "172.23.0.20", | ||
| ProvisioningDHCPEnd: "172.23.0.200", | ||
| CachedImageURL: "http://192.168.111.1/images", | ||
| }, | ||
| }, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| ic := &types.InstallConfig{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: testClusterName, | ||
| }, | ||
| BaseDomain: "test", | ||
| } | ||
| SetPlatformDefaults(tc.platform, ic) | ||
| assert.Equal(t, tc.expected, tc.platform, "unexpected platform") | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.