Skip to content

Commit 98e2d58

Browse files
committed
fixes issue with ipfs cluster container, includes version info
Signed-off-by: Oleg <[email protected]>
1 parent 97ce0f8 commit 98e2d58

File tree

7 files changed

+147
-31
lines changed

7 files changed

+147
-31
lines changed

controllers/ipfs_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (r *IpfsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
121121
}
122122

123123
// Reconcile the tracked objects
124-
trackedObjects := r.createTrackedObjects(ctx, instance, peerid, privStr, clusSec)
124+
trackedObjects := r.createTrackedObjects(ctx, instance, peerid, clusSec, privStr)
125125
shouldRequeue := utils.CreateOrPatchTrackedObjects(ctx, trackedObjects, r.Client, log)
126126
return ctrl.Result{Requeue: shouldRequeue}, nil
127127
}

controllers/statefulset.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const (
4141
notDNSPattern = "[[:^alnum:]]"
4242
// ipfsClusterImage Defines which container image to use when pulling IPFS Cluster.
4343
// HACK: break this up so the version is parameterized, and we can inject the image locally.
44-
ipfsClusterImage = "ipfs/ipfs-cluster:v1.0.1"
44+
ipfsClusterImage = "ipfs-cluster-k8s-image:local-build"
4545
// ipfsClusterMountPath Defines where the cluster storage volume is mounted.
4646
ipfsClusterMountPath = "/data/ipfs-cluster"
4747
// ipfsMountPath Defines where the IPFS volume is mounted.
@@ -163,8 +163,10 @@ func (r *IpfsReconciler) statefulSet(m *clusterv1alpha1.Ipfs,
163163
Image: ipfsClusterImage,
164164
ImagePullPolicy: corev1.PullIfNotPresent,
165165
Command: []string{
166-
"sh",
167-
"/custom/entrypoint.sh",
166+
"/entry.sh",
167+
},
168+
Args: []string{
169+
"run",
168170
},
169171
Env: []corev1.EnvVar{
170172
{

hack/run-in-kind.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -e -o pipefail
44

55
# Declare globals
66
KIND_TAG="local-build"
7-
DOCKER_IMAGE="quay.io/redhat-et-ipfs/ipfs-operator"
87

98
################################
109
# Makes sure the given commands are installed
@@ -28,14 +27,27 @@ function check_cmd() {
2827
# make sure that helm, kind, and docker are installed
2928
check_cmd helm docker kind
3029

31-
# build the container image
30+
# build the container images
3231
make docker-build
33-
docker tag "${DOCKER_IMAGE}:latest" "${DOCKER_IMAGE}:${KIND_TAG}"
34-
kind load docker-image "${DOCKER_IMAGE}:${KIND_TAG}"
32+
make -C ipfs-cluster-image image
33+
34+
# load them into kind
35+
IMAGES=(
36+
"quay.io/redhat-et-ipfs/ipfs-operator"
37+
"ipfs-cluster-k8s-image"
38+
)
39+
40+
for i in "${IMAGES[@]}"; do
41+
docker tag "${i}:latest" "${i}:${KIND_TAG}"
42+
kind load docker-image "${i}:${KIND_TAG}"
43+
done
3544

3645
# using helm, install the IPFS Cluster Operator into the current cluster
3746
helm upgrade --install \
3847
--debug \
3948
--set image.tag="${KIND_TAG}" \
4049
ipfs-cluster ./helm/ipfs-operator
4150

51+
# TODO: implement auto-deletion of previous operator pod
52+
# # if there is an existing operator pod running, delete it so we can properly restart
53+
# kubectl delete pod -l app=ipfs-operator

ipfs-cluster-image/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ WORKDIR /workspace
99
ARG IPFS_CLUSTER_VERSION="v1.0.2"
1010
ARG IPFS_CLUSTER_GIT_HASH="b2ce7d916dd2828d86954dac98495eb3aebb12bf"
1111

12+
1213
# just clone the repo at the most recent hash
1314
RUN git clone \
1415
--depth 1 \
15-
--branch=${IPFS_CLUSTER_GIT_HASH} \
16+
--branch=${IPFS_CLUSTER_VERSION} \
1617
https://github.com/ipfs-cluster/ipfs-cluster.git
1718
WORKDIR /workspace/ipfs-cluster
1819

1920
# Ensure we have the correct IPFS Cluster release
20-
RUN /bin/sh -c "[[ $(git rev-list -n 1 HEAD) == ${IPFS_CLUSTER_GIT_HASH} ]]"
21+
RUN /bin/bash -c "[[ $(git rev-list -n 1 HEAD) == ${IPFS_CLUSTER_GIT_HASH} ]]"
2122

2223
# this will create binaries for the following programs under cmd:
2324
# - cmd/ipfs-cluster-service
@@ -47,13 +48,13 @@ EXPOSE \
4748

4849
# copy the built binaries from earlier
4950
COPY --from=builder \
50-
/workspace/ipfs-cluster/cmd/ipfs-cluster-service \
51+
/workspace/ipfs-cluster/cmd/ipfs-cluster-service/ipfs-cluster-service \
5152
/usr/local/bin/ipfs-cluster-service
5253
COPY --from=builder \
53-
/workspace/ipfs-cluster/cmd/ipfs-cluster-ctl \
54+
/workspace/ipfs-cluster/cmd/ipfs-cluster-ctl/ipfs-cluster-ctl \
5455
/usr/local/bin/ipfs-cluster-ctl
5556
COPY --from=builder \
56-
/workspace/ipfs-cluster/cmd/ipfs-cluster-follow \
57+
/workspace/ipfs-cluster/cmd/ipfs-cluster-follow/ipfs-cluster-follow \
5758
/usr/local/bin/ipfs-cluster-follow
5859

5960
# image args

ipfs-cluster-image/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# include version info
2+
include ../version.mk
3+
4+
# image
5+
IMAGE := ipfs-cluster-k8s-image
6+
7+
8+
.PHONY: all
9+
all: image
10+
11+
.PHONY: image
12+
image:
13+
docker build \
14+
--build-arg "builddate_arg=$(BUILDDATE)" \
15+
--build-arg "version_arg=$(BUILD_VERSION)" \
16+
-t $(IMAGE) \
17+
-f Dockerfile .

ipfs-cluster-image/entry.sh

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,100 @@
11
#!/bin/sh
22

3+
set -e -o pipefail
4+
5+
######################################
6+
# Prints out the given message to STDOUT
7+
# with timestamped formatting.
8+
# Globals:
9+
# None
10+
# Arguments:
11+
# msg: (string) message to print
12+
# Returns:
13+
# None
14+
######################################
15+
log() {
16+
msg="$1"
17+
# get the current time
18+
time=$(date +%Y-%m-%dT%H:%M:%S%z)
19+
# print the message with printf
20+
printf "[%s] %s\n" "${time}" "${msg}"
21+
}
22+
23+
######################################
24+
# Prints out information about the running
25+
# container for debugging purposes.
26+
# Globals:
27+
# version: (string) version of the container
28+
# Arguments:
29+
# None
30+
# Returns:
31+
# None
32+
######################################
33+
print_container_info() {
34+
log "---------- IPFS Cluster container version: ${version:-unknown} ----------"
35+
log "${@}"
36+
}
37+
38+
39+
40+
######################################
341
# This is a custom entrypoint for k8s designed to connect to the bootstrap
442
# node running in the cluster. It has been set up using a configmap to
543
# allow changes on the fly.
44+
#
45+
# Globals:
46+
# BOOTSTRAP_PEER_ID (string) the peer id of the bootstrap node
47+
# BOOTSTRAP_PEER_PRIV_KEY (string) the private key of the bootstrap node
48+
# BOOTSTRAP_ADDR (string) the address of the bootstrap node
49+
# SVC_NAME (string) the name of the service to connect to
50+
######################################
51+
run_ipfs_cluster() {
52+
if [ ! -f /data/ipfs-cluster/service.json ]; then
53+
log "📰 no service.json found, creating one"
54+
ipfs-cluster-service init --consensus crdt
55+
log "✅ service.json created"
56+
fi
657

7-
if [ ! -f /data/ipfs-cluster/service.json ]; then
8-
ipfs-cluster-service init --consensus crdt
9-
fi
10-
11-
PEER_HOSTNAME=$(cat /proc/sys/kernel/hostname)
12-
13-
grep -q ".*-0$" /proc/sys/kernel/hostname
14-
if [ $? -eq 0 ]; then
15-
CLUSTER_ID=${BOOTSTRAP_PEER_ID} \
16-
CLUSTER_PRIVATEKEY=${BOOTSTRAP_PEER_PRIV_KEY} \
17-
exec ipfs-cluster-service daemon --upgrade
18-
else
19-
BOOTSTRAP_ADDR=/dns4/${SVC_NAME}-0.${SVC_NAME}/tcp/9096/ipfs/${BOOTSTRAP_PEER_ID}
58+
log "🔍 reading hostname"
59+
PEER_HOSTNAME=$(cat /proc/sys/kernel/hostname)
60+
log "starting ipfs-cluster on ${PEER_HOSTNAME}"
2061

21-
if [ -z $BOOTSTRAP_ADDR ]; then
22-
exit 1
62+
grep -q ".*-0$" /proc/sys/kernel/hostname
63+
if [ $? -eq 0 ]; then
64+
log "starting ipfs-cluster using the provided bootstrap private key"
65+
CLUSTER_ID=${BOOTSTRAP_PEER_ID} \
66+
CLUSTER_PRIVATEKEY=${BOOTSTRAP_PEER_PRIV_KEY} \
67+
exec ipfs-cluster-service daemon --upgrade
68+
else
69+
log "building the bootstrap address"
70+
BOOTSTRAP_ADDR=/dns4/${SVC_NAME}-0.${SVC_NAME}/tcp/9096/ipfs/${BOOTSTRAP_PEER_ID}
71+
log "bootstrap address: ${BOOTSTRA_ADDR}"
72+
if [ -z $BOOTSTRAP_ADDR ]; then
73+
log "no bootstrap address found, exiting"
74+
exit 1
75+
fi
76+
log "starting ipfs-cluster using the bootstrap address"
77+
# Only ipfs user can get here
78+
exec ipfs-cluster-service daemon --upgrade --bootstrap $BOOTSTRAP_ADDR --leave
2379
fi
24-
# Only ipfs user can get here
25-
exec ipfs-cluster-service daemon --upgrade --bootstrap $BOOTSTRAP_ADDR --leave
26-
fi
80+
}
81+
82+
print_container_info
83+
for op in "$@"; do
84+
case $op in
85+
"debug")
86+
log "💤 Sleeping indefinitely"
87+
sleep infinity
88+
log "✅ Done"
89+
;;
90+
"run")
91+
log "🏃 Running IPFS Cluster"
92+
run_ipfs_cluster
93+
log "✅ Done"
94+
;;
95+
*)
96+
log "😕 Operation '${op}' not defined"
97+
exit 1
98+
;;
99+
esac
100+
done

version.mk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file contains information about versioning that is used when building containers.
2+
3+
VERSION := 0.0.1
4+
HEAD_HASH := $(shell git rev-parse --short HEAD)
5+
# whether or not this repository has any commits, or this is directly from the commit#
6+
DIRTY := $(shell git diff --quiet || echo '-dirty')
7+
# the full version string, to be consumed by containers
8+
BUILD_VERSION := v$(VERSION)+$(HEAD_HASH)$(DIRTY)
9+
10+
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%S.%NZ')

0 commit comments

Comments
 (0)