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 authored and adamjensenbot committed Oct 14, 2024
1 parent e2bba7b commit a087118
Show file tree
Hide file tree
Showing 52 changed files with 157 additions and 123 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)
}
}
3 changes: 2 additions & 1 deletion cmd/liqo-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
"github.com/liqotech/liqo/pkg/ipam"
remoteresourceslicecontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller"
foreignclustercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/foreigncluster-controller"
foreignclustercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/core/foreigncluster-controller"
ipmapping "github.com/liqotech/liqo/pkg/liqo-controller-manager/ipmapping"
quotacreatorcontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/quotacreator-controller"
virtualnodecreatorcontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/virtualnodecreator-controller"
Expand Down Expand Up @@ -393,6 +393,7 @@ func main() {
}
}

// CORE OPERATORS
// Configure the foreigncluster controller.
idManager := identitymanager.NewCertificateIdentityManager(ctx, mgr.GetClient(), clientset, mgr.GetConfig(), clusterID, namespaceManager)
foreignClusterReconciler := &foreignclustercontroller.ForeignClusterReconciler{
Expand Down
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.CtrlSecretCRDReplicator).
For(&corev1.Secret{}, builder.WithPredicates(secretsFilter)).
WithEventFilter(resourceToBeProccesedPredicate).
Complete(c)
}

Expand Down
80 changes: 80 additions & 0 deletions pkg/consts/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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.
CtrlForeignCluster = "foreigncluster"
CtrlSecretCRDReplicator = "secret_crdreplicator" //nolint:gosec // not a credential

// Networking.
CtrlConfigurationExternal = "configuration_external"
CtrlConfigurationInternal = "configuration_internal"
CtrlConfigurationRemapping = "configuration_remapping"
CtrlConfigurationRoute = "configuration_route"
CtrlConnection = "connection"
CtrlFirewallConfiguration = "firewallconfiguration"
CtrlGatewayClientExternal = "gatewayclient_external"
CtrlGatewayClientInternal = "gatewayclient_internal"
CtrlGatewayServerExternal = "gatewayserver_external"
CtrlGatewayServerInternal = "gatewayserver_internal"
CtrlInternalFabricCM = "internalfabric_cm"
CtrlInternalFabricFabric = "internalfabric_fabric"
CtrlInternalNodeGeneve = "internalnode_geneve"
CtrlInternalNodeRoute = "internalnode_route"
CtrlIP = "ip"
CtrlIPRemapping = "ip_remapping"
CtrlNetwork = "network"
CtrlNode = "node"
CtrlPodGateway = "pod_gateway"
CtrlPodGwMasq = "pod_gw_masq"
CtrlPodInternalNet = "pod_internalnet"
CtrlPublicKey = "publickey"
CtrlRouteConfiguration = "routeconfiguration"
CtrlWGGatewayClient = "wggatewayclient"
CtrlWGGatewayServer = "wggatewayserver"

// Authentication.
CtrlIdentity = "identity"
CtrlIdentityCreator = "identity_creator"
CtrlSecretNonceCreator = "secret_noncecreator"
CtrlSecretNonceSigner = "secret_noncesigner"
CtrlResourceSliceLocal = "resourceslice_local"
CtrlResourceSliceRemote = "resourceslice_remote"
CtrlTenant = "tenant"

// Offloading.
CtrlNamespaceMap = "namespacemap"
CtrlNamespaceOffloading = "namespaceoffloading"
CtrlNodeFailure = "node_failure"
CtrlPodStatus = "pod_status"
CtrlShadowEndpointSlice = "shadowendpointslice"
CtrlShadowPod = "shadowpod"
CtrlVirtualNode = "virtualnode"

// Cross modules.
CtrlResourceSliceQuotaCreator = "resourceslice_quotacreator"
CtrlResourceSliceVNCreator = "resourceslice_vncreator"
CtrlPodIPMapping = "pod_ipmapping"
CtrlConfigurationIPMapping = "configuration_ipmapping"
)
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.CtrlInternalFabricFabric).
For(&networkingv1beta1.InternalFabric{}).
Complete(r)
}
3 changes: 2 additions & 1 deletion pkg/fabric/source-detector/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/fabric"
"github.com/liqotech/liqo/pkg/gateway"
)
Expand Down Expand Up @@ -115,7 +116,7 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPodGateway).
For(&corev1.Pod{}, builder.WithPredicates(filterByLabelsGatewayPods)).
Complete(r)
}
3 changes: 2 additions & 1 deletion pkg/firewall/firewallconfiguration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

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

