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: add controller for external load balancer #101

Open
wants to merge 7 commits into
base: rcfeat_add_api_types_for_external_load_b
Choose a base branch
from

Conversation

richardcase
Copy link
Member

@richardcase richardcase commented Jan 19, 2022

What this PR does / why we need it:

  • The controller does a simple HTTP get on the endpoint.
  • Any non-5xx response is acceptable.
  • The MvmCluster checks the endpointRef for it's ready status
  • If it is not ready, it requeues the reconciliation.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Relates #90

Special notes for your reviewer:

Checklist:

  • adds unit tests

@richardcase
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@richardcase richardcase added the kind/feature New feature or request label Jan 19, 2022
- The controller does a simple HTTP get on the endpoint.
- Any non-5xx response is acceptable.
- The MvmCluster checks the endpointRef for it's ready status
- If it is not ready, it requeues the reconciliation.
@github-actions github-actions bot added size/m and removed size/s labels Jan 25, 2022
@jmickey jmickey marked this pull request as ready for review January 25, 2022 11:01
@@ -20,19 +20,30 @@ spec:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
name: "${CLUSTER_NAME}-control-plane"
---
# ExternalLoadBalancer Definition
Copy link
Member

Choose a reason for hiding this comment

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

do we need to do the same in cluster-template-cilium.yaml?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we do

@@ -25,6 +19,8 @@ type MicrovmClusterSpec struct {
// Placement specifies how machines for the cluster should be placed onto hosts (i.e. where the microvms are created).
// +kubebuilder:validation:Required
Placement Placement `json:"placement"`
// EndpointRef
EndpointRef *corev1.ObjectReference `json:"endpointRef,omitempty"`
Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably be LoadBalancerRef or something more descriptive.

}

if ownerRef := loadbalancer.GetOwnerReferences(); len(ownerRef) == 0 {
// What should we do here if the OwnerReference is empty, simply requeue??
Copy link
Member Author

Choose a reason for hiding this comment

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

I would do a debug log and then requeue.

Timeout: defaultHTTPTimeout,
}

epReq, err := http.NewRequestWithContext(ctx, http.MethodGet, loadbalancer.Spec.Endpoint.String(), nil)
Copy link
Member Author

Choose a reason for hiding this comment

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

Could we move the actual testing of the endpoint to a separate function?

return ctrl.Result{}, nil
}

client := &http.Client{
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we be passing in a interface of some sort for the http client so that we can mock it for tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been thinking a bit more about this, perhaps we could use the remote client and the secret to actually connect....this would require a small change....lets chat today.

Copy link

Choose a reason for hiding this comment

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

Haha, we did talk about this before. It's ok I know how to make this change!


epReq, err := http.NewRequestWithContext(ctx, http.MethodGet, loadbalancer.Spec.Endpoint.String(), nil)
if err != nil {
log.Error(err, "creating endpoint request", "id", req.NamespacedName)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should return from reconciliation with the error as well.

infrav1 "github.com/weaveworks/cluster-api-provider-microvm/api/v1alpha1"
)

type ExternalLoadBalancerReconciler struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

We could do with some unit tests to cover this controller.

Copy link

Choose a reason for hiding this comment

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

I thought about this and mentioned as much in slack. Happy to add tests but there isn't a huge amount to actually test. Outside of the HTTP call it's mostly basic logic. Probably worth doing it anyway - will add some.

@@ -51,6 +51,7 @@ type MicrovmClusterReconciler struct {
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=microvmclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=microvmclusters/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=microvmclusters/finalizers,verbs=update
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=externalloadbalancerendpoint,verbs=get;list;watch
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be externalloadbalancers instead?

remoteClient, err := r.RemoteClientGetter(ctx, clusterScope.ClusterName(), r.Client, clusterKey)
if err != nil {
clusterScope.Error(err, "creating remote cluster client")
if err := r.Get(ctx, eprnn, endpoint); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

If we get the endpoint i think we need to ensure the owner reference is set on it using EnsureOwnerRef. This would then require we patch the loadbalancer kind.

Copy link
Member Author

Choose a reason for hiding this comment

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

That could also be done in the ExternalLoadBalancer controller but that would required we have a cluster name field (or something similar)

@@ -20,19 +20,30 @@ spec:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
name: "${CLUSTER_NAME}-control-plane"
---
# ExternalLoadBalancer Definition
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we do


type ExternalLoadBalancerReconciler struct {
client.Client
Scheme *runtime.Scheme
Copy link
Member Author

Choose a reason for hiding this comment

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

We need a SetupWithManager for this new controller and that will need to be called from main

Among a variety of other changes.

- Patch is called earlier and we now have a
ExternalLoadBalancerEndpointAvailableCondition that we can use to convey
failure information.
- Rather than simply checking the OwnerReferences the ClusterName is
used to ensure the owner reference exists.
- Added SetupWithManager method which is called from main.
- Moved test request logic to separate function. The test request now
calls the {ENDPOINT}/livez which should reach the Kubernetes API server
@jmickey jmickey force-pushed the rcfeat_add_controller_for_external_load_ branch from b277f16 to 66b8c53 Compare February 9, 2022 12:37
Signed-off-by: Richard Case <richard@weave.works>
Signed-off-by: Richard Case <richard@weave.works>
@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 13, 2022
@richardcase
Copy link
Member Author

We still need to finish this.

@Callisto13 Callisto13 removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants