Skip to content

Commit

Permalink
Adding PriorityClassName in podOptions. (#152)
Browse files Browse the repository at this point in the history
Signed-off-by: Houston Putman <[email protected]>
  • Loading branch information
HoustonPutman authored and bsankara committed Nov 12, 2020
1 parent 5b114ff commit 4312384
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/solr.bloomberg.com_solrclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion controllers/controller_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ var (
Operator: "Exists",
},
}
extraVars = []corev1.EnvVar{
testPriorityClass = "p4"
extraVars = []corev1.EnvVar{
{
Name: "VAR_1",
Value: "VAL_1",
Expand Down
16 changes: 9 additions & 7 deletions controllers/solrcloud_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions controllers/solrprometheusexporter_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions controllers/util/prometheus_exporter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions controllers/util/solr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions controllers/util/zk_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions helm/solr-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4312384

Please sign in to comment.