Skip to content

Commit

Permalink
Merge pull request #1401 from achouhan09/topology-const
Browse files Browse the repository at this point in the history
Added TopologySpreadConstraints to the backingstore pod for better performance
  • Loading branch information
achouhan09 authored Aug 5, 2024
2 parents d3d8033 + a11a7e6 commit 2660a9a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
25 changes: 23 additions & 2 deletions pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ func (r *Reconciler) isPodinNoobaa(pod *corev1.Pod) bool {
}

func (r *Reconciler) updatePodTemplate() error {
log := r.Logger.WithField("func", "updatePodTemplate")
c := &r.PodAgentTemplate.Spec.Containers[0]
for j := range c.Env {
switch c.Env[j].Name {
Expand Down Expand Up @@ -1277,8 +1278,9 @@ func (r *Reconciler) updatePodTemplate() error {
[]corev1.LocalObjectReference{*r.NooBaa.Spec.ImagePullSecret}
}
r.PodAgentTemplate.Labels = map[string]string{
"app": "noobaa",
"pool": r.BackingStore.Name,
"app": "noobaa",
"pool": r.BackingStore.Name,
"backingstore": "noobaa",
}
if r.NooBaa.Spec.Tolerations != nil {
r.PodAgentTemplate.Spec.Tolerations = r.NooBaa.Spec.Tolerations
Expand All @@ -1287,6 +1289,25 @@ func (r *Reconciler) updatePodTemplate() error {
r.PodAgentTemplate.Spec.Affinity = r.NooBaa.Spec.Affinity
}

if !util.HasNodeInclusionPolicyInPodTopologySpread() {
log.Info("TopologySpreadConstraints cannot be set because feature gate NodeInclusionPolicyInPodTopologySpread is not supported on this cluster version")
} else {
log.Info("Adding default TopologySpreadConstraints to backingstore pod")
honor := corev1.NodeInclusionPolicyHonor
topologySpreadConstraint := corev1.TopologySpreadConstraint{
MaxSkew: 1,
TopologyKey: "kubernetes.io/hostname",
WhenUnsatisfiable: corev1.ScheduleAnyway,
NodeTaintsPolicy: &honor,
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"backingstore": "noobaa",
},
},
}
r.PodAgentTemplate.Spec.TopologySpreadConstraints = []corev1.TopologySpreadConstraint{topologySpreadConstraint}
}

return r.updatePodResourcesTemplate(c)
}

Expand Down
31 changes: 6 additions & 25 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"encoding/json"

"cloud.google.com/go/storage"
semver "github.com/coreos/go-semver/semver"
"github.com/marstr/randname"
nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
"github.com/noobaa/noobaa-operator/v5/pkg/bundle"
Expand All @@ -42,12 +41,11 @@ import (
)

const (
ibmEndpoint = "https://s3.direct.%s.cloud-object-storage.appdomain.cloud"
ibmLocation = "%s-standard"
ibmCosBucketCred = "ibm-cloud-cos-creds"
topologyConstraintsEnabledKubeVersion = "1.26.0"
minutesToWaitForDefaultBSCreation = 10
credentialsKey = "credentials"
ibmEndpoint = "https://s3.direct.%s.cloud-object-storage.appdomain.cloud"
ibmLocation = "%s-standard"
ibmCosBucketCred = "ibm-cloud-cos-creds"
minutesToWaitForDefaultBSCreation = 10
credentialsKey = "credentials"
)

type gcpAuthJSON struct {
Expand Down Expand Up @@ -285,7 +283,7 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error {
disableDefaultTopologyConstraints, found := r.NooBaa.ObjectMeta.Annotations[nbv1.SkipTopologyConstraints]
if podSpec.TopologySpreadConstraints != nil {
r.Logger.Debugf("deployment %s TopologySpreadConstraints already exists, leaving as is", r.DeploymentEndpoint.Name)
} else if !r.hasNodeInclusionPolicyInPodTopologySpread() {
} else if !util.HasNodeInclusionPolicyInPodTopologySpread() {
r.Logger.Debugf("deployment %s TopologySpreadConstraints cannot be set because feature gate NodeInclusionPolicyInPodTopologySpread is not supported on this cluster version",
r.DeploymentEndpoint.Name)
} else if found && disableDefaultTopologyConstraints == "true" {
Expand Down Expand Up @@ -436,23 +434,6 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error {
return nil
}

func (r *Reconciler) hasNodeInclusionPolicyInPodTopologySpread() bool {
kubeVersion, err := util.GetKubeVersion()
if err != nil {
r.Logger.Printf("❌ Failed to get kube version %s", err)
return false
}
enabledKubeVersion, err := semver.NewVersion(topologyConstraintsEnabledKubeVersion)
if err != nil {
util.Panic(err)
return false
}
if kubeVersion.LessThan(*enabledKubeVersion) {
return false
}
return true
}

func (r *Reconciler) setDesiredRootMasterKeyMounts(podSpec *corev1.PodSpec, container *corev1.Container) {
// Don't map secret map volume if the string secret is used
if len(r.SecretRootMasterKey) > 0 {
Expand Down
20 changes: 20 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
gigabyte = 1024 * 1024 * 1024
petabyte = gigabyte * 1024 * 1024
obcMaxSizeUpperLimit = petabyte * 1023

topologyConstraintsEnabledKubeVersion = "1.26.0"
)

// OAuth2Endpoints holds OAuth2 endpoints information.
Expand Down Expand Up @@ -2199,3 +2201,21 @@ func IsDevEnv() bool {
}
return false
}

// HasNodeInclusionPolicyInPodTopologySpread checks if the cluster supports the spread topology policy
func HasNodeInclusionPolicyInPodTopologySpread() bool {
kubeVersion, err := GetKubeVersion()
if err != nil {
fmt.Printf("❌ Failed to get kube version %s", err)
return false
}
enabledKubeVersion, err := semver.NewVersion(topologyConstraintsEnabledKubeVersion)
if err != nil {
Panic(err)
return false
}
if kubeVersion.LessThan(*enabledKubeVersion) {
return false
}
return true
}

0 comments on commit 2660a9a

Please sign in to comment.