Skip to content

Migrate all backend controllers to controller-runtime#274

Merged
mjudeikis merged 1 commit into
kbind-dev:mainfrom
mjudeikis:mjudeikis/ctrl.runtime.part3.2
Aug 12, 2025
Merged

Migrate all backend controllers to controller-runtime#274
mjudeikis merged 1 commit into
kbind-dev:mainfrom
mjudeikis:mjudeikis/ctrl.runtime.part3.2

Conversation

@mjudeikis

@mjudeikis mjudeikis commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

Summary

Migrate all controllers to controller-runtime

What Type of PR Is This?

/kind cleanup
/kind feature

Related Issue(s)

Fixes #267

Release Notes

Migrate backend to controller-runtime

@mjudeikis mjudeikis marked this pull request as ready for review August 9, 2025 12:19
@mjudeikis mjudeikis requested a review from a team as a code owner August 9, 2025 12:19
Comment thread cmd/example-backend/main.go Outdated
}
var exports []*kubebindv1alpha2.APIServiceExport
for i := range list.Items {
if list.Items[i].Namespace == ns || ns == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we support clusterscoped and namespaced mode for the same resource? The original code didn't do it, did it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

{
NamespacedName: types.NamespacedName{
Namespace: serviceExport.Namespace,
Name: "cluster", // This matches the original logic: ns + "/cluster"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed duplicates

Comment thread contrib/example-backend/controllers/serviceexport/serviceexport_controller.go Outdated
Comment thread contrib/example-backend/controllers/serviceexport/serviceexport_controller.go Outdated
return false
// Update status if it has changed
if !reflect.DeepEqual(original, apiServiceExport) {
err := r.Update(ctx, apiServiceExport)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we already have original and updated object, we could send a smart patch here instead of an update.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

wdym? What is smart patch?

Comment thread contrib/example-backend/controllers/serviceexport/serviceexport_controller.go Outdated
errs = append(errs, err)
// Update status if it has changed
if !reflect.DeepEqual(original.Status, apiServiceExportRequest.Status) {
err := r.Status().Update(ctx, apiServiceExportRequest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here we indeed update the status subresource.

Comment thread contrib/example-backend/server.go Outdated
Comment thread contrib/example-backend/server.go Outdated
Comment thread contrib/example-backend/server.go Outdated
Comment thread contrib/example-backend/server.go Outdated
Comment thread contrib/example-backend/server.go Outdated
}

// IndexServiceExportByCustomResourceDefinitionControllerRuntime is a controller-runtime compatible indexer function
// that indexes APIServiceExports by their CustomResourceDefinition name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks though as if APIServiceExports are indexed by their name, not their CRD's name. Is that the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This stinks. I think this is wrong (old and new ones, both). Thanks for poking this.

Comment thread pkg/indexers/serviceexportrequest.go Outdated
Comment thread apiserviceexport.yaml Outdated
@mjudeikis mjudeikis force-pushed the mjudeikis/ctrl.runtime.part3.2 branch 4 times, most recently from 3821c18 to f737f1f Compare August 11, 2025 19:09
@xrstf

xrstf commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

/lgtm

@xrstf xrstf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

under the assumption that my review comments are adressed later

Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt>
On-behalf-of: @SAP mangirdas.judeikis@sap.com
@mjudeikis mjudeikis force-pushed the mjudeikis/ctrl.runtime.part3.2 branch from f737f1f to 778d030 Compare August 11, 2025 19:14
@mjudeikis

Copy link
Copy Markdown
Contributor Author

TODO:

  • move rest of the clients to move client
  • check what is happening with apiserviceexport index

@mjudeikis mjudeikis enabled auto-merge (squash) August 12, 2025 06:10
@mjudeikis mjudeikis disabled auto-merge August 12, 2025 06:10
@mjudeikis mjudeikis merged commit 800c89a into kbind-dev:main Aug 12, 2025
9 checks passed
mjudeikis added a commit to mjudeikis/kube-bind that referenced this pull request Aug 18, 2025
On-behalf-of: @SAP mangirdas.judeikis@sap.com

Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt>
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.

Refactor KubeBind to work with Multicluster-runtime

2 participants