From f61ee991844ddc950ffea0882091a4d5b074f9e6 Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Date: Tue, 24 Dec 2019 13:13:05 +0530 Subject: [PATCH] feat(cspc): add support to pass priority class to the pool pods Signed-off-by: Ashutosh Kumar --- cmd/cspc-operator/app/storagepool_create.go | 5 +++++ pkg/algorithm/nodeselect/v1alpha2/build_csp.go | 4 ++++ pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go | 11 +++++++++++ .../podtemplatespec/v1alpha1/podtemplatespec.go | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/cmd/cspc-operator/app/storagepool_create.go b/cmd/cspc-operator/app/storagepool_create.go index db32ef9fbf..6b5142e659 100644 --- a/cmd/cspc-operator/app/storagepool_create.go +++ b/cmd/cspc-operator/app/storagepool_create.go @@ -116,6 +116,7 @@ func (pc *PoolConfig) GetPoolDeploySpec(cspi *apis.CStorPoolInstance) (*appsv1.D WithPodTemplateSpecBuilder( pts.NewBuilder(). WithLabelsNew(getPodLabels(cspi)). + WithPriorityClassName(getPriorityClass(cspi)). WithNodeSelector(cspi.Spec.NodeSelector). WithAnnotationsNew(getPodAnnotations()). WithServiceAccountName(OpenEBSServiceAccount). @@ -408,3 +409,7 @@ func getPoolPodToleration(cspi *apis.CStorPoolInstance) []corev1.Toleration { } return tolerations } + +func getPriorityClass(cspi *apis.CStorPoolInstance) string { + return cspi.Spec.PoolConfig.PriorityClassName +} diff --git a/pkg/algorithm/nodeselect/v1alpha2/build_csp.go b/pkg/algorithm/nodeselect/v1alpha2/build_csp.go index 8f88d2fdba..87c37058ed 100644 --- a/pkg/algorithm/nodeselect/v1alpha2/build_csp.go +++ b/pkg/algorithm/nodeselect/v1alpha2/build_csp.go @@ -46,6 +46,10 @@ func (ac *Config) GetCSPSpec() (*apis.CStorPoolInstance, error) { poolSpec.PoolConfig.Tolerations = ac.CSPC.Spec.Tolerations } + if poolSpec.PoolConfig.PriorityClassName == "" { + poolSpec.PoolConfig.PriorityClassName = ac.CSPC.Spec.DefaultPriorityClassName + } + csplabels := ac.buildLabelsForCSPI(nodeName) cspObj, err := apiscsp.NewBuilder(). WithName(ac.CSPC.Name + "-" + rand.String(4)). diff --git a/pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go b/pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go index 007b1a3fff..96c3893e81 100644 --- a/pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go +++ b/pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go @@ -80,6 +80,11 @@ type CStorPoolClusterSpec struct { // If tolerations at PoolConfig is empty, this is written to // CSPI PoolConfig. Tolerations []v1.Toleration `json:"tolerations"` + + // DefaultPriorityClassName if specified applies to all the pool pods + // in the pool spec if the priorityClass at the pool level is + // not specified. + DefaultPriorityClassName string `json:"priorityClassName"` } //PoolSpec is the spec for pool on node where it should be created. @@ -120,6 +125,12 @@ type PoolConfig struct { // Tolerations, if specified, the pool pod's tolerations. Tolerations []v1.Toleration `json:"tolerations"` + + // PriorityClassName if specified applies to this pool pod + // If left empty, DefaultPriorityClassName is applied. + // (See CStorPoolClusterSpec.DefaultPriorityClassName) + // If both are empty, not priority class is applied. + PriorityClassName string `json:"priorityClassName"` } // RaidGroup contains the details of a raid group for the pool diff --git a/pkg/kubernetes/podtemplatespec/v1alpha1/podtemplatespec.go b/pkg/kubernetes/podtemplatespec/v1alpha1/podtemplatespec.go index a48a003244..d24c93fe06 100644 --- a/pkg/kubernetes/podtemplatespec/v1alpha1/podtemplatespec.go +++ b/pkg/kubernetes/podtemplatespec/v1alpha1/podtemplatespec.go @@ -184,6 +184,12 @@ func (b *Builder) WithNodeSelector(nodeselectors map[string]string) *Builder { return b } +// WithPriorityClassName sets the PriorityClassName field of podtemplatespec +func (b *Builder) WithPriorityClassName(prorityClassName string) *Builder { + b.podtemplatespec.Object.Spec.PriorityClassName = prorityClassName + return b +} + // WithNodeSelectorNew resets the nodeselector field of podtemplatespec // with provided arguments func (b *Builder) WithNodeSelectorNew(nodeselectors map[string]string) *Builder {