Skip to content

Commit 93fc8d6

Browse files
Merge pull request #77 from barkhachoithani/feature/CLD-667
CLD-667: Provide Option to Configure Pod Priority
2 parents 168c124 + 87904c2 commit 93fc8d6

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,27 @@ Note: To use network policies, you must be using a networking solution that supp
400400

401401
Use NetworkPolicy to control network traffic flow for your applications, it allows you to specify how pods should communicate over the network. By default network policy is disabled in the values.yaml file. Set the networkPolicy.enabled to true to enable the use of network policy resource, default ports are provided in the settings, you can define custom rules for the sources of the traffic to the desired ports.
402402

403+
## Pod Priorty
404+
405+
Pods can be assigned priority that reflects the signifance of a pod compared to other pods. For detailed explanation, please refer [https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/)
406+
407+
To add priority for pods, use the following the steps:
408+
409+
1. Add a PriorityClass. Following is an example of PriorityClass:
410+
```
411+
apiVersion: scheduling.k8s.io/v1
412+
kind: PriorityClass
413+
metadata:
414+
name: high-priority
415+
value: 1000000
416+
globalDefault: false
417+
description: "This high priority class should be used for MarkLogic service pods only."
418+
```
419+
For more details and examples, refer [https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass)
420+
421+
2. Set priorityClassName in the values.yaml file or using --set flag while installing the chart. Value of priorityClassName should be set to one of the added PriorityClassName.
422+
423+
403424
## Notice
404425

405426
To use transactional functionality with MarkLogic, you have to set up Ingress and configure cookie-based session affinity. This function will be supported in a future release.
@@ -494,6 +515,7 @@ This table describes the list of available parameters for Helm Chart.
494515
| `networkPolicy.enabled` | Enable this parameter to enable network policy | `false` |
495516
| `networkPolicy.customRules` | Placeholder to specify selectors | `{}` |
496517
| `networkPolicy.ports` | Ports to which traffic is allowed | `[8000, 8001, 8002]` |
518+
| `priorityClassName` | Name of a PriortyClass defined to set pod priority | `""` |
497519

498520
# Known Issues and Limitations
499521

charts/templates/statefulset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ spec:
264264
fieldPath: metadata.name
265265
resources: {{- toYaml .Values.logCollection.resources | nindent 12 }}
266266
{{- end }}
267+
{{- if .Values.priorityClassName }}
268+
priorityClassName: {{ .Values.priorityClassName }}
269+
{{- end }}
267270
{{- with .Values.nodeSelector }}
268271
nodeSelector: {{- toYaml . | nindent 8}}
269272
{{- end }}

charts/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ serviceAccount:
100100
# If not set and create is true, a name is generated using the fullname template
101101
name: ""
102102

103+
# Configure priority class for pods
104+
# ref: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/
105+
priorityClassName: ""
106+
103107
# Configure options for network policy
104108
# ref: https://kubernetes.io/docs/concepts/services-networking/network-policies
105109
networkPolicy:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 TestChartTemplatePodPriorityClass(t *testing.T) {
17+
t.Parallel()
18+
19+
// Path to the helm chart we will test
20+
helmChartPath, err := filepath.Abs("../../charts")
21+
releaseName := "marklogic-pod-priority-test"
22+
t.Log(helmChartPath, releaseName)
23+
require.NoError(t, err)
24+
25+
// Set up the namespace; confirm that the template renders the expected value for the namespace.
26+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
27+
t.Logf("Namespace: %s\n", namespaceName)
28+
29+
// Setup the args for helm install
30+
options := &helm.Options{
31+
SetValues: map[string]string{
32+
"image.repository": "marklogicdb/marklogic-db",
33+
"image.tag": "latest",
34+
"persistence.enabled": "false",
35+
"priorityClassName": "high-priority",
36+
},
37+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
38+
}
39+
40+
// render the tempate
41+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
42+
43+
var statefulset appsv1.StatefulSet
44+
helm.UnmarshalK8SYaml(t, output, &statefulset)
45+
46+
// Verify the name and namespace matches
47+
require.Equal(t, namespaceName, statefulset.Namespace)
48+
49+
// Verify the priortyClass is set for pods
50+
expectedPriorityClass := "high-priority"
51+
statefulSetPods := statefulset.Spec.Template.Spec
52+
require.Equal(t, statefulSetPods.PriorityClassName, expectedPriorityClass)
53+
}

0 commit comments

Comments
 (0)