Skip to content

Commit

Permalink
Refactoring corev1.VolumeResourceRequirements
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed Jan 12, 2024
1 parent 5156472 commit abb8be6
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 42 deletions.
16 changes: 8 additions & 8 deletions pkg/apis/elasticsearch/v1beta1/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("10Gi"),
},
Expand Down Expand Up @@ -382,7 +382,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand Down Expand Up @@ -412,7 +412,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand All @@ -424,7 +424,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data1",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand Down Expand Up @@ -454,7 +454,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data1",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand Down Expand Up @@ -484,7 +484,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand All @@ -501,7 +501,7 @@ func Test_pvcModified(t *testing.T) {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("10Gi"),
},
Expand Down Expand Up @@ -645,7 +645,7 @@ func getEsCluster() *Elasticsearch {
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5Gi"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (nsb *nodeSetBuilder) build() esv1.NodeSet {
Name: volume.ElasticsearchDataVolumeName,
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: *nsb.storageRequest,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/elasticsearch/driver/desired_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (esb esBuilder) toExpectedResources() nodespec.ResourcesList {
{
ObjectMeta: metav1.ObjectMeta{Name: "elasticsearch-data"},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: fns.claimedStorage.DeepCopy(),
},
Expand Down Expand Up @@ -673,7 +673,7 @@ func (esb esBuilder) toResources() []crclient.Object {
Generation: 1,
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{corev1.ResourceStorage: nodeSet.claimedStorage.DeepCopy()},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/elasticsearch/driver/pvc_expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ var (
ObjectMeta: metav1.ObjectMeta{Name: "sample-claim"},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String(sampleStorageClass.Name),
Resources: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
Resources: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}}}}
sampleClaim2 = corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Name: "sample-claim-2"},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String(sampleStorageClass.Name),
Resources: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
Resources: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}}}}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/driver/upscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestHandleUpscaleAndSpecChanges_PVCResize(t *testing.T) {
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{
{ObjectMeta: metav1.ObjectMeta{Name: "elasticsearch-data"},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/nodespec/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Test_BuildVolumes_DataVolumeMountPath(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("42Ti"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ var (
ObjectMeta: metav1.ObjectMeta{Name: "sample-claim"},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String(sampleStorageClass.Name),
Resources: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
Resources: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}}}}
sampleClaim2 = corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Name: "sample-claim-2"},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String(sampleStorageClass.Name),
Resources: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
Resources: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}}}}
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/volume/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: DefaultPersistentVolumeSize,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/logstash/volume/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: DefaultPersistentVolumeSize,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/logstash/volume/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_BuildVolumesAndMounts(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("42Ti"),
},
Expand All @@ -138,7 +138,7 @@ func Test_BuildVolumesAndMounts(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("42Ti"),
},
Expand All @@ -161,7 +161,7 @@ func Test_BuildVolumesAndMounts(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("42Ti"),
},
Expand All @@ -176,7 +176,7 @@ func Test_BuildVolumesAndMounts(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("42Ti"),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/k8s/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type StorageComparison struct {

// CompareStorageRequests compares storage requests in the given resource requirements.
// It returns a zero-ed StorageComparison in case one of the requests is zero (value not set: comparison not possible).
func CompareStorageRequests(initial corev1.ResourceRequirements, updated corev1.ResourceRequirements) StorageComparison {
func CompareStorageRequests(initial corev1.VolumeResourceRequirements, updated corev1.VolumeResourceRequirements) StorageComparison {
initialSize := initial.Requests.Storage()
updatedSize := updated.Requests.Storage()
if initialSize.IsZero() || updatedSize.IsZero() {
Expand Down
28 changes: 14 additions & 14 deletions pkg/utils/k8s/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func TestGetServiceIPAddresses(t *testing.T) {

func TestCompareStorageRequests(t *testing.T) {
type args struct {
initial corev1.ResourceRequirements
updated corev1.ResourceRequirements
initial corev1.VolumeResourceRequirements
updated corev1.VolumeResourceRequirements
}
tests := []struct {
name string
Expand All @@ -161,10 +161,10 @@ func TestCompareStorageRequests(t *testing.T) {
{
name: "same size",
args: args{
initial: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
initial: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
updated: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
updated: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
},
Expand All @@ -173,10 +173,10 @@ func TestCompareStorageRequests(t *testing.T) {
{
name: "storage increase",
args: args{
initial: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
initial: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
updated: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
updated: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("2Gi"),
}},
},
Expand All @@ -185,10 +185,10 @@ func TestCompareStorageRequests(t *testing.T) {
{
name: "storage decrease",
args: args{
initial: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
initial: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("2Gi"),
}},
updated: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
updated: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
},
Expand All @@ -197,16 +197,16 @@ func TestCompareStorageRequests(t *testing.T) {
{
name: "no storage specified in both",
args: args{
initial: corev1.ResourceRequirements{},
updated: corev1.ResourceRequirements{},
initial: corev1.VolumeResourceRequirements{},
updated: corev1.VolumeResourceRequirements{},
},
want: StorageComparison{},
},
{
name: "no initial storage specified: not an increase",
args: args{
initial: corev1.ResourceRequirements{},
updated: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
initial: corev1.VolumeResourceRequirements{},
updated: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
},
Expand All @@ -215,10 +215,10 @@ func TestCompareStorageRequests(t *testing.T) {
{
name: "no updated storage specified: not a decrease",
args: args{
initial: corev1.ResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
initial: corev1.VolumeResourceRequirements{Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceStorage: resource.MustParse("1Gi"),
}},
updated: corev1.ResourceRequirements{},
updated: corev1.VolumeResourceRequirements{},
},
want: StorageComparison{},
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/es/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func newPVC(storageQuantity, storageClass string) corev1.PersistentVolumeClaim {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse(storageQuantity),
},
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/es/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestVolumeMultiDataPath(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("2Gi"),
},
Expand All @@ -130,7 +130,7 @@ func TestVolumeMultiDataPath(t *testing.T) {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("2Gi"),
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/elasticsearch/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (b Builder) WithDefaultPersistentVolumes() Builder {
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Gi"),
},
Expand Down

0 comments on commit abb8be6

Please sign in to comment.