Skip to content
6 changes: 6 additions & 0 deletions cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func RunController(_ *cobra.Command, _ []string) { // coverage-ignore
os.Exit(1)
}

resourceReconciler := controller.NewResourceReconciler(log, mgr, &operatorCfg)
if err := resourceReconciler.SetupWithManager(mgr, defaultCfg, log); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "PlatformMesh")
os.Exit(1)
}

if operatorCfg.PatchOIDCControllerEnabled {
realmReconciler := controller.NewRealmReconciler(mgr, log, &operatorCfg)
if err := realmReconciler.SetupWithManager(mgr, defaultCfg, log); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/platform-mesh/platform-mesh-operator
go 1.25.1

replace sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.19.0-kcp.1

replace ocm.software/open-component-model/kubernetes/controller => github.com/open-component-model/open-component-model/kubernetes/controller v0.0.0-20251104083903-c6d40af9889f
replace (
k8s.io/api => k8s.io/api v0.34.1
k8s.io/apimachinery => k8s.io/apimachinery v0.34.1
Expand Down
84 changes: 84 additions & 0 deletions internal/controller/resource_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"context"

pmconfig "github.com/platform-mesh/golang-commons/config"
"github.com/platform-mesh/golang-commons/controller/lifecycle/controllerruntime"
"github.com/platform-mesh/golang-commons/controller/lifecycle/subroutine"
"github.com/platform-mesh/golang-commons/logger"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/platform-mesh/platform-mesh-operator/internal/config"
"github.com/platform-mesh/platform-mesh-operator/pkg/subroutines/resource"
)

var (
resourceReconcilerName = "ResourceReconciler"
)

// ResourceReconciler reconciles a PlatformMesh object
type ResourceReconciler struct {
lifecycle *controllerruntime.LifecycleManager
}

var gvk = schema.GroupVersionKind{
Group: "delivery.ocm.software",
Version: "v1alpha1",
Kind: "Resource",
}

func (r *ResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)
return r.lifecycle.Reconcile(ctx, req, obj)
}

// SetupWithManager sets up the controller with the Manager.
func (r *ResourceReconciler) SetupWithManager(mgr ctrl.Manager, cfg *pmconfig.CommonServiceConfig,
log *logger.Logger, eventPredicates ...predicate.Predicate) error {

obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)

mgr.GetScheme().AddKnownTypeWithName(gvk, &unstructured.Unstructured{})
mgr.GetScheme().AddKnownTypeWithName(gvk.GroupVersion().WithKind(gvk.Kind+"List"), &unstructured.UnstructuredList{})

builder, err := r.lifecycle.SetupWithManagerBuilder(mgr, cfg.MaxConcurrentReconciles, resourceReconcilerName, obj,
cfg.DebugLabelValue, log, eventPredicates...)
if err != nil {
return err
}
return builder.Complete(r)
}

func NewResourceReconciler(log *logger.Logger, mgr ctrl.Manager, cfg *config.OperatorConfig) *ResourceReconciler {
var subs []subroutine.Subroutine

subs = append(subs, resource.NewResourceSubroutine(mgr))

return &ResourceReconciler{
lifecycle: controllerruntime.NewLifecycleManager(subs, operatorName,
resourceReconcilerName, mgr.GetClient(), log).WithReadOnly(),
}
}
Loading
Loading