Skip to content

Commit a3c6dbb

Browse files
authored
Merge pull request #83 from RobotSail/RobotSail/issue81
Implement Private Networking
2 parents 4521daf + 4e784d4 commit a3c6dbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1597
-825
lines changed

.github/workflows/validate-ipfs.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ jobs:
8181
runs-on: ubuntu-20.04
8282
steps:
8383
- uses: actions/checkout@v2
84-
84+
- name: Test commands
85+
shell: bash
86+
run: |
87+
# display path
88+
echo "${PATH}"
89+
# display where awk is
90+
echo $(whereis awk)
8591
- name: Install the Kubectl binary
8692
run: |
8793
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ vendor/*
3636

3737
# use this directory for files during development that shouldn't be pushed
3838
temp/*
39+
40+
report.json

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Build the manager binary
22
FROM golang:1.18 as builder
33

4+
# these are reasonable defaults which accommodate 90% of cases
5+
ARG arch=amd64
6+
ARG platform=linux
7+
48
WORKDIR /workspace
59
# Copy the Go Modules manifests
610
COPY go.mod go.mod
@@ -15,7 +19,7 @@ COPY api/ api/
1519
COPY controllers/ controllers/
1620

1721
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
22+
RUN CGO_ENABLED=0 GOOS=${platform} GOARCH=${arch} go build -a -o manager main.go
1923

2024
# Use distroless as minimal base image to package the manager binary
2125
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# set binary versions
2-
GOLANGCI_VERSION := v1.46.1
2+
GOLANGCI_VERSION := v1.51.1
33
HELM_VERSION := v3.8.2
44
KUTTL_VERSION := 0.15.0
55
GINKGO_VERSION := v2.7.0
@@ -105,6 +105,7 @@ help: ## Display this help.
105105
.PHONY: manifests
106106
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
107107
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
108+
cp config/crd/bases/* helm/ipfs-operator/crds
108109

109110
.PHONY: generate
110111
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -157,6 +158,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
157158
go run ./main.go
158159

159160
.PHONY: docker-build
161+
# docker build -t ${IMG} . --build-arg arch=$(ARCH) --build-arg platform=$(OS)
160162
docker-build: ## Build docker image with the manager.
161163
docker build -t ${IMG} .
162164

@@ -320,6 +322,17 @@ chmod a+x "$(1)" ;\
320322
}
321323
endef
322324

325+
# download-tool will curl any file $2 and install it to $1, using $3 as an output directory.
326+
define download-helm
327+
@[ -f $(1) ] || { \
328+
set -e ;\
329+
echo "📥 Downloading $(2)" ;\
330+
curl -sSLo "$(1).tar.gz" "$(2)" ;\
331+
tar -zxvf "$(1).tar.gz" -C "$(3)" ;\
332+
mv "$(3)/linux-amd64/helm" "$(1)" ;\
333+
}
334+
endef
335+
323336
.PHONY: kuttl
324337
KUTTL := $(LOCALBIN)/kuttl
325338
KUTTL_URL := https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_$(OS)_$(SYS_ARCH)
@@ -347,7 +360,7 @@ HELM := $(LOCALBIN)/helm
347360
HELM_URL := https://get.helm.sh/helm-$(HELM_VERSION)-$(OS)-$(ARCH).tar.gz
348361
helm: $(HELM) ## Install helm
349362
$(HELM): $(LOCALBIN)
350-
$(call download-tool,$(HELM),$(HELM_URL))
363+
$(call download-helm,$(HELM),$(HELM_URL),$(LOCALBIN))
351364

352365

353366
.PHONY: golangci-lint
@@ -357,4 +370,4 @@ golangci-lint: $(GOLANGCILINT) ## Download golangci-lint
357370
$(GOLANGCILINT): $(LOCALBIN)
358371
@ echo "📥 Downloading helm"
359372
curl -sSfL $(GOLANGCI_URL) | sh -s -- -b $(LOCALBIN) $(GOLANGCI_VERSION)
360-
@ echo "✅ Done"
373+
@ echo "✅ Done"

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ Once the values match your environment run the following.
3030
```bash
3131
kubectl create -n default -f ifps.yaml
3232
```
33+
34+
### Running in KIND
35+
36+
An easy way to test and modify changes to the operator is by running it in a local KIND cluster.
37+
To bootstrap a KIND cluster, you can run `hack/setup-kind-cluster.sh`, which will install all of the
38+
required components to operate an IPFS cluster.
39+
40+
To deploy the operator in this repository into the cluster, you can run `hack/run-in-kind.sh` which
41+
will build the source code and inject it into the cluster.
42+
If you make subsequent changes, you will need to re-run `hack/run-in-kind.sh` and kill the previous
43+
operator manager by running `kubectl delete pod -A -n ipfs-operator-system` in order to redploy the updated image.
44+
45+
### Testing Local Changes
46+
47+
If you're developing the operator and would like to test your changes locally, you can do this by
48+
running the kuttl end-to-end tests with `make test-e2e` after redploying the operator.
49+

api/v1alpha1/circuitrelay_types.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"github.com/libp2p/go-libp2p-core/peer"
20+
"github.com/libp2p/go-libp2p/core/peer"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

2323
ma "github.com/multiformats/go-multiaddr"
@@ -70,7 +70,17 @@ func (a *AddrInfoBasicType) DeepCopy() *AddrInfoBasicType {
7070
return out
7171
}
7272

73+
// KeyRef Defines a reference to a specific key on a certain secret.
74+
type KeyRef struct {
75+
KeyName string `json:"keyName"`
76+
SecretName string `json:"secretName"`
77+
}
78+
79+
// CircuitRelaySpec Defines a specification for the RelayCircuit launched by Kubernetes.
7380
type CircuitRelaySpec struct {
81+
// SwarmKeyRef points to a multicodec-encoded v1 PSK stored within a secret somewhere.
82+
// +optional
83+
SwarmKeyRef *KeyRef `json:"swarmKeyRef,omitempty"`
7484
}
7585

7686
type CircuitRelayStatus struct {

api/v1alpha1/ipfscluster_types.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ type followParams struct {
6060
Template string `json:"template"`
6161
}
6262

63-
// networkConfig defines the configuration structure used for networking.
64-
type networkConfig struct {
63+
// NetworkConfig defines the configuration structure used for networking.
64+
type NetworkConfig struct {
65+
// circuitRelays defines how many CircuitRelays should be created.
6566
CircuitRelays int32 `json:"circuitRelays"`
67+
// public is a switch which defines whether this IPFSCluster will use
68+
// the global IPFS network or create its own.
69+
// +kubebuilder:default:=true
70+
Public bool `json:"public,omitempty"`
6671
}
6772

6873
// IpfsClusterSpec defines the desired state of the IpfsCluster.
@@ -74,9 +79,10 @@ type IpfsClusterSpec struct {
7479
// replicas sets the number of replicas of IPFS Cluster nodes we should be running.
7580
Replicas int32 `json:"replicas"`
7681
// networking defines network configuration settings.
77-
Networking networkConfig `json:"networking"`
82+
Networking NetworkConfig `json:"networking"`
7883
// follows defines the list of other IPFS Clusters this one should follow.
79-
Follows []followParams `json:"follows"`
84+
// +optional
85+
Follows []*followParams `json:"follows,omitempty"`
8086
// ipfsResources specifies the resource requirements for each IPFS container. If this
8187
// value is omitted, then the operator will automatically determine these settings
8288
// based on the storage sizes used.

api/v1alpha1/zz_generated.deepcopy.go

+44-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/cluster.ipfs.io_circuitrelays.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ spec:
3232
metadata:
3333
type: object
3434
spec:
35+
description: CircuitRelaySpec Defines a specification for the RelayCircuit
36+
launched by Kubernetes.
37+
properties:
38+
swarmKeyRef:
39+
description: SwarmKeyRef points to a multicodec-encoded v1 PSK stored
40+
within a secret somewhere.
41+
properties:
42+
keyName:
43+
type: string
44+
secretName:
45+
type: string
46+
required:
47+
- keyName
48+
- secretName
49+
type: object
3550
type: object
3651
status:
3752
properties:

bundle/manifests/cluster.ipfs.io_ipfsclusters.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,15 @@ spec:
9797
description: networking defines network configuration settings.
9898
properties:
9999
circuitRelays:
100+
description: circuitRelays defines how many CircuitRelays should
101+
be created.
100102
format: int32
101103
type: integer
104+
public:
105+
default: true
106+
description: public is a switch which defines whether this IPFSCluster
107+
will use the global IPFS network or create its own.
108+
type: boolean
102109
required:
103110
- circuitRelays
104111
type: object
@@ -126,7 +133,6 @@ spec:
126133
type: object
127134
required:
128135
- clusterStorage
129-
- follows
130136
- ipfsStorage
131137
- networking
132138
- replicas

bundle/manifests/ipfs-operator.clusterserviceversion.yaml

+20-8
Large diffs are not rendered by default.

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

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ spec:
3333
metadata:
3434
type: object
3535
spec:
36+
description: CircuitRelaySpec Defines a specification for the RelayCircuit
37+
launched by Kubernetes.
38+
properties:
39+
swarmKeyRef:
40+
description: SwarmKeyRef points to a multicodec-encoded v1 PSK stored
41+
within a secret somewhere.
42+
properties:
43+
keyName:
44+
type: string
45+
secretName:
46+
type: string
47+
required:
48+
- keyName
49+
- secretName
50+
type: object
3651
type: object
3752
status:
3853
properties:

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ spec:
9898
description: networking defines network configuration settings.
9999
properties:
100100
circuitRelays:
101+
description: circuitRelays defines how many CircuitRelays should
102+
be created.
101103
format: int32
102104
type: integer
105+
public:
106+
default: true
107+
description: public is a switch which defines whether this IPFSCluster
108+
will use the global IPFS network or create its own.
109+
type: boolean
103110
required:
104111
- circuitRelays
105112
type: object
@@ -127,7 +134,6 @@ spec:
127134
type: object
128135
required:
129136
- clusterStorage
130-
- follows
131137
- ipfsStorage
132138
- networking
133139
- replicas

config/manifests/bases/ipfs-operator.clusterserviceversion.yaml

+46-10
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)