Skip to content

Commit

Permalink
fix: added unique names to all controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 committed Oct 9, 2024
1 parent cf7fd91 commit 9c5775b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 30 deletions.
6 changes: 3 additions & 3 deletions cmd/crd-replicator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ func main() {
clusterID, namespaceManager),
}
if err = d.SetupWithManager(mgr); err != nil {
klog.Error(err, "unable to setup the crdreplicator-operator")
klog.Error(err, "unable to setup the crdReplicator controller")
os.Exit(1)
}

klog.Info("Starting crdreplicator-operator")
klog.Info("Starting crdReplicator manager")
if err := mgr.Start(ctx); err != nil {
klog.Error(err, "problem running manager")
klog.Error(err, "unable to start the crdReplicator manager")
os.Exit(1)
}
}
8 changes: 3 additions & 5 deletions internal/crdReplicator/crdReplicator-operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import (
)

const (
operatorName = "crdReplicator-operator"
finalizer = "crdreplicator.liqo.io/operator"
finalizer = "crdreplicator.liqo.io/operator"
)

// Controller reconciles identity Secrets to start/stop the reflection of registered resources to remote clusters.
Expand Down Expand Up @@ -166,10 +165,9 @@ func (c *Controller) SetupWithManager(mgr ctrl.Manager) error {
return err
}

return ctrl.NewControllerManagedBy(mgr).
Named(operatorName).
WithEventFilter(resourceToBeProccesedPredicate).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlSecretsCRDReplicator).
For(&corev1.Secret{}, builder.WithPredicates(secretsFilter)).
WithEventFilter(resourceToBeProccesedPredicate).
Complete(c)
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/consts/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019-2024 The Liqo Authors
//
// 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 consts

// Constants used to name and identify controllers.
// Controller-runtime requires that each controller has a unique name within the container.
// This name is used, for example, to identify a controller univocally in the logs
// and must be a prometheus compatible name (underscores and alphanumeric characters only).
// As a convention to avoid conflicts, we use the name of the reconciled resource (lowercase version of their kind),
// and, if already used, we add a recognizable identifier, separated by the underscore character.
// To catch duplicated names, we name the constant as its value (in CamelCase and stripping the separator character),
// with the prefix "Ctrl".
const (
// Core.
CtrlSecretsCRDReplicator = "secrets_crdreplicator"

// Networking.
CtrlInternalFabricsFabric = "internalfabrics_fabric"
CtrlInternalFabricsCM = "internalfabrics_cm"

// Authentication.
CtrlResourceSlicesLocal = "resourceslices_local"
CtrlResourceSlicesRemote = "resourceslices_remote"

// Offloading.
CtrlShadowPods = "shadowpods"

// Cross modules.
CtrlResourceSlicesQuotaCreator = "resourceslices_quotacreator"
)
3 changes: 2 additions & 1 deletion pkg/fabric/internalfabric_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/utils/network/geneve"
)

Expand Down Expand Up @@ -126,7 +127,7 @@ func (r *InternalFabricReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// SetupWithManager register the InternalFabricReconciler to the manager.
func (r *InternalFabricReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlInternalFabricsFabric).
For(&networkingv1beta1.InternalFabric{}).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ import (
tenantnamespace "github.com/liqotech/liqo/pkg/tenantNamespace"
)

// ControllerName is the name of the controller.
const ControllerName = "localResourceSlice"

// NewLocalResourceSliceReconciler returns a new LocalResourceSliceReconciler.
func NewLocalResourceSliceReconciler(cl client.Client, s *runtime.Scheme,
recorder record.EventRecorder, liqoNamespace string,
Expand Down Expand Up @@ -120,7 +117,7 @@ func (r *LocalResourceSliceReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, err
}

if resourceSlice.Spec.CSR == nil || len(resourceSlice.Spec.CSR) == 0 {
if len(resourceSlice.Spec.CSR) == 0 {
// Generate a CSR for the remote cluster.
CSR, err := authentication.GenerateCSRForResourceSlice(privateKey, &resourceSlice)
if err != nil {
Expand Down Expand Up @@ -153,7 +150,7 @@ func (r *LocalResourceSliceReconciler) SetupWithManager(mgr ctrl.Manager) error
return err
}

return ctrl.NewControllerManagedBy(mgr).Named(ControllerName).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlResourceSlicesLocal).
For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(localResSliceFilter)).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ import (

authv1beta1 "github.com/liqotech/liqo/apis/authentication/v1beta1"
"github.com/liqotech/liqo/internal/crdReplicator/reflection"
"github.com/liqotech/liqo/pkg/consts"
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
"github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication"
"github.com/liqotech/liqo/pkg/utils/getters"
liqolabels "github.com/liqotech/liqo/pkg/utils/labels"
)

// ControllerName is the name of the controller.
const ControllerName = "remoteResourceSlice"

// NewRemoteResourceSliceReconciler returns a new RemoteResourceSliceReconciler.
func NewRemoteResourceSliceReconciler(cl client.Client, s *runtime.Scheme, config *rest.Config,
recorder record.EventRecorder,
Expand Down Expand Up @@ -257,7 +255,7 @@ func (r *RemoteResourceSliceReconciler) SetupWithManager(mgr ctrl.Manager) error
return err
}

return ctrl.NewControllerManagedBy(mgr).Named(ControllerName).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlResourceSlicesRemote).
For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(predicate.And(remoteResSliceFilter, withCSR()))).
Watches(&authv1beta1.Tenant{}, handler.EnqueueRequestsFromMapFunc(r.resourceSlicesEnquer())).
Complete(r)
Expand Down Expand Up @@ -300,7 +298,7 @@ func withCSR() predicate.Funcs {
if !ok {
return false
}
return rs.Spec.CSR != nil && len(rs.Spec.CSR) > 0
return len(rs.Spec.CSR) > 0
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func (r *InternalFabricReconciler) SetupWithManager(mgr ctrl.Manager) error {
},
)

return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlInternalFabricsCM).
For(&networkingv1beta1.InternalFabric{}).
Watches(&networkingv1beta1.InternalNode{}, internalNodeEnqueuer).
Owns(&networkingv1beta1.RouteConfiguration{}).
Owns(&networkingv1beta1.GeneveTunnel{}).
For(&networkingv1beta1.InternalFabric{}).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
UpdateFunc: func(_ event.UpdateEvent) bool { return true },
GenericFunc: func(_ event.GenericEvent) bool { return false },
}
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlShadowPods).
For(&offloadingv1beta1.ShadowPod{}).
Owns(&corev1.Pod{}, builder.WithPredicates(reconciledPredicates)).
WithOptions(controller.Options{MaxConcurrentReconciles: workers}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ import (
"github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication"
)

const (
// ControllerName is the name of the controller.
ControllerName = "quotaCreator"
)

// QuotaCreatorReconciler manage Quota lifecycle.
type QuotaCreatorReconciler struct {
client.Client
Expand Down Expand Up @@ -141,9 +136,8 @@ func (r *QuotaCreatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
klog.Error(err)
return err
}
return ctrl.NewControllerManagedBy(mgr).Named(ControllerName).
For(&authv1beta1.ResourceSlice{},
builder.WithPredicates(remoteResSliceFilter)).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlResourceSlicesQuotaCreator).
For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(remoteResSliceFilter)).
Owns(&offloadingv1beta1.Quota{}).
Complete(r)
}

0 comments on commit 9c5775b

Please sign in to comment.