diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 602a048a..e8747a71 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -11,6 +11,7 @@ resources: - manager.yaml +- priority-class.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: diff --git a/config/manager/priority-class.yaml b/config/manager/priority-class.yaml new file mode 100644 index 00000000..a7d1b0e3 --- /dev/null +++ b/config/manager/priority-class.yaml @@ -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." diff --git a/e2e/common/fixtures/fixtures.go b/e2e/common/fixtures/fixtures.go index 87e62650..a3e77e64 100644 --- a/e2e/common/fixtures/fixtures.go +++ b/e2e/common/fixtures/fixtures.go @@ -23,6 +23,7 @@ const ( FileStorageSize = "1Gi" MemStorageSize = "1Gi" True = "true" + PriorityClassName = "nats-manager-priority-class" ) func NATSCR() *natsv1alpha1.NATS { diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 4daab0e0..bb15612d 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -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. @@ -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() diff --git a/resources/nats/values.yaml b/resources/nats/values.yaml index 2569e99c..41011b89 100644 --- a/resources/nats/values.yaml +++ b/resources/nats/values.yaml @@ -30,6 +30,8 @@ global: # when replacing pods on nodes, or when scaling down. podManagementPolicy: Parallel + priorityClassName: "nats-manager-priority-class" + #################################### # # # Security Context Configuration #