diff --git a/pkg/operator/ceph/cluster/mon/spec.go b/pkg/operator/ceph/cluster/mon/spec.go index 140657f4d..9d79ace7b 100644 --- a/pkg/operator/ceph/cluster/mon/spec.go +++ b/pkg/operator/ceph/cluster/mon/spec.go @@ -79,7 +79,7 @@ func GetFailureDomainLabel(spec cephv1.ClusterSpec) string { } if spec.ZonesRequired() && spec.Mon.FailureDomainLabel != "" { - return spec.Mon.StretchCluster.FailureDomainLabel + return spec.Mon.FailureDomainLabel } // The default topology label is for a zone return corev1.LabelZoneFailureDomainStable diff --git a/pkg/operator/ceph/cluster/mon/spec_test.go b/pkg/operator/ceph/cluster/mon/spec_test.go index a4d666429..1384d90de 100644 --- a/pkg/operator/ceph/cluster/mon/spec_test.go +++ b/pkg/operator/ceph/cluster/mon/spec_test.go @@ -256,3 +256,69 @@ func TestRequiredDuringScheduling(t *testing.T) { testRequiredDuringScheduling(t, true, true, true) testRequiredDuringScheduling(t, false, true, false) } + +func TestGetFailureDomainLabel(t *testing.T) { + type args struct { + spec cephv1.ClusterSpec + } + tests := []struct { + name string + args args + want string + }{ + { + name: "stretch", + args: args{ + spec: cephv1.ClusterSpec{ + Mon: cephv1.MonSpec{ + Count: 3, + StretchCluster: &cephv1.StretchClusterSpec{ + FailureDomainLabel: "topology.kubernetes.io/region", + Zones: []cephv1.MonZoneSpec{ + {Name: "eu-central-1"}, + {Name: "eu-central-2"}, + {Name: "eu-central-3"}, + }, + }, + }, + }, + }, + want: "topology.kubernetes.io/region", + }, + { + name: "zones", + args: args{ + spec: cephv1.ClusterSpec{ + Mon: cephv1.MonSpec{ + Count: 3, + FailureDomainLabel: "topology.kubernetes.io/zone", + Zones: []cephv1.MonZoneSpec{ + {Name: "eu-central-1a"}, + {Name: "eu-central-1b"}, + {Name: "eu-central-1c"}, + }, + }, + }, + }, + want: "topology.kubernetes.io/zone", + }, + { + name: "default", + args: args{ + spec: cephv1.ClusterSpec{ + Mon: cephv1.MonSpec{ + Count: 3, + }, + }, + }, + want: "topology.kubernetes.io/zone", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetFailureDomainLabel(tt.args.spec); got != tt.want { + t.Errorf("GetFailureDomainLabel() = %v, want %v", got, tt.want) + } + }) + } +}