Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/external api #74

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
18 changes: 17 additions & 1 deletion api/v1alpha1/ipfscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ const (

type ReproviderStrategy string

type ExternalStrategy string

const (
// ReproviderStrategyAll Announces the CID of every stored block.
ReproviderStrategyAll ReproviderStrategy = "all"
// ReproviderStrategyPinned Only announces the pinned CIDs recursively.
ReproviderStrategyPinned ReproviderStrategy = "pinned"
// ReproviderStrategyRoots Only announces the root block of explicitly pinned CIDs.
ReproviderStrategyRoots ReproviderStrategy = "roots"
ReproviderStrategyRoots ReproviderStrategy = "roots"
ExternalStrategyNone ExternalStrategy = "none"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string values themselves should be in Pascal case to be consistent with the Kubernetes style.
So these would be None, LoadBalancer, Ingress

ExternalStrategyIngress ExternalStrategy = "ingress"
ExternalStrategyLoadBalancer ExternalStrategy = "loadbalancer"
)

type ReprovideSettings struct {
Expand All @@ -55,6 +60,14 @@ type ReprovideSettings struct {
Interval string `json:"interval,omitempty"`
}

type ExternalSettings struct {
// +kubebuilder:validation:Enum={ingress,loadbalancer,none}
// +optional
Strategy ExternalStrategy `json:"strategy,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly are these fields supposed to change or control? Could you please include a one-sentence comment above the new fields and structs being added?

// +optional
Annotations map[string]string `json:"interval,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

}

type followParams struct {
Name string `json:"name"`
Template string `json:"template"`
Expand All @@ -69,6 +82,7 @@ type networkConfig struct {
type IpfsClusterSpec struct {
// url defines the URL to be using as an ingress controller.
// +kubebuilder:validation:Optional
// Reprovider Describes the settings that each IPFS node
URL string `json:"url"`
// public determines whether or not we should be exposing this IPFS Cluster to the public.
Public bool `json:"public"`
Expand All @@ -91,6 +105,8 @@ type IpfsClusterSpec struct {
// should use when reproviding content.
// +optional
Reprovider ReprovideSettings `json:"reprovider,omitempty"`
Gateway ExternalSettings `json:"gateway"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a description

ClusterAPI ExternalSettings `json:"clusterApi"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make Gateway and ClusterAPI as optional field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Setting these to omitempty

}

type IpfsClusterStatus struct {
Expand Down
24 changes: 24 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions config/crd/bases/cluster.ipfs.io_ipfsclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ spec:
spec:
description: IpfsClusterSpec defines the desired state of the IpfsCluster.
properties:
clusterApi:
properties:
interval:
additionalProperties:
type: string
type: object
strategy:
enum:
- ingress
- loadbalancer
- none
type: string
type: object
clusterStorage:
anyOf:
- type: integer
Expand All @@ -57,6 +70,19 @@ spec:
- template
type: object
type: array
gateway:
properties:
interval:
additionalProperties:
type: string
type: object
strategy:
enum:
- ingress
- loadbalancer
- none
type: string
type: object
ipfsResources:
description: ipfsResources specifies the resource requirements for
each IPFS container. If this value is omitted, then the operator
Expand Down Expand Up @@ -131,10 +157,13 @@ spec:
type: object
url:
description: url defines the URL to be using as an ingress controller.
Reprovider Describes the settings that each IPFS node
type: string
required:
- clusterApi
- clusterStorage
- follows
- gateway
- ipfsStorage
- networking
- public
Expand Down
8 changes: 4 additions & 4 deletions controllers/circuitrelay_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (r *CircuitRelayReconciler) serviceRelay(
{
Name: "swarm",
Protocol: corev1.ProtocolTCP,
Port: portSwarm,
Port: portIpfsSwarm,
TargetPort: intstr.FromString("swarm"),
},
// Commented out because some load balancers don't support TCP+UDP:(
Expand Down Expand Up @@ -420,18 +420,18 @@ func (r *CircuitRelayReconciler) deploymentRelay(
Ports: []corev1.ContainerPort{
{
Name: "swarm",
ContainerPort: portSwarm,
ContainerPort: portIpfsSwarm,
Protocol: "TCP",
},
{
// Should this port number be the same as portSwarm or should it be a different one?
Name: "swarm-udp",
ContainerPort: portSwarmUDP,
ContainerPort: portIpfsSwarmUDP,
Protocol: "UDP",
},
{
Name: "pprof",
ContainerPort: portPprof,
ContainerPort: portIpfsPprof,
Protocol: "UDP",
},
},
Expand Down
14 changes: 13 additions & 1 deletion controllers/ipfscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,26 @@ func (r *IpfsClusterReconciler) createTrackedObjects(
) map[client.Object]controllerutil.MutateFn {
sa := corev1.ServiceAccount{}
svc := corev1.Service{}
gwsvc := corev1.Service{}
apisvc := corev1.Service{}
cmScripts := corev1.ConfigMap{}
secConfig := corev1.Secret{}
sts := appsv1.StatefulSet{}

mutsa := r.serviceAccount(instance, &sa)
mutsvc, svcName := r.serviceCluster(instance, &svc)

mutgwsvc, _ := r.serviceGateway(instance, &gwsvc)
mutapisvc, _ := r.serviceAPI(instance, &apisvc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider moving this under the below if condition on line 170?

mutCmScripts, cmScriptName := r.ConfigMapScripts(ctx, instance, &cmScripts)
mutSecConfig, secConfigName := r.SecretConfig(
ctx,
instance,
&secConfig,
[]byte(clusterSecret),
[]byte(peerID.String()),
[]byte(privateString),
peerID.String(),
)
mutSts := r.StatefulSet(instance, &sts, svcName, secConfigName, cmScriptName)

Expand All @@ -161,6 +166,13 @@ func (r *IpfsClusterReconciler) createTrackedObjects(
&secConfig: mutSecConfig,
&sts: mutSts,
}

if instance.Spec.Gateway.Strategy == clusterv1alpha1.ExternalStrategyLoadBalancer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in other words, only LoadBalancer is currently supported?

trackedObjects[&gwsvc] = mutgwsvc
}
if instance.Spec.ClusterAPI.Strategy == clusterv1alpha1.ExternalStrategyLoadBalancer {
trackedObjects[&apisvc] = mutapisvc
}
return trackedObjects
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/ipfscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ var _ = Describe("IPFS Reconciler", func() {
})
It("creates a new peer ids", func() {
secretConfig := &v1.Secret{}
fn, _ := ipfsReconciler.SecretConfig(ctx, ipfs, secretConfig, clusterSec, bootstrapKey, clusterPeerID)
fn, _ := ipfsReconciler.SecretConfig(ctx, ipfs, secretConfig, clusterSec, bootstrapKey, []byte(clusterPeerID))
Expect(fn()).To(BeNil())
secretStringToData(secretConfig)
expectedKeys := int(replicas)*2 + alwaysKeys
Expect(len(secretConfig.Data)).To(Equal(expectedKeys))

// increase the replica count. Expect to see new keys generated.
ipfs.Spec.Replicas++
fn, _ = ipfsReconciler.SecretConfig(ctx, ipfs, secretConfig, clusterSec, bootstrapKey, clusterPeerID)
fn, _ = ipfsReconciler.SecretConfig(ctx, ipfs, secretConfig, clusterSec, bootstrapKey, []byte(clusterPeerID))
Expect(fn()).To(BeNil())
secretStringToData(secretConfig)
Expect(len(secretConfig.Data)).To(Equal(expectedKeys + 2))
Expand Down
4 changes: 2 additions & 2 deletions controllers/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (r *IpfsClusterReconciler) SecretConfig(
m *clusterv1alpha1.IpfsCluster,
sec *corev1.Secret,
clusterSecret,
bootstrapPeerID,
bootstrapPrivateKey []byte,
peerID string,
) (controllerutil.MutateFn, string) {
secName := "ipfs-cluster-" + m.Name

Expand All @@ -60,7 +60,7 @@ func (r *IpfsClusterReconciler) SecretConfig(
}
expectedSecret.Data["CLUSTER_SECRET"] = clusterSecret
expectedSecret.Data["BOOTSTRAP_PEER_PRIV_KEY"] = bootstrapPrivateKey
expectedSecret.StringData["BOOTSTRAP_PEER_ID"] = peerID
expectedSecret.Data["BOOTSTRAP_PEER_ID"] = bootstrapPeerID
} else {
// secret exists.
// test if we need to add more identieis
Expand Down
Loading