Skip to content

Commit d496890

Browse files
authored
Merge pull request #21 from coryschwartz/feat/follow
ipfs cluster follow
2 parents f906aa8 + 8e010fd commit d496890

File tree

8 files changed

+95
-9
lines changed

8 files changed

+95
-9
lines changed

api/v1alpha1/ipfs_types.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,23 @@ const (
3131
ReconciledReasonError string = "ReconcileError"
3232
)
3333

34+
type followParams struct {
35+
Name string `json:"name"`
36+
Template string `json:"template"`
37+
}
38+
3439
type networkConfig struct {
3540
CircuitRelays int32 `json:"circuitRelays"`
3641
}
3742

3843
type IpfsSpec struct {
39-
URL string `json:"url"`
40-
Public bool `json:"public"`
41-
IpfsStorage string `json:"ipfsStorage"`
42-
ClusterStorage string `json:"clusterStorage"`
43-
Replicas int32 `json:"replicas"`
44-
Networking networkConfig `json:"networking"`
44+
URL string `json:"url"`
45+
Public bool `json:"public"`
46+
IpfsStorage string `json:"ipfsStorage"`
47+
ClusterStorage string `json:"clusterStorage"`
48+
Replicas int32 `json:"replicas"`
49+
Networking networkConfig `json:"networking"`
50+
Follows []followParams `json:"follows"`
4551
}
4652

4753
type IpfsStatus struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.ipfs.io_ipfs.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ spec:
3636
properties:
3737
clusterStorage:
3838
type: string
39+
follows:
40+
items:
41+
properties:
42+
name:
43+
type: string
44+
template:
45+
type: string
46+
required:
47+
- name
48+
- template
49+
type: object
50+
type: array
3951
ipfsStorage:
4052
type: string
4153
networking:
@@ -55,6 +67,7 @@ spec:
5567
type: string
5668
required:
5769
- clusterStorage
70+
- follows
5871
- ipfsStorage
5972
- networking
6073
- public

controllers/scripts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ user=ipfs
2929
3030
3131
if [ ! -f /data/ipfs-cluster/service.json ]; then
32-
ipfs-cluster-service init
32+
ipfs-cluster-service init --consensus crdt
3333
fi
3434
3535
PEER_HOSTNAME=$(cat /proc/sys/kernel/hostname)

controllers/statefulset.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package controllers
22

33
import (
4+
"regexp"
5+
"strings"
6+
47
appsv1 "k8s.io/api/apps/v1"
58
corev1 "k8s.io/api/core/v1"
69
"k8s.io/apimachinery/pkg/api/resource"
@@ -12,6 +15,14 @@ import (
1215
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
1316
)
1417

18+
var (
19+
// objects need to be RFC-1123 compliant, and k8s uses this regex to test.
20+
// https://github.com/kubernetes/apimachinery/blob/v0.24.2/pkg/util/validation/validation.go
21+
// dns1123LabelFmt "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
22+
// We want to match the opposite.
23+
notdns *regexp.Regexp = regexp.MustCompile("[[:^alnum:]]")
24+
)
25+
1526
func (r *IpfsReconciler) statefulSet(m *clusterv1alpha1.Ipfs,
1627
sts *appsv1.StatefulSet,
1728
serviceName string,
@@ -255,6 +266,30 @@ func (r *IpfsReconciler) statefulSet(m *clusterv1alpha1.Ipfs,
255266
ServiceName: serviceName,
256267
},
257268
}
269+
270+
// Add a follower container for each follow.
271+
for _, follow := range m.Spec.Follows {
272+
container := corev1.Container{
273+
Name: "ipfs-cluster-follow-" + notdns.ReplaceAllString(strings.ToLower(follow.Name), "-"),
274+
Image: "ipfs/ipfs-cluster:v1.0.1",
275+
ImagePullPolicy: corev1.PullIfNotPresent,
276+
Command: []string{
277+
"ipfs-cluster-follow",
278+
follow.Name,
279+
"run",
280+
"--init",
281+
follow.Template,
282+
},
283+
VolumeMounts: []corev1.VolumeMount{
284+
{
285+
Name: "cluster-storage",
286+
MountPath: "/data/ipfs-cluster",
287+
},
288+
},
289+
}
290+
expected.Spec.Template.Spec.Containers = append(expected.Spec.Template.Spec.Containers, container)
291+
}
292+
258293
expected.DeepCopyInto(sts)
259294
ctrl.SetControllerReference(m, sts, r.Scheme)
260295
return func() error {

examples/collab-follow.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
apiVersion: cluster.ipfs.io/v1alpha1
3+
kind: Ipfs
4+
metadata:
5+
name: ipfs-sample-collab
6+
spec:
7+
url: apps.jephilli-4-11-04-28-0655.devcluster.openshift.com
8+
ipfsStorage: 5Ti
9+
clusterStorage: 20Gi
10+
public: true
11+
replicas: 5
12+
follows:
13+
- name: filecoin
14+
template: filecoin.collab.ipfscluster.io
15+
- name: gutenberg_es
16+
template: gutenberg-es.collab.ipfscluster.io
17+
- name: ipfs-websites
18+
template: ipfs-websites.collab.ipfscluster.io
19+
- name: pkg.pacman.store
20+
template: cluster.pkg.pacman.store
21+
- name: ravencoin
22+
template: ipfs-collab.ravencoin.network
23+
- name: wikipedia
24+
template: wikipedia.collab.ipfscluster.io

examples/ipfs.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: cluster.ipfs.io/v1alpha1
23
kind: Ipfs
34
metadata:
@@ -7,6 +8,7 @@ spec:
78
ipfsStorage: 50Gi
89
clusterStorage: 5Gi
910
public: true
10-
replicas: 3
11+
replicas: 2
12+
follows: []
1113
networking:
1214
circuitRelays: 2

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ spec:
1313
clusterStorage: 2Gi
1414
public: false
1515
replicas: 2
16+
follows: []
1617
networking:
1718
circuitRelays: 0
1819
EOF

0 commit comments

Comments
 (0)