From 43123845a79b0e1db74ed3bc70cd0b1942497665 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Mon, 12 Oct 2020 18:42:28 -0400 Subject: [PATCH] Adding PriorityClassName in podOptions. (#152) Signed-off-by: Houston Putman --- api/v1beta1/common_types.go | 4 ++++ .../crd/bases/solr.bloomberg.com_solrclouds.yaml | 3 +++ ...lr.bloomberg.com_solrprometheusexporters.yaml | 3 +++ controllers/controller_utils_test.go | 3 ++- controllers/solrcloud_controller_test.go | 16 +++++++++------- .../solrprometheusexporter_controller_test.go | 12 +++++++----- controllers/util/prometheus_exporter_util.go | 4 ++++ controllers/util/solr_util.go | 9 +++++++++ controllers/util/zk_util.go | 6 ++++++ helm/solr-operator/crds/crds.yaml | 6 ++++++ 10 files changed, 53 insertions(+), 13 deletions(-) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 3ab8543d..81c88a58 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -95,6 +95,10 @@ type PodOptions struct { // Startup probe parameters // +optional StartupProbe *corev1.Probe `json:"startupProbe,omitempty"` + + // PriorityClassName for the pod + // +optional + PriorityClassName string `json:"priorityClassName,omitempty"` } // ServiceOptions defines custom options for services diff --git a/config/crd/bases/solr.bloomberg.com_solrclouds.yaml b/config/crd/bases/solr.bloomberg.com_solrclouds.yaml index dcfb8d1c..8a861a58 100644 --- a/config/crd/bases/solr.bloomberg.com_solrclouds.yaml +++ b/config/crd/bases/solr.bloomberg.com_solrclouds.yaml @@ -1653,6 +1653,9 @@ spec: type: string type: object type: object + priorityClassName: + description: PriorityClassName for the pod + type: string readinessProbe: description: Readiness probe parameters properties: diff --git a/config/crd/bases/solr.bloomberg.com_solrprometheusexporters.yaml b/config/crd/bases/solr.bloomberg.com_solrprometheusexporters.yaml index ede68468..e7e4adda 100644 --- a/config/crd/bases/solr.bloomberg.com_solrprometheusexporters.yaml +++ b/config/crd/bases/solr.bloomberg.com_solrprometheusexporters.yaml @@ -686,6 +686,9 @@ spec: type: string type: object type: object + priorityClassName: + description: PriorityClassName for the pod + type: string readinessProbe: description: Readiness probe parameters properties: diff --git a/controllers/controller_utils_test.go b/controllers/controller_utils_test.go index 85887cd3..80e6d34c 100644 --- a/controllers/controller_utils_test.go +++ b/controllers/controller_utils_test.go @@ -385,7 +385,8 @@ var ( Operator: "Exists", }, } - extraVars = []corev1.EnvVar{ + testPriorityClass = "p4" + extraVars = []corev1.EnvVar{ { Name: "VAR_1", Value: "VAL_1", diff --git a/controllers/solrcloud_controller_test.go b/controllers/solrcloud_controller_test.go index fcb57090..830cefaf 100644 --- a/controllers/solrcloud_controller_test.go +++ b/controllers/solrcloud_controller_test.go @@ -167,13 +167,14 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) { SolrGCTune: "gc Options", CustomSolrKubeOptions: solr.CustomSolrKubeOptions{ PodOptions: &solr.PodOptions{ - Annotations: testPodAnnotations, - Labels: testPodLabels, - Tolerations: testTolerations, - NodeSelector: testNodeSelectors, - LivenessProbe: testProbeLivenessNonDefaults, - ReadinessProbe: testProbeReadinessNonDefaults, - StartupProbe: testProbeStartup, + Annotations: testPodAnnotations, + Labels: testPodLabels, + Tolerations: testTolerations, + NodeSelector: testNodeSelectors, + LivenessProbe: testProbeLivenessNonDefaults, + ReadinessProbe: testProbeReadinessNonDefaults, + StartupProbe: testProbeStartup, + PriorityClassName: testPriorityClass, }, StatefulSetOptions: &solr.StatefulSetOptions{ Annotations: testSSAnnotations, @@ -257,6 +258,7 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) { testPodProbe(t, testProbeReadinessNonDefaults, statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe) assert.ElementsMatch(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") testPodTolerations(t, testTolerations, statefulSet.Spec.Template.Spec.Tolerations) + assert.EqualValues(t, testPriorityClass, statefulSet.Spec.Template.Spec.PriorityClassName, "Incorrect Priority class name for Pod Spec") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Selector.MatchLabels) diff --git a/controllers/solrprometheusexporter_controller_test.go b/controllers/solrprometheusexporter_controller_test.go index 9cc5d9dc..a0da8e03 100644 --- a/controllers/solrprometheusexporter_controller_test.go +++ b/controllers/solrprometheusexporter_controller_test.go @@ -123,11 +123,12 @@ func TestMetricsReconcileWithExporterConfig(t *testing.T) { Config: testExporterConfig, CustomKubeOptions: solr.CustomExporterKubeOptions{ PodOptions: &solr.PodOptions{ - Annotations: testPodAnnotations, - Labels: testPodLabels, - Volumes: extraVolumes, - Tolerations: testTolerationsPromExporter, - NodeSelector: testNodeSelectors, + Annotations: testPodAnnotations, + Labels: testPodLabels, + Volumes: extraVolumes, + Tolerations: testTolerationsPromExporter, + NodeSelector: testNodeSelectors, + PriorityClassName: testPriorityClass, }, DeploymentOptions: &solr.DeploymentOptions{ Annotations: testDeploymentAnnotations, @@ -189,6 +190,7 @@ func TestMetricsReconcileWithExporterConfig(t *testing.T) { testMapsEqual(t, "deployment annotations", testDeploymentAnnotations, deployment.Annotations) testMapsEqual(t, "pod labels", util.MergeLabelsOrAnnotations(expectedDeploymentLabels, testPodLabels), deployment.Spec.Template.ObjectMeta.Labels) testMapsEqual(t, "pod annotations", testPodAnnotations, deployment.Spec.Template.ObjectMeta.Annotations) + assert.EqualValues(t, testPriorityClass, deployment.Spec.Template.Spec.PriorityClassName, "Incorrect Priority class name for Pod Spec") // Test tolerations and node selectors testMapsEqual(t, "pod node selectors", testNodeSelectors, deployment.Spec.Template.Spec.NodeSelector) diff --git a/controllers/util/prometheus_exporter_util.go b/controllers/util/prometheus_exporter_util.go index e34b7dc6..94a303ac 100644 --- a/controllers/util/prometheus_exporter_util.go +++ b/controllers/util/prometheus_exporter_util.go @@ -224,6 +224,10 @@ func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrP if customPodOptions.NodeSelector != nil { deployment.Spec.Template.Spec.NodeSelector = customPodOptions.NodeSelector } + + if customPodOptions.PriorityClassName != "" { + deployment.Spec.Template.Spec.PriorityClassName = customPodOptions.PriorityClassName + } } return deployment diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index 177bdfbb..4bc07179 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -406,6 +406,9 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl stateful.Spec.Template.Spec.Containers[0].StartupProbe = fillProbe(*customPodOptions.StartupProbe, DefaultStartupProbeInitialDelaySeconds, DefaultStartupProbeTimeoutSeconds, DefaultStartupProbeSuccessThreshold, DefaultStartupProbeFailureThreshold, DefaultStartupProbePeriodSeconds, &defaultHandler) } + if customPodOptions.PriorityClassName != "" { + stateful.Spec.Template.Spec.PriorityClassName = customPodOptions.PriorityClassName + } } return stateful @@ -509,6 +512,12 @@ func CopyStatefulSetFields(from, to *appsv1.StatefulSet) bool { to.Spec.Template.Spec.NodeSelector = from.Spec.Template.Spec.NodeSelector } + if !DeepEqualWithNils(to.Spec.Template.Spec.PriorityClassName, from.Spec.Template.Spec.PriorityClassName) { + requireUpdate = true + log.Info("Update required because:", "Spec.Template.Spec.PriorityClassName changed from", to.Spec.Template.Spec.PriorityClassName, "To:", from.Spec.Template.Spec.PriorityClassName) + to.Spec.Template.Spec.PriorityClassName = from.Spec.Template.Spec.PriorityClassName + } + if !DeepEqualWithNils(to.Spec.Template.Spec.Tolerations, from.Spec.Template.Spec.Tolerations) { requireUpdate = true log.Info("Update required because:", "Spec.Template.Spec.Tolerations changed from", to.Spec.Template.Spec.Tolerations, "To:", from.Spec.Template.Spec.Tolerations) diff --git a/controllers/util/zk_util.go b/controllers/util/zk_util.go index feda4143..27f13974 100644 --- a/controllers/util/zk_util.go +++ b/controllers/util/zk_util.go @@ -299,5 +299,11 @@ func CopyDeploymentFields(from, to *appsv1.Deployment) bool { to.Spec.Template.Spec.NodeSelector = from.Spec.Template.Spec.NodeSelector } + if !DeepEqualWithNils(to.Spec.Template.Spec.PriorityClassName, from.Spec.Template.Spec.PriorityClassName) { + requireUpdate = true + log.Info("Update required because:", "Spec.Template.Spec.PriorityClassName changed from", to.Spec.Template.Spec.PriorityClassName, "To:", from.Spec.Template.Spec.PriorityClassName) + to.Spec.Template.Spec.PriorityClassName = from.Spec.Template.Spec.PriorityClassName + } + return requireUpdate } diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index 106e0487..7a4b5680 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -2780,6 +2780,9 @@ spec: type: string type: object type: object + priorityClassName: + description: PriorityClassName for the pod + type: string readinessProbe: description: Readiness probe parameters properties: @@ -6548,6 +6551,9 @@ spec: type: string type: object type: object + priorityClassName: + description: PriorityClassName for the pod + type: string readinessProbe: description: Readiness probe parameters properties: