@@ -66,6 +66,40 @@ func (r *IpfsClusterReconciler) statefulSet(m *clusterv1alpha1.IpfsCluster,
6666) controllerutil.MutateFn {
6767 ssName := "ipfs-cluster-" + m .Name
6868
69+ var ipfsResources corev1.ResourceRequirements
70+
71+ // Determine resource constraints from how much we are storing.
72+ // for every TB of storage, Request 1GB of memory and limit if we exceed 2x this amount.
73+ // memory floor is 2G.
74+ // The CPU requirement starts at 4 cores and increases by 500m for every TB of storage
75+ // many block storage providers have a maximum block storage of 16TB, so in this case, the
76+ // biggest node we would allocate would request a minimum allocation of 16G of RAM and 12 cores
77+ // and would permit usage up to twice this size
78+
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+ }
86+
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 )
91+
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+ },
101+ }
102+
69103 expected := & appsv1.StatefulSet {
70104 ObjectMeta : metav1.ObjectMeta {
71105 Name : ssName ,
@@ -164,7 +198,7 @@ func (r *IpfsClusterReconciler) statefulSet(m *clusterv1alpha1.IpfsCluster,
164198 MountPath : ipfsMountPath ,
165199 },
166200 },
167- Resources : corev1. ResourceRequirements {} ,
201+ Resources : ipfsResources ,
168202 },
169203 {
170204 Name : "ipfs-cluster" ,
0 commit comments