Skip to content
Draft
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
39 changes: 15 additions & 24 deletions controllers/storagecluster/cephcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.
}
}

ipFamily, isDualStack, err := getIPFamilyConfig(r.Client)
ipFamily, err := getIPFamilyConfig(r.Client)
if err != nil {
r.Log.Error(err, "failed to get IPFamily of the cluster")
return reconcile.Result{}, err
Expand All @@ -240,14 +240,9 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.
// Dual Stack is not supported in downstream ceph. BZ references:
// https://bugzilla.redhat.com/show_bug.cgi?id=1804290
// https://bugzilla.redhat.com/show_bug.cgi?id=2181350#c10
// So use IPv4 and DualStack:False in case of dual stack cluster
// No need to update the ipFamily config in the Network settings if the cluster is single Stack IPv4.
if isDualStack {
cephCluster.Spec.Network.IPFamily = rookCephv1.IPv4
cephCluster.Spec.Network.DualStack = false
} else if ipFamily == rookCephv1.IPv6 {
cephCluster.Spec.Network.IPFamily = ipFamily
}
// So spec.Network.DualStack never set to true in the CephCluster resource
r.Log.Info("Setting IPFamily", "IPFamily", ipFamily, "CephCluster", klog.KRef(cephCluster.Namespace, cephCluster.Name))
cephCluster.Spec.Network.IPFamily = ipFamily

// Check if this CephCluster already exists
found := &rookCephv1.CephCluster{}
Expand Down Expand Up @@ -1334,30 +1329,26 @@ func getMonitoringClient() (*monitoringclient.Clientset, error) {
}

// getIPFamilyConfig checks for a Single Stack IPv6 or a Dual Stack cluster
func getIPFamilyConfig(c client.Client) (rookCephv1.IPFamilyType, bool, error) {
isIPv6 := false
isIPv4 := false
func getIPFamilyConfig(c client.Client) (rookCephv1.IPFamilyType, error) {
networkConfig := &configv1.Network{}
err := c.Get(context.TODO(), types.NamespacedName{Name: "cluster", Namespace: ""}, networkConfig)
if err != nil {
return "", false, fmt.Errorf("could not get network config details. %v", err)
return "", fmt.Errorf("could not get network config details. %v", err)
}

// Note: In case of a dual stack cluster, the order of the CIDR in the networkConfig resource decides if its a IPv6 Primary or IPv4 primary cluster.
// So we only check the first CIDR entry and return the IPFamily accordingly.
for _, cidr := range networkConfig.Status.ClusterNetwork {
if strings.Count(cidr.CIDR, ":") < 2 {
isIPv4 = true
} else if strings.Count(cidr.CIDR, ":") >= 2 {
isIPv6 = true
if strings.Count(cidr.CIDR, ":") >= 2 {
// the first CIDR entry is IPv6. So return IPv6 IPFamily
return rookCephv1.IPv6, nil
} else if strings.Count(cidr.CIDR, ":") < 2 {
// the first CIDR entry is IPv4. So return IPv4 IPFamily
return rookCephv1.IPv4, nil
}
}

if isIPv4 && isIPv6 {
return "", true, nil
} else if isIPv6 { // IPv6 single stack cluster
return rookCephv1.IPv6, false, nil
}

return rookCephv1.IPv4, false, nil
return rookCephv1.IPv4, nil
}

func updateOSDStore(existingOSDStore rookCephv1.OSDStore) rookCephv1.OSDStore {
Expand Down
25 changes: 16 additions & 9 deletions controllers/storagecluster/cephcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestEnsureCephCluster(t *testing.T) {
reconciler := createFakeStorageClusterReconciler(t, networkConfig)

expected := newCephCluster(reconciler, mockStorageCluster.DeepCopy(), nil)
expected.Spec.Network.IPFamily = rookCephv1.IPv4
expected.Status.State = c.cephClusterState

if !c.shouldCreate {
Expand Down Expand Up @@ -1688,19 +1689,28 @@ func TestGetIPFamilyConfig(t *testing.T) {
// status of the configv1.Network object for the cluster
networkStatus configv1.NetworkStatus
expectedIPFamily rookCephv1.IPFamilyType
isDualStack bool
expectedError error
}{
{
label: "Case #1: DualStack cluster",
label: "Case #1: DualStack cluster (IPv4)",
networkStatus: configv1.NetworkStatus{
ClusterNetwork: []configv1.ClusterNetworkEntry{
{CIDR: "198.1v2.3.4/16"},
{CIDR: "fd01::/48"},
},
},
expectedIPFamily: "",
isDualStack: true,
expectedIPFamily: "IPv4",
expectedError: nil,
},
{
label: "Case #2: DualStack cluster (IPv6 Primary)",
networkStatus: configv1.NetworkStatus{
ClusterNetwork: []configv1.ClusterNetworkEntry{
{CIDR: "fd01::/48"},
{CIDR: "198.1v2.3.4/16"},
},
},
expectedIPFamily: "IPv6",
expectedError: nil,
},
{
Expand All @@ -1711,18 +1721,16 @@ func TestGetIPFamilyConfig(t *testing.T) {
},
},
expectedIPFamily: "IPv6",
isDualStack: false,
expectedError: nil,
},
{
label: "Case #1: IPv4 cluster",
label: "Case #1: IPv4 Cluster",
networkStatus: configv1.NetworkStatus{
ClusterNetwork: []configv1.ClusterNetworkEntry{
{CIDR: "198.1v2.3.4/16"},
},
},
expectedIPFamily: "IPv4",
isDualStack: false,
expectedError: nil,
},
}
Expand All @@ -1737,9 +1745,8 @@ func TestGetIPFamilyConfig(t *testing.T) {
Status: tc.networkStatus,
}
r := createFakeStorageClusterReconciler(t, networkConfig)
ipfamily, isDualStack, err := getIPFamilyConfig(r.Client)
ipfamily, err := getIPFamilyConfig(r.Client)
assert.Equal(t, ipfamily, tc.expectedIPFamily)
assert.Equal(t, isDualStack, tc.isDualStack)
assert.Equal(t, err, tc.expectedError)
})

Expand Down
Loading