Skip to content

Commit b88914b

Browse files
committed
create ipfsResources field in api
Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>
1 parent f47d411 commit b88914b

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

api/v1alpha1/ipfscluster_types.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
"k8s.io/apimachinery/pkg/api/resource"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
@@ -59,20 +60,34 @@ type followParams struct {
5960
Template string `json:"template"`
6061
}
6162

63+
// networkConfig defines the configuration structure used for networking.
6264
type networkConfig struct {
6365
CircuitRelays int32 `json:"circuitRelays"`
6466
}
6567

68+
// IpfsClusterSpec defines the desired state of the IpfsCluster.
6669
type IpfsClusterSpec struct {
70+
// url defines the URL to be using as an ingress controller.
6771
// +kubebuilder:validation:Optional
68-
URL string `json:"url"`
69-
Public bool `json:"public"`
70-
IpfsStorage resource.Quantity `json:"ipfsStorage"`
71-
ClusterStorage string `json:"clusterStorage"`
72-
Replicas int32 `json:"replicas"`
73-
Networking networkConfig `json:"networking"`
74-
Follows []followParams `json:"follows"`
75-
// Reprovider Describes the settings that each IPFS node
72+
URL string `json:"url"`
73+
// public determines whether or not we should be exposing this IPFS Cluster to the public.
74+
Public bool `json:"public"`
75+
// ipfsStorage defines the total storage to be allocated by this resource.
76+
IpfsStorage resource.Quantity `json:"ipfsStorage"`
77+
// clusterStorage defines the amount of storage to be used by IPFS Cluster.
78+
ClusterStorage string `json:"clusterStorage"`
79+
// replicas sets the number of replicas of IPFS Cluster nodes we should be running.
80+
Replicas int32 `json:"replicas"`
81+
// networking defines network configuration settings.
82+
Networking networkConfig `json:"networking"`
83+
// follows defines the list of other IPFS Clusters this one should follow.
84+
Follows []followParams `json:"follows"`
85+
// ipfsResources specifies the resource requirements for each IPFS container. If this
86+
// value is omitted, then the operator will automatically determine these settings
87+
// based on the storage sizes used.
88+
// +optional
89+
IPFSResources *corev1.ResourceRequirements `json:"ipfsResources,omitempty"`
90+
// reprovider Describes the settings that each IPFS node
7691
// should use when reproviding content.
7792
// +optional
7893
Reprovider ReprovideSettings `json:"reprovider,omitempty"`

controllers/statefulset.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ func (r *IpfsClusterReconciler) statefulSet(m *clusterv1alpha1.IpfsCluster,
6666
) controllerutil.MutateFn {
6767
ssName := "ipfs-cluster-" + m.Name
6868

69-
ipfsResources := utils.IPFSContainerResources(m.Spec.IpfsStorage.Value())
69+
//
70+
var ipfsResources corev1.ResourceRequirements
71+
if m.Spec.IPFSResources == nil {
72+
ipfsResources = *m.Spec.IPFSResources
73+
} else {
74+
ipfsResources = utils.IPFSContainerResources(m.Spec.IpfsStorage.Value())
75+
}
76+
7077
expected := &appsv1.StatefulSet{
7178
ObjectMeta: metav1.ObjectMeta{
7279
Name: ssName,

controllers/utils/utils.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,16 @@ func IPFSContainerResources(ipfsStorageBytes int64) (ipfsResources corev1.Resour
6262
ipfsRAMGBMin = 1
6363
}
6464

65-
// // ipfsRAMMinQuantity := resource.NewScaledQuantity(ipfsRAMGBMin, resource.Giga)
66-
// ipfsRAMMaxQuantity := resource.NewScaledQuantity(2*ipfsRAMGBMin, resource.Giga)
67-
// // ipfsCoresMinQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
68-
// ipfsCoresMaxQuantity := resource.NewScaledQuantity(2*ipfsMilliCoresMin, resource.Milli)
69-
70-
// ipfsRAMMinQuantity := resource.NewScaledQuantity(ipfsRAMGBMin, resource.Giga)
71-
ipfsRAMMaxQuantity := resource.NewScaledQuantity(ipfsRAMGBMin, resource.Giga)
72-
// ipfsCoresMinQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
73-
ipfsCoresMaxQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
65+
ipfsRAMMinQuantity := resource.NewScaledQuantity(ipfsRAMGBMin, resource.Giga)
66+
ipfsRAMMaxQuantity := resource.NewScaledQuantity(2*ipfsRAMGBMin, resource.Giga)
67+
ipfsCoresMinQuantity := resource.NewScaledQuantity(ipfsMilliCoresMin, resource.Milli)
68+
ipfsCoresMaxQuantity := resource.NewScaledQuantity(2*ipfsMilliCoresMin, resource.Milli)
7469

7570
ipfsResources = corev1.ResourceRequirements{
76-
// Requests: corev1.ResourceList{
77-
// corev1.ResourceMemory: *ipfsRAMMinQuantity,
78-
// corev1.ResourceCPU: *ipfsCoresMinQuantity,
79-
// },
71+
Requests: corev1.ResourceList{
72+
corev1.ResourceMemory: *ipfsRAMMinQuantity,
73+
corev1.ResourceCPU: *ipfsCoresMinQuantity,
74+
},
8075
Limits: corev1.ResourceList{
8176
corev1.ResourceMemory: *ipfsRAMMaxQuantity,
8277
corev1.ResourceCPU: *ipfsCoresMaxQuantity,

test-kuttl/e2e/cluster-follow/00-create-cluster.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ spec:
1010
replicas: 1
1111
networking:
1212
circuitRelays: 1
13+
ipfsResources:
14+
limits:
15+
cpu: 250m
16+
memory: 512M
1317
follows:
1418
- name: gutenberg_es
1519
template: gutenberg-es.collab.ipfscluster.io

test-kuttl/e2e/ipfs/05-create-ipfs-cluster.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ spec:
1010
public: false
1111
replicas: 2
1212
follows: []
13+
ipfsResources:
14+
limits:
15+
cpu: 250m
16+
memory: 512M
1317
networking:
1418
circuitRelays: 0

0 commit comments

Comments
 (0)