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

Experimental update to generic reconciler-runtime #113

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctlr "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand All @@ -44,12 +43,11 @@ import (
//+kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;update;patch;delete

// ServiceBindingReconciler reconciles a ServiceBinding object
func ServiceBindingReconciler(c reconcilers.Config) *reconcilers.ResourceReconciler {
return &reconcilers.ResourceReconciler{
Type: &servicebindingv1beta1.ServiceBinding{},
Reconciler: &reconcilers.WithFinalizer{
func ServiceBindingReconciler(c reconcilers.Config) *reconcilers.ResourceReconciler[*servicebindingv1beta1.ServiceBinding] {
return &reconcilers.ResourceReconciler[*servicebindingv1beta1.ServiceBinding]{
Reconciler: &reconcilers.WithFinalizer[*servicebindingv1beta1.ServiceBinding]{
Finalizer: servicebindingv1beta1.GroupVersion.Group + "/finalizer",
Reconciler: reconcilers.Sequence{
Reconciler: reconcilers.Sequence[*servicebindingv1beta1.ServiceBinding]{
ResolveBindingSecret(),
ResolveWorkloads(),
ProjectBinding(),
Expand All @@ -61,8 +59,8 @@ func ServiceBindingReconciler(c reconcilers.Config) *reconcilers.ResourceReconci
}
}

func ResolveBindingSecret() reconcilers.SubReconciler {
return &reconcilers.SyncReconciler{
func ResolveBindingSecret() reconcilers.SubReconciler[*servicebindingv1beta1.ServiceBinding] {
return &reconcilers.SyncReconciler[*servicebindingv1beta1.ServiceBinding]{
Name: "ResolveBindingSecret",
Sync: func(ctx context.Context, resource *servicebindingv1beta1.ServiceBinding) error {
c := reconcilers.RetrieveConfigOrDie(ctx)
Expand Down Expand Up @@ -119,11 +117,11 @@ func ResolveBindingSecret() reconcilers.SubReconciler {
}
}

func ResolveWorkloads() reconcilers.SubReconciler {
return &reconcilers.SyncReconciler{
func ResolveWorkloads() reconcilers.SubReconciler[*servicebindingv1beta1.ServiceBinding] {
return &reconcilers.SyncReconciler[*servicebindingv1beta1.ServiceBinding]{
Name: "ResolveWorkloads",
SyncDuringFinalization: true,
Sync: func(ctx context.Context, resource *servicebindingv1beta1.ServiceBinding) (reconcile.Result, error) {
SyncWithResult: func(ctx context.Context, resource *servicebindingv1beta1.ServiceBinding) (reconcile.Result, error) {
c := reconcilers.RetrieveConfigOrDie(ctx)

ref := corev1.ObjectReference{
Expand Down Expand Up @@ -164,8 +162,8 @@ func ResolveWorkloads() reconcilers.SubReconciler {

//+kubebuilder:rbac:groups=servicebinding.io,resources=clusterworkloadresourcemappings,verbs=get;list;watch

func ProjectBinding() reconcilers.SubReconciler {
return &reconcilers.SyncReconciler{
func ProjectBinding() reconcilers.SubReconciler[*servicebindingv1beta1.ServiceBinding] {
return &reconcilers.SyncReconciler[*servicebindingv1beta1.ServiceBinding]{
Name: "ProjectBinding",
SyncDuringFinalization: true,
Sync: func(ctx context.Context, resource *servicebindingv1beta1.ServiceBinding) error {
Expand Down Expand Up @@ -201,16 +199,15 @@ func ProjectBinding() reconcilers.SubReconciler {
}
}

func PatchWorkloads() reconcilers.SubReconciler {
workloadManager := &reconcilers.ResourceManager{
func PatchWorkloads() reconcilers.SubReconciler[*servicebindingv1beta1.ServiceBinding] {
workloadManager := &reconcilers.ResourceManager[*unstructured.Unstructured]{
Name: "PatchWorkloads",
Type: &unstructured.Unstructured{},
MergeBeforeUpdate: func(current, desired *unstructured.Unstructured) {
current.SetUnstructuredContent(desired.UnstructuredContent())
},
}

return &reconcilers.SyncReconciler{
return &reconcilers.SyncReconciler[*servicebindingv1beta1.ServiceBinding]{
Name: "PatchWorkloads",
SyncDuringFinalization: true,
Sync: func(ctx context.Context, resource *servicebindingv1beta1.ServiceBinding) error {
Expand All @@ -222,8 +219,8 @@ func PatchWorkloads() reconcilers.SubReconciler {
}

for i := range workloads {
workload := workloads[i].(client.Object)
projectedWorkload := projectedWorkloads[i].(client.Object)
workload := workloads[i].(*unstructured.Unstructured)
projectedWorkload := projectedWorkloads[i].(*unstructured.Unstructured)
if workload.GetUID() != projectedWorkload.GetUID() || workload.GetResourceVersion() != projectedWorkload.GetResourceVersion() {
panic(fmt.Errorf("workload and projectedWorkload must have the same uid and resourceVersion"))
}
Expand Down
Loading