Skip to content

Commit 8b54d72

Browse files
committed
Add service-config and expose metrics
1 parent 080e796 commit 8b54d72

11 files changed

+598
-141
lines changed

api/v1alpha1/ipfscluster_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ type IpfsClusterSpec struct {
8686
// should use when reproviding content.
8787
// +optional
8888
Reprovider ReprovideSettings `json:"reprovider,omitempty"`
89+
// stats determines whether metrics should be enabled.
90+
// +optional
91+
Stats bool `json:"stats"`
8992
}
9093

9194
type IpfsClusterStatus struct {

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

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ spec:
125125
- roots
126126
type: string
127127
type: object
128+
stats:
129+
description: stats determines whether metrics should be enabled.
130+
type: boolean
128131
required:
129132
- clusterStorage
130133
- follows

controllers/circuitrelay_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import (
3636
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3737
"sigs.k8s.io/controller-runtime/pkg/log"
3838

39-
"github.com/libp2p/go-libp2p-core/crypto"
40-
peer "github.com/libp2p/go-libp2p-core/peer"
4139
relaydaemon "github.com/libp2p/go-libp2p-relay-daemon"
40+
"github.com/libp2p/go-libp2p/core/crypto"
41+
peer "github.com/libp2p/go-libp2p/core/peer"
4242
relayv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay"
4343
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
4444
"github.com/redhat-et/ipfs-operator/controllers/utils"

controllers/ipfs_cluster_service.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package controllers
2+
3+
import (
4+
"github.com/ipfs-cluster/ipfs-cluster/cmdutils"
5+
ma "github.com/multiformats/go-multiaddr"
6+
)
7+
8+
func GetDefaultServiceConfig() *cmdutils.ConfigHelper {
9+
cfgHelper := cmdutils.NewConfigHelper("", "", "crdt", "badger")
10+
cfgHelper.Manager().Default()
11+
return cfgHelper
12+
}
13+
14+
func EnableMetrics(serviceConfig *cmdutils.Configs) {
15+
serviceConfig.Metrics.EnableStats = true
16+
serviceConfig.Metrics.PrometheusEndpoint, _ = ma.NewMultiaddr("/ip4/0.0.0.0/tcp/8888")
17+
}

controllers/ipfs_util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"encoding/hex"
77
"fmt"
88

9-
ci "github.com/libp2p/go-libp2p-core/crypto"
10-
peer "github.com/libp2p/go-libp2p-core/peer"
9+
ci "github.com/libp2p/go-libp2p/core/crypto"
10+
peer "github.com/libp2p/go-libp2p/core/peer"
1111
)
1212

1313
func newClusterSecret() (string, error) {

controllers/ipfscluster_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3333
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
3434

35-
"github.com/libp2p/go-libp2p-core/peer"
35+
"github.com/libp2p/go-libp2p/core/peer"
3636
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
3737
"github.com/redhat-et/ipfs-operator/controllers/utils"
3838
)

controllers/scripts.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/alecthomas/units"
1212
"github.com/ipfs/kubo/config"
13-
"github.com/libp2p/go-libp2p-core/peer"
13+
"github.com/libp2p/go-libp2p/core/peer"
1414
ma "github.com/multiformats/go-multiaddr"
1515
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
1616
"github.com/redhat-et/ipfs-operator/controllers/scripts"
@@ -101,6 +101,17 @@ func (r *IpfsClusterReconciler) ConfigMapScripts(
101101
string(reproviderStrategy),
102102
)
103103

104+
serviceConfig := GetDefaultServiceConfig()
105+
if m.Spec.Stats {
106+
EnableMetrics(serviceConfig.Configs())
107+
}
108+
109+
serviceConfigFile, err := serviceConfig.Manager().ToJSON()
110+
if err != nil {
111+
log.Error(err, "could not marshal service config file")
112+
return utils.ErrFunc(fmt.Errorf("error converting serviceConfig to JSON: %w", err)), ""
113+
}
114+
104115
expected := &corev1.ConfigMap{
105116
ObjectMeta: metav1.ObjectMeta{
106117
Name: cmName,
@@ -109,6 +120,7 @@ func (r *IpfsClusterReconciler) ConfigMapScripts(
109120
Data: map[string]string{
110121
"entrypoint.sh": scripts.IPFSClusterEntrypoint,
111122
"configure-ipfs.sh": configScript,
123+
"service.json": string(serviceConfigFile),
112124
},
113125
}
114126
expected.DeepCopyInto(cm)

controllers/scripts/config.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/alecthomas/units"
1212
"github.com/ipfs/kubo/config"
13-
"github.com/libp2p/go-libp2p-core/peer"
13+
"github.com/libp2p/go-libp2p/core/peer"
1414
)
1515

1616
type configureIpfsOpts struct {
@@ -92,6 +92,8 @@ run_ipfs_cluster() {
9292
log "🔍 reading hostname"
9393
PEER_HOSTNAME=$(cat /proc/sys/kernel/hostname)
9494
log "starting ipfs-cluster on ${PEER_HOSTNAME}"
95+
cp /custom/service.json /data/ipfs-cluster/
96+
sed -i '/peername/c\ \"peername\" : \"'$PEER_HOSTNAME'\",' /data/ipfs-cluster/service.json
9597
9698
grep -q ".*-0$" /proc/sys/kernel/hostname
9799
if [ $? -eq 0 ]; then
@@ -236,7 +238,9 @@ func applyIPFSClusterK8sDefaults(conf *config.Config, storageMax string, peers [
236238
conf.Bootstrap = config.DefaultBootstrapAddresses
237239
conf.Addresses.API = config.Strings{"/ip4/0.0.0.0/tcp/5001"}
238240
conf.Addresses.Gateway = config.Strings{"/ip4/0.0.0.0/tcp/8080"}
239-
conf.Swarm.ConnMgr.HighWater = 2000
241+
highWater := &config.OptionalInteger{}
242+
highWater.UnmarshalJSON([]byte("2000"))
243+
conf.Swarm.ConnMgr.HighWater = highWater
240244
conf.Datastore.BloomFilterSize = 1048576
241245
conf.Datastore.StorageMax = storageMax
242246
conf.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001"}

controllers/statefulset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const (
5454
// ipfsMountPath Defines where the IPFS volume is mounted.
5555
ipfsMountPath = "/data/ipfs"
5656
// ipfsImage Defines which image we should pull when running IPFS containers.
57-
ipfsImage = "docker.io/ipfs/kubo:v0.14.0"
57+
ipfsImage = "docker.io/ipfs/kubo:v0.17.0"
5858
)
5959

6060
// StatefulSet Returns a mutate function that creates a StatefulSet for the

0 commit comments

Comments
 (0)