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

CephFS: Update fetchIP() to add support for IPv6 address #4230

Merged
merged 2 commits into from
Nov 8, 2023
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
9 changes: 6 additions & 3 deletions internal/csi-addons/networkfence/fencing.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ func (ac *activeClient) fetchIP() (string, error) {
clientInfo := ac.Inst
parts := strings.Fields(clientInfo)
if len(parts) >= 2 {
ip := strings.Split(parts[1], ":")[0]

return ip, nil
lastColonIndex := strings.LastIndex(parts[1], ":")
firstPart := parts[1][:lastColonIndex]
ip := net.ParseIP(firstPart)
if ip != nil {
return ip.String(), nil
}
}

return "", fmt.Errorf("failed to extract IP address, incorrect format: %s", clientInfo)
Expand Down
5 changes: 5 additions & 0 deletions internal/csi-addons/networkfence/fencing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func TestFetchIP(t *testing.T) {
expectedIP: "172.21.9.34",
expectedErr: false,
},
{
clientInfo: "client.4305 2001:0db8:85a3:0000:0000:8a2e:0370:7334:0/422650892",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you confirm that Ceph uses this format with IPv6 addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the official documentation of ceph
As the inst listed in ceph tell mds.0 client ls for the IPv4 address,
'"inst": "client.4305 172.21.9.34:0/422650892",
So IPv6 should also be the same only like the client id and then..
I'll check with ceph for more clarity on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with Xiubo and Kotresh, the given syntax is fine!

expectedIP: "2001:db8:85a3::8a2e:370:7334",
expectedErr: false,
},
{
clientInfo: "",
expectedIP: "",
Expand Down