Expand Down Expand Up @@ -172,7 +173,7 @@ func (r *FirewallConfigurationReconciler) SetupWithManager(ctx context.Context,
go func() {
utilruntime.Must(netmonitor.InterfacesMonitoring(ctx, src, &netmonitor.Options{Nftables: &netmonitor.OptionsNftables{Delete: true}}))
}()
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlFirewallConfiguration).
For(&networkingv1beta1.FirewallConfiguration{}, builder.WithPredicates(filterByLabelsPredicate)).
WatchesRawSource(NewFirewallWatchSource(src, NewFirewallWatchEventHandler(r.Client, r.LabelsSets))).
Complete(r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/connection/connections_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *ConnectionsReconciler) SetupWithManager(mgr ctrl.Manager) error {
if err != nil {
return err
}
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConnection).
For(&networkingv1beta1.Connection{}, builder.WithPredicates(filterByLabelsPredicate)).
Complete(r)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/gateway/fabric/geneve/internalnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/gateway/fabric"
"github.com/liqotech/liqo/pkg/utils/network/geneve"
)
Expand Down Expand Up @@ -116,7 +117,7 @@ func (r *InternalNodeReconciler) Reconcile(ctx context.Context, req ctrl.Request

// SetupWithManager register the InternalNodeReconciler to the manager.
func (r *InternalNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlInternalNodeGeneve).
For(&networkingv1beta1.InternalNode{}).
Complete(r)
}
2 changes: 1 addition & 1 deletion pkg/gateway/tunnel/wireguard/publickeys_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *PublicKeysReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager register the ConfigurationReconciler to the manager.
func (r *PublicKeysReconciler) SetupWithManager(mgr ctrl.Manager, src <-chan event.GenericEvent) error {
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPublicKey).
For(&networkingv1beta1.PublicKey{}, r.Predicates()).
WatchesRawSource(NewDNSSource(src, NewDNSEventHandler(r.Client, r.Options))).
Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

authv1beta1 "github.com/liqotech/liqo/apis/authentication/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication"
"github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication/forge"
)
Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *IdentityReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c

// SetupWithManager sets up the controller with the Manager.
func (r *IdentityReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlIdentity).
For(&authv1beta1.Identity{}).
Owns(&corev1.Secret{}).
Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *IdentityCreatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return err
}

return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlIdentityCreator).
For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(predicate.And(localResSliceFilter, withAuthCondition()))).
Owns(&authv1beta1.Identity{}).
Complete(r)
Expand Down
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.CtrlResourceSliceLocal).
For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(localResSliceFilter)).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (r *NonceCreatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return selector.Matches(labels.Set(o.GetLabels()))
})

return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlSecretNonceCreator).
For(&corev1.Secret{}, builder.WithPredicates(filter)).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ import (
"github.com/liqotech/liqo/pkg/utils"
)

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

// NewNonceSignerReconciler returns a new SecretReconciler.
func NewNonceSignerReconciler(cl client.Client, s *runtime.Scheme,
recorder record.EventRecorder,
Expand Down Expand Up @@ -153,7 +148,7 @@ func (r *NonceSignerReconciler) SetupWithManager(mgr ctrl.Manager) error {
return selector.Matches(labels.Set(o.GetLabels()))
})

return ctrl.NewControllerManagedBy(mgr).Named(ControllerName).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlSecretNonceSigner).
For(&corev1.Secret{}, builder.WithPredicates(filter)).
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.CtrlResourceSliceRemote).
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 @@ -263,7 +263,7 @@ func (r *TenantReconciler) ensureSetup(ctx context.Context) error {

// SetupWithManager sets up the TenantReconciler with the Manager.
func (r *TenantReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlTenant).
For(&authv1beta1.Tenant{}).
Owns(&corev1.Namespace{}).
Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (r *ForeignClusterReconciler) SetupWithManager(mgr ctrl.Manager, workers in
return err
}

return ctrl.NewControllerManagedBy(mgr).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlForeignCluster).
For(&liqov1beta1.ForeignCluster{}, builder.WithPredicates(foreignClusterPredicate)).
Watches(&networkingv1beta1.Connection{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).
Watches(&networkingv1beta1.GatewayServer{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ import (
configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration"
)

// ConfigurationControllerName is the name of the controller.
const ConfigurationControllerName = "IpMappingConfiguration"

// cluster-role
// +kubebuilder:rbac:groups=networking.liqo.io,resources=configurations,verbs=get;list;watch
// +kubebuilder:rbac:groups=ipam.liqo.io,resources=ips,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -98,7 +95,7 @@ func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error {
if err != nil {
return err
}
return ctrl.NewControllerManagedBy(mgr).Named(ConfigurationControllerName).
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConfigurationIPMapping).
For(&networkingv1beta1.Configuration{}, builder.WithPredicates(filterByLabelsPredicate)).
Complete(r)
}
Expand Down
Loading

0 comments on commit a087118

Please sign in to comment.