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

Use Required Pod anti affinity if Active MDS is not more than 1 #3035

Merged
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
2 changes: 1 addition & 1 deletion controllers/defaults/placements.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var (
getOcsToleration(),
},
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
// left the selector value empty as it will be updated later in the getPlacement()
},
},
Expand Down
18 changes: 14 additions & 4 deletions controllers/storagecluster/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ func getPlacement(sc *ocsv1.StorageCluster, component string) rookCephv1.Placeme
(&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)),
},
// if active MDS number is more than 1 then Preferred and if it is 1 then Required pod anti-affinity is set
mdsWeightedPodAffinity := defaults.GetMdsWeightedPodAffinityTerm(100, generateNameForCephFilesystem(sc))
if sc.Spec.ManagedResources.CephFilesystems.ActiveMetadataServers > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

@malayparida2000 can we also list the total nodes and see if the storage nodes are more than a number of pods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parth-gr I didn't do that as this fix needs to be backported till 4.15 & I don't want to add client list operations in backports. We can implement the get node & decision based on that may be in 4.19.

Copy link
Member

@parth-gr parth-gr Feb 12, 2025

Choose a reason for hiding this comment

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

@malayparida2000 the fix for using filesystem name as key for antiaffinity is even not backported, so there is already being a lot of changes

So can have this in 4.18?

And for backports we can have seperate PR in 4.17

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went through the code a bit. To list & get odf labeled nodes We will need a change in the getPlacement() funcs signature as it would now need the client. This would require a lot of changes in the codebase especially the unit tests. Considering tomorrow is the RC I don't think it's achievable by tomorrow.

placement.PodAntiAffinity = &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
mdsWeightedPodAffinity,
},
}
} else {
placement.PodAntiAffinity = &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
mdsWeightedPodAffinity.PodAffinityTerm,
},
}
}
}
}
Expand Down
31 changes: 14 additions & 17 deletions controllers/storagecluster/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,18 @@ func TestGetPlacement(t *testing.T) {
NodeAffinity: defaults.DefaultNodeAffinity,
Tolerations: defaults.DaemonPlacements["mds"].Tolerations,
PodAntiAffinity: &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "rook_file_system",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"storage-test-cephfilesystem"},
},
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "rook_file_system",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"storage-test-cephfilesystem"},
},
},
TopologyKey: corev1.LabelZoneFailureDomainStable,
},
TopologyKey: corev1.LabelZoneFailureDomainStable,
},
},
},
Expand Down Expand Up @@ -503,18 +500,18 @@ func TestGetPlacement(t *testing.T) {

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