Skip to content

Commit

Permalink
Merge pull request #2762 from parth-gr/mds-fix
Browse files Browse the repository at this point in the history
mds: fix mds placement
  • Loading branch information
openshift-merge-bot[bot] authored Aug 30, 2024
2 parents 8499a91 + 603f9e4 commit 4129b30
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
23 changes: 20 additions & 3 deletions controllers/defaults/placements.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
},
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
getWeightedPodAffinityTerm(100, "rook-ceph-mds"),
// left the selector value empty as it will be updated later in the getPlacement()
},
},
},
Expand Down Expand Up @@ -158,7 +158,7 @@ func getTopologySpreadConstraintsSpec(maxSkew int32, valueLabels []string) corev
}

func getWeightedPodAffinityTerm(weight int32, selectorValue ...string) corev1.WeightedPodAffinityTerm {
WeightedPodAffinityTerm := corev1.WeightedPodAffinityTerm{
return corev1.WeightedPodAffinityTerm{
Weight: weight,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
Expand All @@ -173,7 +173,24 @@ func getWeightedPodAffinityTerm(weight int32, selectorValue ...string) corev1.We
TopologyKey: corev1.LabelHostname,
},
}
return WeightedPodAffinityTerm
}

func GetMdsWeightedPodAffinityTerm(weight int32, selectorValue ...string) corev1.WeightedPodAffinityTerm {
return corev1.WeightedPodAffinityTerm{
Weight: weight,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "rook_file_system",
Operator: metav1.LabelSelectorOpIn,
Values: selectorValue,
},
},
},
TopologyKey: corev1.LabelHostname,
},
}
}

func getPodAffinityTerm(selectorValue ...string) corev1.PodAffinityTerm {
Expand Down
8 changes: 8 additions & 0 deletions controllers/storagecluster/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func getPlacement(sc *ocsv1.StorageCluster, component string) rookCephv1.Placeme
} else {
in := defaults.DaemonPlacements[component]
(&in).DeepCopyInto(&placement)
// label rook_file_system is added to the mds pod using rook operator
if component == "mds" {
placement.PodAntiAffinity = &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
defaults.GetMdsWeightedPodAffinityTerm(100, generateNameForCephFilesystem(sc)),
},
}
}
}

// ignore default PodAntiAffinity mon placement when arbiter is enabled
Expand Down
19 changes: 17 additions & 2 deletions controllers/storagecluster/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ func TestGetPlacement(t *testing.T) {
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "app",
Key: "rook_file_system",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"rook-ceph-mds"},
Values: []string{"storage-test-cephfilesystem"},
},
},
},
Expand Down Expand Up @@ -507,6 +507,21 @@ func TestGetPlacement(t *testing.T) {
assert.Equal(t, expectedPlacement, actualPlacement, c.label)

expectedPlacement = c.expectedPlacements["mds"]
testPodAffinity := &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
defaults.GetMdsWeightedPodAffinityTerm(100, generateNameForCephFilesystem(sc)),
},
}
if expectedPlacement.PodAntiAffinity != nil {
topologyKeys := ""
if len(expectedPlacement.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution) != 0 {
topologyKeys = expectedPlacement.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.TopologyKey
}
expectedPlacement.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution = testPodAffinity.PreferredDuringSchedulingIgnoredDuringExecution
if topologyKeys != "" {
expectedPlacement.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.TopologyKey = topologyKeys
}
}
actualPlacement = getPlacement(sc, "mds")
assert.Equal(t, expectedPlacement, actualPlacement, c.label)
}
Expand Down

0 comments on commit 4129b30

Please sign in to comment.