Skip to content

Commit

Permalink
Pass instanceSpec.CtlPlaneIP in CIDR notation
Browse files Browse the repository at this point in the history
Get the ipPrefix from the Cidr in the ipSet reservation, combine
address and prefix when setting CtlPlaneIP in the instanceSpec.

Depends-On: openstack-k8s-operators/openstack-baremetal-operator#129
  • Loading branch information
hjensas committed Feb 16, 2024
1 parent 27b4f4c commit 3df0f94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions pkg/deployment/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,23 @@ func DeployBaremetalSet(
ipSet, ok := ipSets[hostName]
instanceSpec := baremetalSet.Spec.BaremetalHosts[hostName]
if !ok {
// TODO: Change this to raise an error instead.
// NOTE(hjensas): Hardcode /24 here, this used to rely on
// baremetalSet.Spec.CtlplaneNetmask's default value ("255.255.255.0").
utils.LogForObject(helper, "IPAM Not configured for use, skipping", instance)
instanceSpec.CtlPlaneIP = node.Ansible.AnsibleHost
instanceSpec.CtlPlaneIP = fmt.Sprintf("%s/24", node.Ansible.AnsibleHost)
} else {
for _, res := range ipSet.Status.Reservation {
if strings.ToLower(string(res.Network)) == CtlPlaneNetwork {
instanceSpec.CtlPlaneIP = res.Address
_, ipNet, err := net.ParseCIDR(res.Cidr)
if err != nil {
return err
}
ipPrefix, _ := ipNet.Mask.Size()
instanceSpec.CtlPlaneIP = fmt.Sprintf("%s/%d", res.Address, ipPrefix)
baremetalSet.Spec.CtlplaneGateway = *res.Gateway
baremetalSet.Spec.BootstrapDNS = dnsAddresses
baremetalSet.Spec.DNSSearchDomains = []string{res.DNSDomain}
_, ipNet, err := net.ParseCIDR(res.Cidr)
if err == nil {
baremetalSet.Spec.CtlplaneNetmask = net.IP(ipNet.Mask).String()
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/openstackdataplanenodeset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
},
BaremetalHosts: map[string]baremetalv1.InstanceSpec{
"compute-0": {
CtlPlaneIP: "192.168.1.12",
CtlPlaneIP: "192.168.1.12/24",
},
},
}
Expand All @@ -87,7 +87,7 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
},
BaremetalHosts: map[string]baremetalv1.InstanceSpec{
"compute-0": {
CtlPlaneIP: "192.168.1.12",
CtlPlaneIP: "192.168.1.12/24",
},
},
}
Expand Down

0 comments on commit 3df0f94

Please sign in to comment.