Skip to content

Commit 106baca

Browse files
sumanthravipatiSumanth Ravipati
andauthored
CLD-925: Topology Spread Constraints Implementation Changes Commit(#168)
Co-authored-by: Sumanth Ravipati <[email protected]>
1 parent d3e63d1 commit 106baca

File tree

3 files changed

+95
-81
lines changed

3 files changed

+95
-81
lines changed

charts/values.yaml

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,24 @@ license:
9494

9595
## Configure Affinity property for scheduling pods to nodes
9696
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
97-
## Preferred anti affinity rule to schedule one marklogic pod per worker node
98-
affinity:
99-
podAntiAffinity:
100-
preferredDuringSchedulingIgnoredDuringExecution:
101-
- weight: 100
102-
podAffinityTerm:
103-
labelSelector:
104-
matchExpressions:
105-
- key: app.kubernetes.io/name
106-
operator: In
107-
values:
108-
- marklogic
109-
topologyKey: kubernetes.io/hostname
110-
111-
## Configure POD Topology Spread Constraints to spread Pods across cluster
97+
affinity: {}
98+
99+
## Configure POD Topology Spread Constraints to spread pods across cluster
112100
## ref: https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/
113-
topologySpreadConstraints: []
114-
# - maxSkew: 1
115-
# topologyKey: topology.kubernetes.io/zone
116-
# whenUnsatisfiable: ScheduleAnyway
117-
# labelSelector:
118-
# matchLabels:
119-
# app.kubernetes.io/name: marklogic
101+
## Preferred Topology Spread Constraints rule to evenly distribute Marklogic pods across worker nodes and zones
102+
topologySpreadConstraints:
103+
- maxSkew: 1
104+
topologyKey: kubernetes.io/hostname
105+
whenUnsatisfiable: DoNotSchedule
106+
labelSelector:
107+
matchLabels:
108+
app.kubernetes.io/name: marklogic
109+
- maxSkew: 1
110+
topologyKey: topology.kubernetes.io/zone
111+
whenUnsatisfiable: ScheduleAnyway
112+
labelSelector:
113+
matchLabels:
114+
app.kubernetes.io/name: marklogic
120115

121116
## Configure NodeSelector property for scheduling pods to nodes
122117
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/#create-a-pod-that-gets-scheduled-to-your-chosen-node

test/template/pod_antiaffinity_templ_test.go

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package template_test
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
appsv1 "k8s.io/api/apps/v1"
10+
11+
"github.com/gruntwork-io/terratest/modules/helm"
12+
"github.com/gruntwork-io/terratest/modules/k8s"
13+
"github.com/gruntwork-io/terratest/modules/random"
14+
)
15+
16+
func TestChartTemplateTopologySpreadConstraintClass(t *testing.T) {
17+
18+
// Path to the helm chart we will test
19+
helmChartPath, err := filepath.Abs("../../charts")
20+
releaseName := "marklogic-topologyspreadconstraint-test"
21+
t.Log(helmChartPath, releaseName)
22+
require.NoError(t, err)
23+
24+
// Set up the namespace; confirm that the template renders the expected value for the namespace.
25+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
26+
t.Logf("Namespace: %s\n", namespaceName)
27+
28+
// Setup the args for helm install
29+
options := &helm.Options{
30+
SetValues: map[string]string{
31+
"image.repository": "marklogicdb/marklogic-db",
32+
"image.tag": "latest",
33+
"persistence.enabled": "false",
34+
},
35+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
36+
}
37+
38+
// render the tempate
39+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
40+
41+
var statefulset appsv1.StatefulSet
42+
helm.UnmarshalK8SYaml(t, output, &statefulset)
43+
44+
// Verify the name and namespace matches
45+
require.Equal(t, namespaceName, statefulset.Namespace)
46+
47+
// Verify the topologySpreadConstraint rule is set
48+
expectedLabelSelector := map[string]string{
49+
"app.kubernetes.io/name": "marklogic",
50+
}
51+
expectedMaxSkewValue := 1
52+
expectedHostTopologyKey := "kubernetes.io/hostname"
53+
expectedHostScheduleCondition := "DoNotSchedule"
54+
expectedZoneTopologyKey := "topology.kubernetes.io/zone"
55+
expectedZoneScheduleCondition := "ScheduleAnyway"
56+
57+
topologySpreadConstraintsRule := statefulset.Spec.Template.Spec.TopologySpreadConstraints
58+
59+
hostMaxSkew := int(topologySpreadConstraintsRule[0].MaxSkew)
60+
hostTopologyKey := topologySpreadConstraintsRule[0].TopologyKey
61+
hostScheduleCondition := topologySpreadConstraintsRule[0].WhenUnsatisfiable
62+
hostLabelSelector := topologySpreadConstraintsRule[0].LabelSelector.MatchLabels
63+
64+
zoneMaxSkew := int(topologySpreadConstraintsRule[1].MaxSkew)
65+
zoneTopologyKey := topologySpreadConstraintsRule[1].TopologyKey
66+
zoneScheduleCondition := topologySpreadConstraintsRule[1].WhenUnsatisfiable
67+
zoneLabelSelector := topologySpreadConstraintsRule[1].LabelSelector.MatchLabels
68+
69+
require.Equal(t, hostMaxSkew, expectedMaxSkewValue)
70+
require.Equal(t, hostTopologyKey, expectedHostTopologyKey)
71+
require.Equal(t, string(hostScheduleCondition), expectedHostScheduleCondition)
72+
require.Equal(t, hostLabelSelector, expectedLabelSelector)
73+
74+
require.Equal(t, zoneMaxSkew, expectedMaxSkewValue)
75+
require.Equal(t, zoneTopologyKey, expectedZoneTopologyKey)
76+
require.Equal(t, string(zoneScheduleCondition), expectedZoneScheduleCondition)
77+
require.Equal(t, zoneLabelSelector, expectedLabelSelector)
78+
}

0 commit comments

Comments
 (0)