-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: rcfeat_add_api_types_for_external_load_b
Are you sure you want to change the base?
feat: add controller for external load balancer #101
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
- 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.
@@ -20,19 +20,30 @@ spec: | |||
apiVersion: controlplane.cluster.x-k8s.io/v1beta1 | |||
name: "${CLUSTER_NAME}-control-plane" | |||
--- | |||
# ExternalLoadBalancer Definition |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we do
api/v1alpha1/microvmcluster_types.go
Outdated
@@ -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"` |
There was a problem hiding this comment.
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?? |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
b277f16
to
66b8c53
Compare
Signed-off-by: Richard Case <[email protected]>
Signed-off-by: Richard Case <[email protected]>
This PR is stale because it has been open 30 days with no activity. |
We still need to finish this. |
What this PR does / why we need it:
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: