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
Open

Feat/external api #74

wants to merge 14 commits into from

Conversation

coryschwartz
Copy link
Collaborator

fixes: #72
fixes: #71

@coryschwartz coryschwartz marked this pull request as ready for review October 10, 2022 07:43
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?

@coryschwartz
Copy link
Collaborator Author

@RobotSail can you check this out when you get the chance?

@coryschwartz
Copy link
Collaborator Author

This is running in the test cluster,

you can find the gateway with kubectl get services

and this can be used as a gateway just like ipfs.io. i.e. you can find content in a browser by hitting /ipfs/<CID>

@@ -135,28 +146,28 @@ func (r *IpfsClusterReconciler) StatefulSet(m *clusterv1alpha1.IpfsCluster,
},
Ports: []corev1.ContainerPort{
{
Name: "swarm",
ContainerPort: portSwarm,
Name: nameIpfsSwarm,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like it

svcName,
m.Name,
m.Namespace,
"LoadBalancer",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this always need to be a loadbalancer? Could a ClusterIP not fulfill this role?

@@ -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?

@@ -43,8 +43,8 @@ spec:
- --leader-elect
command:
- /manager
image: "{{ include "container-image" (list . .Values.image) }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
image: quay.io/redhat-et-ipfs/ipfs-operator:v0.0.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure why but one of the make targets always makes this change. We want to revert this so that the template exists

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

// +optional
Strategy ExternalStrategy `json:"strategy,omitempty"`
// +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?

@@ -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

m.Name,
m.Namespace,
"LoadBalancer",
m.Annotations,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we're passing the CR's annotations onto the expected service?

m.Name,
m.Namespace,
"LoadBalancer",
m.Annotations,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, this is passing the same annotations onto the expected service

Copy link
Collaborator

@RobotSail RobotSail left a comment

Choose a reason for hiding this comment

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

Some changes needed but it looks good overall, though I did have some questions:

  1. At the moment it looks like we're providing options to have LoadBalancer and Ingress, is there a reason that ClusterIP isn't supported?
  2. I like that you provided options for what the users can select, but I saw in the code that it only does something when LoadBalancer is provided, whereas Ingress and None are both doing nothing. If ClusterIP isn't supported for whatever reason, should we just drop the other fields?
  3. I noticed that you added the option for the user to provide their own annotations, is there a reason we can't provide these values ourselves?

Copy link
Contributor

@patilsuraj767 patilsuraj767 left a comment

Choose a reason for hiding this comment

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

Hello, I have added some observations below.

@@ -91,6 +105,8 @@ type IpfsClusterSpec struct {
// should use when reproviding content.
// +optional
Reprovider ReprovideSettings `json:"reprovider,omitempty"`
Gateway ExternalSettings `json:"gateway"`
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

Comment on lines 148 to 150
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?

@patilsuraj767
Copy link
Contributor

Along with this changes we will also need to add CLUSTER_RESTAPI_HTTPLISTENMULTIADDRESS=/ip4/0.0.0.0/tcp/9094 in configure-script - controllers/scripts/config.go and same as environment variable in statefulset - controllers/statefulset.go

@coryschwartz
Copy link
Collaborator Author

So as discussed before, This adds the ability to expose ports outside the cluster. At the moment, it supports only "LoadBalancer" strategy, but I expect we will want to add an Ingress strategy also in a future PR.

I think some of the old comments have been lost in resolved conversations. The reason for the "AppendAnnotations" is becasuse I am thinking of how we will configure the future Ingress strategy.

Ingress Controllers tend to accept configuration through annotations, and this will let you do such things as set Host names and URL routes.

Likewise, I the user might have external-dns automation, and this is also controlled by annotation.

The LoadBalancer, with no annotations, is probably the simplest, and crudest way to expose the service.

One of the comments is asking why we don't support ClusterIP, and we do! But those services are already created. I just didn't want to expose the administrative endpoints

If you want to try it out, there is an "gateway" service running now! There is no DNS or anything, it's reachable here on port 8080

a0371fb3c5dc7448e8aff816b8c00454-264540294.us-west-1.elb.amazonaws.com

You can try this with anything CID that works on the ipfs.io, cloudflare, or any other IPFS gateway.

Try this:
our gateway service:
a0371fb3c5dc7448e8aff816b8c00454-264540294.us-west-1.elb.amazonaws.com:8080/ipfs/QmNs9ACzPfEuosCpyykHRHhMHphoeMeH6vq826k3LYoXyx

same as other IFPS gateways
https://ipfs.filebase.io/ipfs/QmNs9ACzPfEuosCpyykHRHhMHphoeMeH6vq826k3LYoXyx
https://ipfs.io/ipfs/QmNs9ACzPfEuosCpyykHRHhMHphoeMeH6vq826k3LYoXyx

Authentication, etc, can be setup in a future PR to add Ingress Controller support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to expose IPFS gateway externally Add option to expose the API externally.
3 participants