Migrate all backend controllers to controller-runtime#274
Conversation
| } | ||
| var exports []*kubebindv1alpha2.APIServiceExport | ||
| for i := range list.Items { | ||
| if list.Items[i].Namespace == ns || ns == "" { |
There was a problem hiding this comment.
Why do we support clusterscoped and namespaced mode for the same resource? The original code didn't do it, did it?
| { | ||
| NamespacedName: types.NamespacedName{ | ||
| Namespace: serviceExport.Namespace, | ||
| Name: "cluster", // This matches the original logic: ns + "/cluster" |
There was a problem hiding this comment.
This comment might be less useful after this is merged, maybe it should just be a review comment. Same for other "original logic" comments.
| logger.Error(err, "Failed to update ClusterBinding status") | ||
| return ctrl.Result{}, fmt.Errorf("failed to update ClusterBinding status: %w", err) | ||
| } | ||
| logger.Info("ClusterBinding status updated", "namespace", clusterBinding.Namespace, "name", clusterBinding.Name) |
There was a problem hiding this comment.
Instead of duplicating context here, why not extend the logger := log.FromContext(ctx) part to store some context on the local logger. Then all the other log messages, like logger.Info("ClusterBinding not found, ignoring"), are also properly annotated.
There was a problem hiding this comment.
removed duplicates
| return false | ||
| // Update status if it has changed | ||
| if !reflect.DeepEqual(original, apiServiceExport) { | ||
| err := r.Update(ctx, apiServiceExport) |
There was a problem hiding this comment.
If we already have original and updated object, we could send a smart patch here instead of an update.
There was a problem hiding this comment.
wdym? What is smart patch?
| errs = append(errs, err) | ||
| // Update status if it has changed | ||
| if !reflect.DeepEqual(original.Status, apiServiceExportRequest.Status) { | ||
| err := r.Status().Update(ctx, apiServiceExportRequest) |
There was a problem hiding this comment.
Here we indeed update the status subresource.
| } | ||
|
|
||
| // IndexServiceExportByCustomResourceDefinitionControllerRuntime is a controller-runtime compatible indexer function | ||
| // that indexes APIServiceExports by their CustomResourceDefinition name. |
There was a problem hiding this comment.
It looks though as if APIServiceExports are indexed by their name, not their CRD's name. Is that the same?
There was a problem hiding this comment.
This stinks. I think this is wrong (old and new ones, both). Thanks for poking this.
3821c18 to
f737f1f
Compare
|
/lgtm |
Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt> On-behalf-of: @SAP mangirdas.judeikis@sap.com
f737f1f to
778d030
Compare
|
TODO:
|
On-behalf-of: @SAP mangirdas.judeikis@sap.com Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt>
Summary
Migrate all controllers to controller-runtime
What Type of PR Is This?
/kind cleanup
/kind feature
Related Issue(s)
Fixes #267
Release Notes