From cd390d3d55d1c7ff47cea8303c6a47350f8bb872 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Mon, 25 Sep 2023 14:50:50 +0200 Subject: [PATCH 1/8] add PriorityClass --- resources/nats/templates/priority-class.yaml | 7 +++++++ resources/nats/values.yaml | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 resources/nats/templates/priority-class.yaml diff --git a/resources/nats/templates/priority-class.yaml b/resources/nats/templates/priority-class.yaml new file mode 100644 index 00000000..36b18e65 --- /dev/null +++ b/resources/nats/templates/priority-class.yaml @@ -0,0 +1,7 @@ +apiVersion: scheduling.k8s.io/v1 +kind: PriorityClass +metadata: + name: {{ .Values.global.priorityClassName }} +value: 2000000 +globalDefault: false +description: "Global (default) scheduling priority of Kyma components. Must not be blocked by unschedulable user workloads." diff --git a/resources/nats/values.yaml b/resources/nats/values.yaml index 2569e99c..e22a68cb 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: "eventing-priority-class" + #################################### # # # Security Context Configuration # From 3a022c3cdbab3e5f696268fdd152a9b431595e18 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Mon, 25 Sep 2023 15:28:27 +0200 Subject: [PATCH 2/8] rename pc --- resources/nats/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/nats/values.yaml b/resources/nats/values.yaml index e22a68cb..41011b89 100644 --- a/resources/nats/values.yaml +++ b/resources/nats/values.yaml @@ -30,7 +30,7 @@ global: # when replacing pods on nodes, or when scaling down. podManagementPolicy: Parallel - priorityClassName: "eventing-priority-class" + priorityClassName: "nats-manager-priority-class" #################################### # # From fff9ba49d3831a7f9a928b962bb9ade694ab5171 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 07:55:21 +0200 Subject: [PATCH 3/8] move to config --- config/manager/kustomization.yaml | 1 + config/manager/priority-class.yaml | 7 +++++++ resources/nats/templates/priority-class.yaml | 7 ------- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 config/manager/priority-class.yaml delete mode 100644 resources/nats/templates/priority-class.yaml 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/resources/nats/templates/priority-class.yaml b/resources/nats/templates/priority-class.yaml deleted file mode 100644 index 36b18e65..00000000 --- a/resources/nats/templates/priority-class.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: scheduling.k8s.io/v1 -kind: PriorityClass -metadata: - name: {{ .Values.global.priorityClassName }} -value: 2000000 -globalDefault: false -description: "Global (default) scheduling priority of Kyma components. Must not be blocked by unschedulable user workloads." From 676702c1ed1675288e76f06593141fc9ff5ec3c5 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 10:06:25 +0200 Subject: [PATCH 4/8] extend retries --- e2e/setup/setup_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 4daab0e0..2e727487 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. From be844eb839cb95da0adc293a96f4cd571a0475d2 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 10:58:43 +0200 Subject: [PATCH 5/8] add test for priorityClass in e2e-tests --- e2e/common/fixtures/fixtures.go | 1 + e2e/setup/setup_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) 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 2e727487..452e8e47 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -128,6 +128,27 @@ func Test_CR(t *testing.T) { ) } +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["priorityClassName"] + if pcName == "" { + return fmt.Errorf(".spec.priorityClassName of sts %s is not supposed to be empty", sts.Name) + } + + _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(PriorityClassName, 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() From 6962eddce17d3225e0f4ab5feb582d70a4a554b2 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 11:07:59 +0200 Subject: [PATCH 6/8] fix tests --- e2e/setup/setup_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 452e8e47..c3313a49 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -137,12 +137,12 @@ func Test_PriorityClass(t *testing.T) { return stsErr } - pcName := sts.Spec["priorityClassName"] - if pcName == "" { + pcName := sts.Spec.Template.Spec.PriorityClassName + if len(pcName) < 1 { return fmt.Errorf(".spec.priorityClassName of sts %s is not supposed to be empty", sts.Name) } - _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(PriorityClassName, metav1.GetOptions{}) + _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, PriorityClassName, metav1.GetOptions{}) return pcErr }) From aa20ca75ade0ffb1de76f98ee47a805c9b3f759e Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 11:22:50 +0200 Subject: [PATCH 7/8] fix tests --- e2e/common/fixtures/fixtures.go | 1 - e2e/setup/setup_test.go | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/e2e/common/fixtures/fixtures.go b/e2e/common/fixtures/fixtures.go index a3e77e64..87e62650 100644 --- a/e2e/common/fixtures/fixtures.go +++ b/e2e/common/fixtures/fixtures.go @@ -23,7 +23,6 @@ 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 c3313a49..cba26794 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -128,6 +128,8 @@ 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() @@ -139,10 +141,10 @@ func Test_PriorityClass(t *testing.T) { pcName := sts.Spec.Template.Spec.PriorityClassName if len(pcName) < 1 { - return fmt.Errorf(".spec.priorityClassName of sts %s is not supposed to be empty", sts.Name) + return nil } - _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, PriorityClassName, metav1.GetOptions{}) + _, pcErr := clientSet.SchedulingV1().PriorityClasses().Get(ctx, pcName, metav1.GetOptions{}) return pcErr }) From d8f11dbee8a44a4a308d49958cd011f2eb4a56f1 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 11:54:04 +0200 Subject: [PATCH 8/8] check for the right priorityClassName --- e2e/common/fixtures/fixtures.go | 1 + e2e/setup/setup_test.go | 5 +++++ 2 files changed, 6 insertions(+) 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 cba26794..bb15612d 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -140,10 +140,15 @@ func Test_PriorityClass(t *testing.T) { } 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 })