Skip to content

Commit

Permalink
fix(cspc): add schema for auxResource in poolConfig (#1567)
Browse files Browse the repository at this point in the history
Signed-off-by: shubham <[email protected]>
  • Loading branch information
shubham14bajpai authored and vishnuitta committed Dec 30, 2019
1 parent b779f95 commit a40a6ee
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
20 changes: 14 additions & 6 deletions cmd/cspc-operator/app/storagepool_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (pc *PoolConfig) GetPoolDeploySpec(cspi *apis.CStorPoolInstance) (*appsv1.D
WithPrivilegedSecurityContext(&privileged).
WithEnvsNew(getPoolMgmtEnv(cspi)).
WithEnvs(getPoolUIDAsEnv(pc.AlgorithmConfig.CSPC)).
WithResourcesByValue(getAuxResourceRequirement(cspi)).
WithResources(getAuxResourceRequirement(cspi)).
WithVolumeMountsNew(getPoolMgmtMounts()),
// For CStor-Pool container
container.NewBuilder().
Expand All @@ -149,8 +149,7 @@ func (pc *PoolConfig) GetPoolDeploySpec(cspi *apis.CStorPoolInstance) (*appsv1.D
container.NewBuilder().
WithImage(getMayaExporterImage()).
WithName(PoolExporterContainerName).
WithResourcesByValue(getAuxResourceRequirement(cspi)).
// TODO : Resource and Limit
// TODO: add default values for resources
WithImagePullPolicy(corev1.PullIfNotPresent).
WithPrivilegedSecurityContext(&privileged).
WithPortsNew(getContainerPort(9500)).
Expand Down Expand Up @@ -384,19 +383,28 @@ func getPoolLifeCycle() *corev1.Lifecycle {
return lc
}

// getResourceRequirementForCStorPool returns resource requirement.
// getResourceRequirementForCStorPool returns resource requirement for cstor pool container.
func getResourceRequirementForCStorPool(cspi *apis.CStorPoolInstance) *corev1.ResourceRequirements {
var resourceRequirements *corev1.ResourceRequirements
if cspi.Spec.PoolConfig.Resources == nil {
resourceRequirements = &corev1.ResourceRequirements{}
} else {
resourceRequirements = cspi.Spec.PoolConfig.Resources
}
// TODO: add default values for resources if both are nil
return resourceRequirements
}

func getAuxResourceRequirement(cspi *apis.CStorPoolInstance) corev1.ResourceRequirements {
return cspi.Spec.AuxResources
// getAuxResourceRequirement returns resource requirement for cstor pool side car containers.
func getAuxResourceRequirement(cspi *apis.CStorPoolInstance) *corev1.ResourceRequirements {
var auxResourceRequirements *corev1.ResourceRequirements
if cspi.Spec.PoolConfig.AuxResources == nil {
auxResourceRequirements = &corev1.ResourceRequirements{}
} else {
auxResourceRequirements = cspi.Spec.PoolConfig.AuxResources
}
// TODO: add default values for resources if both are nil
return auxResourceRequirements
}

// getPoolPodToleration returns pool pod tolerations.
Expand Down
5 changes: 3 additions & 2 deletions pkg/algorithm/nodeselect/v1alpha2/build_csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func (ac *Config) GetCSPSpec() (*apis.CStorPoolInstance, error) {
if poolSpec.PoolConfig.Resources == nil {
poolSpec.PoolConfig.Resources = ac.CSPC.Spec.DefaultResources
}

if poolSpec.PoolConfig.AuxResources == nil {
poolSpec.PoolConfig.AuxResources = ac.CSPC.Spec.DefaultAuxResources
}
if len(poolSpec.PoolConfig.Tolerations) == 0 {
poolSpec.PoolConfig.Tolerations = ac.CSPC.Spec.Tolerations
}
Expand All @@ -56,7 +58,6 @@ func (ac *Config) GetCSPSpec() (*apis.CStorPoolInstance, error) {
WithNamespace(ac.Namespace).
WithNodeSelectorByReference(poolSpec.NodeSelector).
WithNodeName(nodeName).
WithAuxResourceRequirement(ac.CSPC.Spec.AuxResources).
WithPoolConfig(&poolSpec.PoolConfig).
WithRaidGroups(poolSpec.RaidGroups).
WithCSPCOwnerReference(ac.CSPC).
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/openebs.io/v1alpha1/cstor_pool_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -48,9 +47,6 @@ type CStorPoolInstanceSpec struct {
// PoolConfig is the default pool config that applies to the
// pool on node.
PoolConfig PoolConfig `json:"poolConfig"`
// AuxResources are the compute resources required by the cstor-pool pod
// side car containers.
AuxResources v1.ResourceRequirements `json:"auxResources"`
// RaidGroups is the group containing block devices
RaidGroups []RaidGroup `json:"raidGroup"`
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/apis/openebs.io/v1alpha1/cstorpool_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
"k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -72,14 +72,14 @@ type CStorPoolClusterSpec struct {
// container.
// If the resources at PoolConfig is not specified, this is written
// to CSPI PoolConfig.
DefaultResources *v1.ResourceRequirements `json:"resources"`
DefaultResources *corev1.ResourceRequirements `json:"resources"`
// AuxResources are the compute resources required by the cstor-pool pod
// side car containers.
AuxResources v1.ResourceRequirements `json:"auxResources"`
DefaultAuxResources *corev1.ResourceRequirements `json:"auxResources"`
// Tolerations, if specified, are the pool pod's tolerations
// If tolerations at PoolConfig is empty, this is written to
// CSPI PoolConfig.
Tolerations []v1.Toleration `json:"tolerations"`
Tolerations []corev1.Toleration `json:"tolerations"`

// DefaultPriorityClassName if specified applies to all the pool pods
// in the pool spec if the priorityClass at the pool level is
Expand Down Expand Up @@ -121,10 +121,12 @@ type PoolConfig struct {
Compression string `json:"compression"`
// Resources are the compute resources required by the cstor-pool
// container.
Resources *v1.ResourceRequirements `json:"resources"`

Resources *corev1.ResourceRequirements `json:"resources"`
// AuxResources are the compute resources required by the cstor-pool pod
// side car containers.
AuxResources *corev1.ResourceRequirements `json:"auxResources"`
// Tolerations, if specified, the pool pod's tolerations.
Tolerations []v1.Toleration `json:"tolerations"`
Tolerations []corev1.Toleration `json:"tolerations"`

// PriorityClassName if specified applies to this pool pod
// If left empty, DefaultPriorityClassName is applied.
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/openebs.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions pkg/cstor/poolinstance/v1alpha3/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha3
import (
apis "github.com/openebs/maya/pkg/apis/openebs.io/v1alpha1"
errors "github.com/openebs/maya/pkg/errors/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -194,12 +193,6 @@ func (b *Builder) WithNodeName(nodeName string) *Builder {
return b
}

// WithAuxResourceRequirement sets the AuxResources field of CSPI with the provided argument.
func (b *Builder) WithAuxResourceRequirement(resource corev1.ResourceRequirements) *Builder {
b.CSPI.Object.Spec.AuxResources = resource
return b
}

// WithPoolConfig sets the pool config field of the CSPI with the provided config.
func (b *Builder) WithPoolConfig(poolConfig *apis.PoolConfig) *Builder {
if poolConfig == nil {
Expand Down

0 comments on commit a40a6ee

Please sign in to comment.