Skip to content

Commit

Permalink
add PriorityClass (#148)
Browse files Browse the repository at this point in the history
* add PriorityClass

* rename pc

* move to config

* extend retries

* add test for priorityClass in e2e-tests

* fix tests

* fix tests

* check for the right priorityClassName
  • Loading branch information
friedrichwilken authored Sep 26, 2023
1 parent fec61bc commit 4efe1e1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

resources:
- manager.yaml
- priority-class.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
Expand Down
7 changes: 7 additions & 0 deletions config/manager/priority-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: manager-priority-class
value: 2000000
globalDefault: false
description: "Scheduling priority of the NATS-Manager module. Must not be blocked by unschedulable user workloads."
1 change: 1 addition & 0 deletions e2e/common/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
FileStorageSize = "1Gi"
MemStorageSize = "1Gi"
True = "true"
PriorityClassName = "nats-manager-priority-class"
)

func NATSCR() *natsv1alpha1.NATS {
Expand Down
32 changes: 30 additions & 2 deletions e2e/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (

// Constants for retries.
const (
interval = 2 * time.Second
attempts = 60
interval = 3 * time.Second
attempts = 120
)

// clientSet is what is used to access K8s build-in resources like Pods, Namespaces and so on.
Expand Down Expand Up @@ -128,6 +128,34 @@ func Test_CR(t *testing.T) {
)
}

// Test_PriorityClass will get the PriorityClass name from the StatefulSet and checks if a PriorityClass with that
// name exists in the cluster.
func Test_PriorityClass(t *testing.T) {
ctx := context.TODO()

err := Retry(attempts, interval, func() error {
sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, metav1.GetOptions{})
if stsErr != nil {
return stsErr
}

pcName := sts.Spec.Template.Spec.PriorityClassName
// todo remove this check after the next release.
if len(pcName) < 1 {
return nil
}

if pcName != PriorityClassName {
return fmt.Errorf("PriorityClassName was expected to be %s but was %s", PriorityClassName, pcName)
}

_, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, pcName, metav1.GetOptions{})
return pcErr
})

require.NoError(t, err)
}

// Test_ConfigMap tests the ConfigMap that the NATS-Manger creates when we define a CR.
func Test_ConfigMap(t *testing.T) {
ctx := context.TODO()
Expand Down
2 changes: 2 additions & 0 deletions resources/nats/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ global:
# when replacing pods on nodes, or when scaling down.
podManagementPolicy: Parallel

priorityClassName: "nats-manager-priority-class"

####################################
# #
# Security Context Configuration #
Expand Down

0 comments on commit 4efe1e1

Please sign in to comment.