Skip to content

Commit

Permalink
Use square brackets around IPv6 in ceph.conf (canonical#432)
Browse files Browse the repository at this point in the history
Small PR which adds square brackets around mon host addresses in
`ceph.conf` if IPv6 is used.

Closes canonical#424.

---------

Signed-off-by: Mark Bolton <[email protected]>
  • Loading branch information
boltmark authored Oct 10, 2024
1 parent 4c28584 commit c76c1f5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ jobs:
run: |
sudo snap logs microceph -n 1000
- name: Test square brackets around IPv6
run: |
sudo snap remove microceph
export MON_IP="fd42:7273:f336:a22::1"
sudo ip -6 addr add dev eth0 "${MON_IP}"
~/actionutils.sh install_microceph "${MON_IP}"
cat /var/snap/microceph/current/conf/ceph.conf
fgrep -q "[${MON_IP}]" /var/snap/microceph/current/conf/ceph.conf
multi-node-tests:
name: Multi node testing
runs-on: ubuntu-22.04
Expand Down
9 changes: 8 additions & 1 deletion microceph/ceph/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql"
"fmt"
"net"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -40,12 +41,18 @@ func Bootstrap(ctx context.Context, s interfaces.StateInterface, data common.Boo
return err
}

// Ensure mon-ip is enclosed in square brackets if IPv6.
monIp := data.MonIp
if net.ParseIP(monIp) != nil && strings.Contains(monIp, ":") {
monIp = fmt.Sprintf("[%s]", monIp)
}

err = conf.WriteConfig(
map[string]any{
"fsid": fsid,
"runDir": pathConsts.RunPath,
// First monitor bootstrap IP as passed to microcluster.
"monitors": data.MonIp,
"monitors": monIp,
"pubNet": data.PublicNet,
"ipv4": strings.Contains(data.PublicNet, "."),
"ipv6": strings.Contains(data.PublicNet, ":"),
Expand Down
18 changes: 18 additions & 0 deletions microceph/ceph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ func UpdateConfig(ctx context.Context, s interfaces.StateInterface) error {
}
}

// Ensure that IPv6 addresses have square brackets around them (if IPv6 is used).
monitorAddresses = formatIPv6(monitorAddresses)

conf := NewCephConfig(constants.CephConfFileName)

// Check if host has IP address on the configured public network.
Expand Down Expand Up @@ -442,3 +445,18 @@ func getMonitorAddresses(configs map[string]string) []string {
}
return monHosts
}

// formatIPv6 returns a slice in which all IPv6 addresses are formatted with square brackets.
func formatIPv6(addrs []string) []string {
formatted := []string{}
for _, addr := range addrs {
ip := net.ParseIP(addr)
if ip != nil && strings.Contains(addr, ":") {
addr = fmt.Sprintf("[%s]", addr)
}

formatted = append(formatted, addr)
}

return formatted
}
8 changes: 6 additions & 2 deletions tests/scripts/actionutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function setup_lxd() {
}

function install_microceph() {
local mon_ip="${1}"
# Install locally built microceph snap and connect interfaces
sudo snap install --dangerous ~/microceph_*.snap
sudo snap connect microceph:block-devices
Expand All @@ -26,15 +27,18 @@ function install_microceph() {
sudo snap connect microceph:microceph-support
sudo snap connect microceph:network-bind

sudo microceph cluster bootstrap
if [ -n "${mon_ip}" ]; then
sudo microceph cluster bootstrap --mon-ip "${mon_ip}"
else
sudo microceph cluster bootstrap
fi
sudo microceph.ceph version
sudo microceph.ceph status

# Allow ceph to notice no OSD are present
sleep 30
sudo microceph.ceph status
sudo microceph.ceph health

}

function create_loop_devices() {
Expand Down

0 comments on commit c76c1f5

Please sign in to comment.