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"
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
AppendAnnotations map[string]string `json:"appendAnnotations,omitempty"`
}

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,omitempty"`
ClusterAPI *ExternalSettings `json:"clusterApi,omitempty"`
}

type IpfsClusterStatus struct {
Expand Down
32 changes: 32 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.

27 changes: 27 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:
appendAnnotations:
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:
appendAnnotations:
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,6 +157,7 @@ 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:
- clusterStorage
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/redhat-et-ipfs/ipfs-operator
newName: coryschwartz/ipfs-operator
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
17 changes: 16 additions & 1 deletion controllers/ipfscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ 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{}
Expand All @@ -149,8 +151,8 @@ func (r *IpfsClusterReconciler) createTrackedObjects(
instance,
&secConfig,
[]byte(clusterSecret),
[]byte(peerID.String()),
[]byte(privateString),
peerID.String(),
)
mutSts := r.StatefulSet(instance, &sts, svcName, secConfigName, cmScriptName)

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

if instance.Spec.Gateway != nil {
mutgwsvc, _ := r.serviceGateway(instance, &gwsvc)
if instance.Spec.Gateway.Strategy == clusterv1alpha1.ExternalStrategyLoadBalancer {
trackedObjects[&gwsvc] = mutgwsvc
}
}
if instance.Spec.ClusterAPI != nil {
mutapisvc, _ := r.serviceAPI(instance, &apisvc)
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