Skip to content

Commit

Permalink
Add Check for CPU limits
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Gupta <Nishant_Gupta3@dell.com>
  • Loading branch information
nishant-yt committed Nov 24, 2021
1 parent f57fe1b commit 45770f9
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 56 deletions.
7 changes: 1 addition & 6 deletions pkg/apis/pravega/v1beta1/pravega.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,9 @@ func (s *PravegaSpec) withDefaults() (changed bool) {
s.SegmentStoreResources.Requests[v1.ResourceMemory] = s.SegmentStoreResources.Limits[v1.ResourceMemory]
}

if s.SegmentStoreResources.Limits[v1.ResourceCPU] == (resource.Quantity{}) {
changed = true
s.SegmentStoreResources.Limits[v1.ResourceCPU] = resource.MustParse(DefaultSegmentStoreLimitCPU)
}

if s.SegmentStoreResources.Requests[v1.ResourceCPU] == (resource.Quantity{}) {
changed = true
s.SegmentStoreResources.Requests[v1.ResourceCPU] = resource.MustParse(DefaultSegmentStoreRequestCPU)
s.SegmentStoreResources.Requests[v1.ResourceCPU] = s.SegmentStoreResources.Limits[v1.ResourceCPU]
}

if s.SegmentStoreSecret == nil {
Expand Down
30 changes: 26 additions & 4 deletions pkg/apis/pravega/v1beta1/pravegacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,21 +1213,43 @@ func (p *PravegaCluster) validateConfigMap() error {
// JVM Direct memory > Segment Store read cache size (pravegaservice.cache.size.max).
func (p *PravegaCluster) ValidateSegmentStoreMemorySettings() error {
if p.Spec.Pravega.SegmentStoreResources == nil {
return fmt.Errorf("Missing required value for field spec.pravega.segmentStoreResources.limits.memory")
return fmt.Errorf("spec.pravega.segmentStoreResources cannot be empty")
}

if p.Spec.Pravega.SegmentStoreResources.Limits == nil {
return fmt.Errorf("spec.pravega.segmentStoreResources.limits cannot be empty")
}

if p.Spec.Pravega.SegmentStoreResources.Requests == nil {
return fmt.Errorf("spec.pravega.segmentStoreResources.requests cannot be empty")
}

totalMemoryLimitsQuantity := p.Spec.Pravega.SegmentStoreResources.Limits[corev1.ResourceMemory]
totalMemoryRequestsQuantity := p.Spec.Pravega.SegmentStoreResources.Requests[corev1.ResourceMemory]
if (resource.Quantity{}) == totalMemoryLimitsQuantity {
totalCpuLimitsQuantity := p.Spec.Pravega.SegmentStoreResources.Limits[corev1.ResourceCPU]
totalCpuRequestsQuantity := p.Spec.Pravega.SegmentStoreResources.Requests[corev1.ResourceCPU]

if totalMemoryLimitsQuantity == (resource.Quantity{}) {
return fmt.Errorf("Missing required value for field spec.pravega.segmentStoreResources.limits.memory")
}

if totalCpuLimitsQuantity == (resource.Quantity{}) {
return fmt.Errorf("Missing required value for field spec.pravega.segmentStoreResources.limits.cpu")
}

totalMemoryLimits := totalMemoryLimitsQuantity.Value()
totalMemoryRequests := totalMemoryRequestsQuantity.Value()
totalCpuLimits := totalCpuLimitsQuantity.Value()
totalCpuRequests := totalCpuRequestsQuantity.Value()

if totalMemoryLimits < totalMemoryRequests {
return fmt.Errorf("spec.pravega.segmentStoreResources.requests.memory value must be less than or equal to spec.pravega.segmentStoreResources.limits.memory")
}

if totalCpuLimits < totalCpuRequests {
return fmt.Errorf("spec.pravega.segmentStoreResources.requests.cpu value must be less than or equal to spec.pravega.segmentStoreResources.limits.cpu")
}

cacheSizeString := p.Spec.Pravega.Options["pravegaservice.cache.size.max"]
if cacheSizeString == "" {
return fmt.Errorf("Missing required value for option pravegaservice.cache.size.max")
Expand Down Expand Up @@ -1261,11 +1283,11 @@ func (p *PravegaCluster) ValidateSegmentStoreMemorySettings() error {
cacheSize := cacheSizeQuantity.Value()

if totalMemoryLimits <= (maxDirectMemorySize + xmx) {
return fmt.Errorf("MaxDirectMemorySize(%v B) along with JVM Xmx value(%v B) is greater than or equal to the total available memory(%v B)!", maxDirectMemorySize, xmx, totalMemoryLimits)
return fmt.Errorf("MaxDirectMemorySize(%v B) along with JVM Xmx value(%v B) should be less than the total available memory(%v B)!", maxDirectMemorySize, xmx, totalMemoryLimits)
}

if maxDirectMemorySize <= cacheSize {
return fmt.Errorf("Cache size(%v B) configured is greater than or equal to the JVM MaxDirectMemorySize(%v B) value", cacheSize, maxDirectMemorySize)
return fmt.Errorf("Cache size(%v B) configured should be less than the JVM MaxDirectMemorySize(%v B) value", cacheSize, maxDirectMemorySize)
}

return nil
Expand Down
Loading

0 comments on commit 45770f9

Please sign in to comment.