From 2c1954d79ea27c7f7bb8055c063fa1b61f7a5820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Sevilla?= Date: Thu, 12 Jan 2023 11:35:14 +0100 Subject: [PATCH] Fix nodeSelector expression (#234) Signed-off-by: Raul Sevilla --- .../ocp-config/node-density-cni/curl-deployment.yml | 12 ++++++++++-- .../node-density-cni/webserver-deployment.yml | 12 ++++++++++-- .../ocp-config/node-density-heavy/app-deployment.yml | 12 ++++++++++-- .../node-density-heavy/postgres-deployment.yml | 12 ++++++++++-- cmd/kube-burner/ocp-config/node-density/pod.yml | 12 ++++++++++-- pkg/discovery/discovery.go | 6 +++--- pkg/discovery/types.go | 9 +++++---- 7 files changed, 58 insertions(+), 17 deletions(-) diff --git a/cmd/kube-burner/ocp-config/node-density-cni/curl-deployment.yml b/cmd/kube-burner/ocp-config/node-density-cni/curl-deployment.yml index a1ab8baf8..ec33f2a1c 100644 --- a/cmd/kube-burner/ocp-config/node-density-cni/curl-deployment.yml +++ b/cmd/kube-burner/ocp-config/node-density-cni/curl-deployment.yml @@ -8,8 +8,16 @@ spec: labels: name: curl-{{.Replica}}-{{.Iteration}} spec: - nodeSelector: - node-role.kubernetes.io/worker: "" + affinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: Exists + - key: node-role.kubernetes.io/infra + operator: DoesNotExist + - key: node-role.kubernetes.io/workload + operator: DoesNotExist containers: - name: curlapp image: quay.io/cloud-bulldozer/curl:latest diff --git a/cmd/kube-burner/ocp-config/node-density-cni/webserver-deployment.yml b/cmd/kube-burner/ocp-config/node-density-cni/webserver-deployment.yml index 20d2dd77a..21800f26b 100644 --- a/cmd/kube-burner/ocp-config/node-density-cni/webserver-deployment.yml +++ b/cmd/kube-burner/ocp-config/node-density-cni/webserver-deployment.yml @@ -8,8 +8,16 @@ spec: labels: name: webserver-{{.Replica}}-{{.Iteration}} spec: - nodeSelector: - node-role.kubernetes.io/worker: "" + affinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: Exists + - key: node-role.kubernetes.io/infra + operator: DoesNotExist + - key: node-role.kubernetes.io/workload + operator: DoesNotExist containers: - name: webserver image: quay.io/cloud-bulldozer/sampleapp:latest diff --git a/cmd/kube-burner/ocp-config/node-density-heavy/app-deployment.yml b/cmd/kube-burner/ocp-config/node-density-heavy/app-deployment.yml index ef28c0fb0..bda1da9fd 100644 --- a/cmd/kube-burner/ocp-config/node-density-heavy/app-deployment.yml +++ b/cmd/kube-burner/ocp-config/node-density-heavy/app-deployment.yml @@ -8,8 +8,16 @@ spec: labels: name: perfapp-{{.Replica}}-{{.Iteration}} spec: - nodeSelector: - node-role.kubernetes.io/worker: "" + affinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: Exists + - key: node-role.kubernetes.io/infra + operator: DoesNotExist + - key: node-role.kubernetes.io/workload + operator: DoesNotExist containers: - name: perfapp image: quay.io/cloud-bulldozer/perfapp:latest diff --git a/cmd/kube-burner/ocp-config/node-density-heavy/postgres-deployment.yml b/cmd/kube-burner/ocp-config/node-density-heavy/postgres-deployment.yml index 51955a141..8c1217554 100644 --- a/cmd/kube-burner/ocp-config/node-density-heavy/postgres-deployment.yml +++ b/cmd/kube-burner/ocp-config/node-density-heavy/postgres-deployment.yml @@ -8,8 +8,16 @@ spec: labels: name: postgres-{{.Replica}}-{{.Iteration}} spec: - nodeSelector: - node-role.kubernetes.io/worker: "" + affinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: Exists + - key: node-role.kubernetes.io/infra + operator: DoesNotExist + - key: node-role.kubernetes.io/workload + operator: DoesNotExist containers: - name: postgresql image: registry.redhat.io/rhel8/postgresql-10@sha256:4b912c80085b88a03309aeb7907efcc29dd3342fa3952b6ea067afb1914bfe53 diff --git a/cmd/kube-burner/ocp-config/node-density/pod.yml b/cmd/kube-burner/ocp-config/node-density/pod.yml index 3331f0ed2..de1c1dc29 100644 --- a/cmd/kube-burner/ocp-config/node-density/pod.yml +++ b/cmd/kube-burner/ocp-config/node-density/pod.yml @@ -5,8 +5,16 @@ metadata: app: node-density-{{.Iteration}} name: {{.JobName}}-{{.Iteration}} spec: - nodeSelector: - node-role.kubernetes.io/worker: "" + affinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: Exists + - key: node-role.kubernetes.io/infra + operator: DoesNotExist + - key: node-role.kubernetes.io/workload + operator: DoesNotExist tolerations: - key: os value: Windows diff --git a/pkg/discovery/discovery.go b/pkg/discovery/discovery.go index 53f91fded..78efceac6 100644 --- a/pkg/discovery/discovery.go +++ b/pkg/discovery/discovery.go @@ -113,15 +113,15 @@ func getBearerToken(clientset *kubernetes.Clientset) (string, error) { // GetWorkerNodeCount returns the number of worker nodes func (da *Agent) GetWorkerNodeCount() (int, error) { - nodeList, err := da.clientSet.CoreV1().Nodes().List(context.TODO(), v1.ListOptions{LabelSelector: "node-role.kubernetes.io/worker="}) - log.Debug("Node count: ", len(nodeList.Items)) + nodeList, err := da.clientSet.CoreV1().Nodes().List(context.TODO(), v1.ListOptions{LabelSelector: workerNodeSelector}) + log.Infof("Listed nodes after using selector %s: %d", workerNodeSelector, len(nodeList.Items)) return len(nodeList.Items), err } // GetCurrentPodCount returns the number of current running pods across all worker nodes func (da *Agent) GetCurrentPodCount() (int, error) { var podCount int - nodeList, err := da.clientSet.CoreV1().Nodes().List(context.TODO(), v1.ListOptions{LabelSelector: "node-role.kubernetes.io/worker="}) + nodeList, err := da.clientSet.CoreV1().Nodes().List(context.TODO(), v1.ListOptions{LabelSelector: workerNodeSelector}) if err != nil { return podCount, err } diff --git a/pkg/discovery/types.go b/pkg/discovery/types.go index dacfcc5a3..1fabc1bfc 100644 --- a/pkg/discovery/types.go +++ b/pkg/discovery/types.go @@ -45,8 +45,9 @@ type NodeInfo struct { } const ( - routeGroup = "route.openshift.io" - routeVersion = "v1" - routeResource = "routes" - completedUpdate = "Completed" + routeGroup = "route.openshift.io" + routeVersion = "v1" + routeResource = "routes" + completedUpdate = "Completed" + workerNodeSelector = "node-role.kubernetes.io/worker=,node-role.kubernetes.io/infra!=,node-role.kubernetes.io/workload!=" )