Skip to content

Commit 0d8ef54

Browse files
author
Cory Schwartz
authored
Merge pull request #20 from coryschwartz/feat/configure-resources-for-volume-size
different resources for different volume size
2 parents 1d7d2f6 + 268956c commit 0d8ef54

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

controllers/ipfs_util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/hex"
77
"fmt"
88

9-
"github.com/libp2p/go-libp2p-core/crypto"
109
ci "github.com/libp2p/go-libp2p-core/crypto"
1110
peer "github.com/libp2p/go-libp2p-core/peer"
1211
)
@@ -42,7 +41,7 @@ func generateIdentity() (peer.ID, string, error) {
4241
if err != nil {
4342
return "", "", fmt.Errorf("cannot generate new key: %w", err)
4443
}
45-
privBytes, err := crypto.MarshalPrivateKey(priv)
44+
privBytes, err := ci.MarshalPrivateKey(priv)
4645
if err != nil {
4746
return "", "", fmt.Errorf("cannot get bytes from private key: %w", err)
4847
}

controllers/statefulset.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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",

test-kuttl/kuttl-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestSuite
44
testDirs:
55
- ./e2e
6-
timeout: 30
6+
timeout: 120

0 commit comments

Comments
 (0)