Skip to content

Commit

Permalink
Make segmentStoreResources.requests not a mandatory field
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 45770f9 commit 6783fe3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/pravega/v1beta1/pravega.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ func (s *PravegaSpec) withDefaults() (changed bool) {
}
}

if s.SegmentStoreResources.Requests == nil {
changed = true
s.SegmentStoreResources.Requests = map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: s.SegmentStoreResources.Limits[v1.ResourceCPU],
corev1.ResourceMemory: s.SegmentStoreResources.Limits[v1.ResourceMemory],
}
}

if s.SegmentStoreResources.Requests[v1.ResourceMemory] == (resource.Quantity{}) {
changed = true
s.SegmentStoreResources.Requests[v1.ResourceMemory] = s.SegmentStoreResources.Limits[v1.ResourceMemory]
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/pravega/v1beta1/pravegacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,10 @@ func (p *PravegaCluster) ValidateSegmentStoreMemorySettings() error {
}

if p.Spec.Pravega.SegmentStoreResources.Requests == nil {
return fmt.Errorf("spec.pravega.segmentStoreResources.requests cannot be empty")
p.Spec.Pravega.SegmentStoreResources.Requests = map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: {},
corev1.ResourceMemory: {},
}
}

totalMemoryLimitsQuantity := p.Spec.Pravega.SegmentStoreResources.Limits[corev1.ResourceMemory]
Expand Down
28 changes: 26 additions & 2 deletions pkg/apis/pravega/v1beta1/pravegacluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,35 @@ var _ = Describe("PravegaCluster Types Spec", func() {
})

Context("empty segmentStoreResources.requests object", func() {
var (
changed bool
)

BeforeEach(func() {
p.Spec.Pravega.Options["pravegaservice.cache.size.max"] = "1610612736"
p.Spec.Pravega.SegmentStoreJVMOptions = []string{"-Xmx1g", "-XX:MaxDirectMemorySize=2560m"}
p.Spec.Pravega.SegmentStoreResources = &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2000m"),
corev1.ResourceMemory: resource.MustParse("4Gi"),
},
}
changed = p.WithDefaults()
})

It("Should set memory and cpu requests to memory and cpu limits respectively", func() {
Ω(changed).Should(Equal(true))
})
})

Context("empty segmentStoreResources.requests object validation check", func() {
var (
err error
)

BeforeEach(func() {
p.Spec.Pravega.Options["pravegaservice.cache.size.max"] = "1610612736"
p.Spec.Pravega.SegmentStoreJVMOptions = []string{"-Xmx1g", "-XX:MaxDirectMemorySize=2560m"}
p.Spec.Pravega.SegmentStoreResources = &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2000m"),
Expand All @@ -556,8 +580,8 @@ var _ = Describe("PravegaCluster Types Spec", func() {
err = p.ValidateSegmentStoreMemorySettings()
})

It("Should return error", func() {
Ω(strings.ContainsAny(err.Error(), "spec.pravega.segmentStoreResources.requests cannot be empty")).Should(Equal(true))
It("should return nil", func() {
Ω(err).Should(BeNil())
})
})

Expand Down
17 changes: 13 additions & 4 deletions test/e2e/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ func testWebhook(t *testing.T) {
noSegmentStoreResourceRequests := pravega_e2eutil.NewDefaultCluster(namespace)
noSegmentStoreResourceRequests.WithDefaults()
noSegmentStoreResourceRequests.Spec.Pravega.SegmentStoreResources.Requests = nil
_, err = pravega_e2eutil.CreatePravegaCluster(t, f, ctx, noSegmentStoreResourceRequests)
g.Expect(err).To(HaveOccurred(), "Spec.Pravega.SegmentStoreResources.Requests cannot be empty")
g.Expect(err.Error()).To(ContainSubstring("spec.pravega.segmentStoreResources.requests cannot be empty"))
pravega, err := pravega_e2eutil.CreatePravegaCluster(t, f, ctx, noSegmentStoreResourceRequests)
g.Expect(err).NotTo(HaveOccurred())

err = pravega_e2eutil.DeletePravegaCluster(t, f, ctx, pravega)
g.Expect(err).NotTo(HaveOccurred())

err = pravega_e2eutil.WaitForPravegaClusterToTerminate(t, f, ctx, pravega)
g.Expect(err).NotTo(HaveOccurred())

//creating the setup for running the test
err = pravega_e2eutil.InitialSetup(t, f, ctx, namespace)
g.Expect(err).NotTo(HaveOccurred())

// Test webhook with no value for segment store memory limits
noMemoryLimits := pravega_e2eutil.NewClusterWithNoSegmentStoreMemoryLimits(namespace)
Expand Down Expand Up @@ -142,7 +151,7 @@ func testWebhook(t *testing.T) {
// Test webhook with a valid Pravega cluster version format
validVersion := pravega_e2eutil.NewClusterWithVersion(namespace, "0.6.0")
validVersion.WithDefaults()
pravega, err := pravega_e2eutil.CreatePravegaCluster(t, f, ctx, validVersion)
pravega, err = pravega_e2eutil.CreatePravegaCluster(t, f, ctx, validVersion)
g.Expect(err).NotTo(HaveOccurred())

podSize := 2
Expand Down

0 comments on commit 6783fe3

Please sign in to comment.