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

Add IPv6 support for networkdata #129

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
description: InstanceSpec Instance specific attributes
properties:
ctlPlaneIP:
description: CtlPlaneIP - Control Plane IP
description: CtlPlaneIP - Control Plane IP in CIDR notation
type: string
networkData:
description: NetworkData - Host Network Data
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/openstackbaremetalset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type AutomatedCleaningMode string
// InstanceSpec Instance specific attributes
type InstanceSpec struct {
// +kubebuilder:validation:Optional
// CtlPlaneIP - Control Plane IP
// CtlPlaneIP - Control Plane IP in CIDR notation
CtlPlaneIP string `json:"ctlPlaneIP"`
// +kubebuilder:validation:Optional
// UserData - Host User Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
description: InstanceSpec Instance specific attributes
properties:
ctlPlaneIP:
description: CtlPlaneIP - Control Plane IP
description: CtlPlaneIP - Control Plane IP in CIDR notation
type: string
networkData:
description: NetworkData - Host Network Data
Expand Down
5 changes: 2 additions & 3 deletions config/samples/baremetal_v1beta1_openstackbaremetalset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ spec:
# Define how many BaremetalHosts are desired to be provisioned and assign
# a control plane IP to them
baremetalHosts:
compute-0: 172.22.0.100
compute-1: 172.22.0.101
compute-0: 172.22.0.100/24
compute-1: 172.22.0.101/24
# The image to install on the provisioned nodes
osImage: edpm-hardened-uefi.qcow2
# provisionServerName: openstack # uncomment if you pre-deploy a separate OsProvServer (use its name for the value)
Expand All @@ -17,7 +17,6 @@ spec:
# The interface on the nodes that will be assigned an IP from the mgmtCidr
ctlplaneInterface: enp1s0
ctlplaneGateway: 172.22.0.3
ctlplaneNetmask: 255.255.255.0
# An optional secret holding a data entry called "NodeRootPassword"
# This will be set as the root password on all provisioned BaremetalHosts
passwordSecret: baremetalset-password-secret
33 changes: 31 additions & 2 deletions pkg/openstackbaremetalset/baremetalhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openstackbaremetalset
import (
"context"
"fmt"
"net"
"strings"

metal3v1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
Expand Down Expand Up @@ -99,11 +100,39 @@ func BaremetalHostProvision(
}

if networkDataSecret == nil {

// Check IP version and set template variables accordingly
ipAddr, ipNet, err := net.ParseCIDR(ctlPlaneIP)
if err != nil {
// TODO: Remove this conversion once all usage sets ctlPlaneIP in CIDR format.
ipAddr = net.ParseIP(ctlPlaneIP)
if ipAddr == nil {
return err
}

var ipPrefix int
if ipAddr.To4() != nil {
ipPrefix, _ = net.IPMask(net.ParseIP(instance.Spec.CtlplaneNetmask).To4()).Size()
} else {
ipPrefix, _ = net.IPMask(net.ParseIP(instance.Spec.CtlplaneNetmask).To16()).Size()
}
_, ipNet, err = net.ParseCIDR(fmt.Sprintf("%s/%d", ipAddr, ipPrefix))
if err != nil {
return err
}
}

CtlplaneIPVersion := "ipv6"
if ipAddr.To4() != nil {
CtlplaneIPVersion = "ipv4"
}

templateParameters := make(map[string]interface{})
templateParameters["CtlplaneIp"] = ctlPlaneIP
templateParameters["CtlplaneIpVersion"] = CtlplaneIPVersion
templateParameters["CtlplaneIp"] = ipAddr
templateParameters["CtlplaneInterface"] = instance.Spec.CtlplaneInterface
templateParameters["CtlplaneGateway"] = instance.Spec.CtlplaneGateway
templateParameters["CtlplaneNetmask"] = instance.Spec.CtlplaneNetmask
templateParameters["CtlplaneNetmask"] = net.IP(ipNet.Mask)
if len(instance.Spec.BootstrapDNS) > 0 {
templateParameters["CtlplaneDns"] = instance.Spec.BootstrapDNS
} else {
Expand Down
11 changes: 7 additions & 4 deletions templates/openstackbaremetalset/cloudinit/networkdata
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ links:
id: {{ .CtlplaneInterface }}
type: vif
networks:
- netmask: {{ .CtlplaneNetmask }}
link: {{ .CtlplaneInterface }}
- link: {{ .CtlplaneInterface }}
id: {{ .CtlplaneInterface }}
type: {{ .CtlplaneIpVersion }}
ip_address: {{ .CtlplaneIp }}
type: ipv4
netmask: {{ .CtlplaneNetmask }}
{{- if (index . "CtlplaneGateway") }}
gateway: {{ .CtlplaneGateway }}
routes:
- network: {{ if eq .CtlplaneIpVersion "ipv6" }}::{{ else }}0.0.0.0{{ end }}
netmask: {{ if eq .CtlplaneIpVersion "ipv6" }}::{{ else }}0.0.0.0{{ end }}
gateway: {{ .CtlplaneGateway }}
{{- end }}
{{- if not (eq (len .CtlplaneDns) 0) }}
services:
Expand Down