Skip to content

Commit 832b97d

Browse files
author
Cory Schwartz
committed
use existing quantity
1 parent 92832c5 commit 832b97d

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

controllers/statefulset.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (r *IpfsClusterReconciler) statefulSet(m *clusterv1alpha1.IpfsCluster,
6767
ssName := "ipfs-cluster-" + m.Name
6868

6969
var ipfsResources corev1.ResourceRequirements
70-
ipfsStorageQuantity, err := resource.ParseQuantity(m.Spec.IpfsStorage)
7170

7271
// Determine resource constraints from how much we are storing.
7372
// for every TB of storage, Request 1GB of memory and limit if we exceed 2x this amount.
@@ -77,32 +76,28 @@ func (r *IpfsClusterReconciler) statefulSet(m *clusterv1alpha1.IpfsCluster,
7776
// biggest node we would allocate would request a minimum allocation of 16G of RAM and 12 cores
7877
// and would permit usage up to twice this size
7978

80-
if err != nil {
81-
ipfsResources = corev1.ResourceRequirements{}
82-
} else {
83-
ipfsStoragei64, _ := ipfsStorageQuantity.AsInt64()
84-
ipfsStorageTB := ipfsStoragei64 / 1024 / 1024 / 1024 / 1024
85-
ipfsMilliCoresMin := 4000 + (500 * ipfsStorageTB)
86-
ipfsRamGBMin := ipfsStorageTB
87-
if ipfsRamGBMin < 2 {
88-
ipfsRamGBMin = 2
89-
}
79+
ipfsStoragei64, _ := m.Spec.IpfsStorage.AsInt64()
80+
ipfsStorageTB := ipfsStoragei64 / 1024 / 1024 / 1024 / 1024
81+
ipfsMilliCoresMin := 4000 + (500 * ipfsStorageTB)
82+
ipfsRamGBMin := ipfsStorageTB
83+
if ipfsRamGBMin < 2 {
84+
ipfsRamGBMin = 2
85+
}
9086

91-
ipfsRamMinQuantity := resource.NewScaledQuantity(ipfsRamGBMin, resource.Giga)
92-
ipfsRamMaxQuantity := resource.NewScaledQuantity(2*ipfsRamGBMin, resource.Giga)
93-
ipfsCoresMinQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
94-
ipfsCoresMaxQuantity := resource.NewScaledQuantity(2*ipfsMilliCoresMin, resource.Milli)
87+
ipfsRamMinQuantity := resource.NewScaledQuantity(ipfsRamGBMin, resource.Giga)
88+
ipfsRamMaxQuantity := resource.NewScaledQuantity(2*ipfsRamGBMin, resource.Giga)
89+
ipfsCoresMinQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
90+
ipfsCoresMaxQuantity := resource.NewScaledQuantity(2*ipfsMilliCoresMin, resource.Milli)
9591

96-
ipfsResources = corev1.ResourceRequirements{
97-
Requests: corev1.ResourceList{
98-
corev1.ResourceMemory: *ipfsRamMinQuantity,
99-
corev1.ResourceCPU: *ipfsCoresMinQuantity,
100-
},
101-
Limits: corev1.ResourceList{
102-
corev1.ResourceMemory: *ipfsRamMaxQuantity,
103-
corev1.ResourceCPU: *ipfsCoresMaxQuantity,
104-
},
105-
}
92+
ipfsResources = corev1.ResourceRequirements{
93+
Requests: corev1.ResourceList{
94+
corev1.ResourceMemory: *ipfsRamMinQuantity,
95+
corev1.ResourceCPU: *ipfsCoresMinQuantity,
96+
},
97+
Limits: corev1.ResourceList{
98+
corev1.ResourceMemory: *ipfsRamMaxQuantity,
99+
corev1.ResourceCPU: *ipfsCoresMaxQuantity,
100+
},
106101
}
107102

108103
expected := &appsv1.StatefulSet{

0 commit comments

Comments
 (0)