diff --git a/cmd/crd-replicator/main.go b/cmd/crd-replicator/main.go index 65c8e9b3e1..813902c7d8 100644 --- a/cmd/crd-replicator/main.go +++ b/cmd/crd-replicator/main.go @@ -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) } } diff --git a/internal/crdReplicator/crdReplicator-operator.go b/internal/crdReplicator/crdReplicator-operator.go index f33a3a1be1..35954fe221 100644 --- a/internal/crdReplicator/crdReplicator-operator.go +++ b/internal/crdReplicator/crdReplicator-operator.go @@ -45,8 +45,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. @@ -188,10 +187,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) } diff --git a/pkg/consts/controllers.go b/pkg/consts/controllers.go new file mode 100644 index 0000000000..201d80aed7 --- /dev/null +++ b/pkg/consts/controllers.go @@ -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" + CtrlSecretsCRDReplicator = "secrets_crdreplicator" + + // Networking. + CtrlConfigurationExternal = "configuration_external" + CtrlConfigurationInternal = "configuration_internal" + CtrlConfigurationIPMapping = "configuration_ipmapping" + CtrlConfigurationRemapping = "configuration_remapping" + CtrlConfigurationRoute = "configuration_route" + CtrlConnections = "connections" + CtrlFirewallConfiguration = "firewallconfiguration" + CtrlGatewayClientExternal = "gatewayclient_external" + CtrlGatewayClientInternal = "gatewayclient_internal" + CtrlGatewayServerExternal = "gatewayserver_external" + CtrlGatewayServerInternal = "gatewayserver_internal" + CtrlInternalFabricsCM = "internalfabrics_cm" + CtrlInternalFabricsFabric = "internalfabrics_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" + CtrlPodIPMapping = "pod_ipmapping" + CtrlPulicKeys = "publickeys" + CtrlRouteConfiguration = "routeconfiguration" + CtrlWGGatewayClient = "wggatewayclient" + CtrlWGGatewayServer = "wggatewayserver" + + // Authentication. + CtrlIdentity = "identity" + CtrlIdentityCreator = "identity_creator" + CtrlNonceCreator = "nonce_creator" + CtrlNonceSigner = "nonce_signer" + CtrlResourceSlicesLocal = "resourceslices_local" + CtrlResourceSlicesRemote = "resourceslices_remote" + CtrlTenant = "tenant" + + // Offloading. + CtrlNamespaceMap = "namespace_map" + CtrlNamespaceOffloading = "namespaceoffloading" + CtrlNodeFailure = "node_failure" + CtrlPodStatus = "pod_status" + CtrlShadowEndpointSlice = "shadowendpointslice" + CtrlShadowPods = "shadowpods" + CtrlVirtualNode = "virtualnode" + CtrlVirtualNodeCreator = "virtualnode_creator" + + // Cross modules. + CtrlResourceSlicesQuotaCreator = "resourceslices_quotacreator" +) diff --git a/pkg/fabric/internalfabric_controller.go b/pkg/fabric/internalfabric_controller.go index 575c6822ca..b3e43b7115 100644 --- a/pkg/fabric/internalfabric_controller.go +++ b/pkg/fabric/internalfabric_controller.go @@ -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" ) @@ -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) } diff --git a/pkg/fabric/source-detector/gateway_controller.go b/pkg/fabric/source-detector/gateway_controller.go index 52a0e140a6..063c1cfc2b 100644 --- a/pkg/fabric/source-detector/gateway_controller.go +++ b/pkg/fabric/source-detector/gateway_controller.go @@ -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" ) @@ -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) } diff --git a/pkg/firewall/firewallconfiguration_controller.go b/pkg/firewall/firewallconfiguration_controller.go index 241a958064..5c730cfb8a 100644 --- a/pkg/firewall/firewallconfiguration_controller.go +++ b/pkg/firewall/firewallconfiguration_controller.go @@ -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" ) @@ -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) diff --git a/pkg/gateway/connection/connections_controller.go b/pkg/gateway/connection/connections_controller.go index f6c498094c..b4d3120fd4 100644 --- a/pkg/gateway/connection/connections_controller.go +++ b/pkg/gateway/connection/connections_controller.go @@ -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.CtrlConnections). For(&networkingv1beta1.Connection{}, builder.WithPredicates(filterByLabelsPredicate)). Complete(r) } diff --git a/pkg/gateway/fabric/geneve/internalnode_controller.go b/pkg/gateway/fabric/geneve/internalnode_controller.go index 6bd2094730..a1df76394d 100644 --- a/pkg/gateway/fabric/geneve/internalnode_controller.go +++ b/pkg/gateway/fabric/geneve/internalnode_controller.go @@ -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" ) @@ -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) } diff --git a/pkg/gateway/tunnel/wireguard/publickeys_controller.go b/pkg/gateway/tunnel/wireguard/publickeys_controller.go index dbd88f5857..5aac92f129 100644 --- a/pkg/gateway/tunnel/wireguard/publickeys_controller.go +++ b/pkg/gateway/tunnel/wireguard/publickeys_controller.go @@ -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.CtrlPulicKeys). For(&networkingv1beta1.PublicKey{}, r.Predicates()). WatchesRawSource(NewDNSSource(src, NewDNSEventHandler(r.Client, r.Options))). Complete(r) diff --git a/pkg/liqo-controller-manager/authentication/identity-controller/identity_controller.go b/pkg/liqo-controller-manager/authentication/identity-controller/identity_controller.go index 35891e0b0d..58ac9b1683 100644 --- a/pkg/liqo-controller-manager/authentication/identity-controller/identity_controller.go +++ b/pkg/liqo-controller-manager/authentication/identity-controller/identity_controller.go @@ -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" ) @@ -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) diff --git a/pkg/liqo-controller-manager/authentication/identitycreator-controller/identitycreator_controller.go b/pkg/liqo-controller-manager/authentication/identitycreator-controller/identitycreator_controller.go index 44f953fbde..1bdf1f44da 100644 --- a/pkg/liqo-controller-manager/authentication/identitycreator-controller/identitycreator_controller.go +++ b/pkg/liqo-controller-manager/authentication/identitycreator-controller/identitycreator_controller.go @@ -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) diff --git a/pkg/liqo-controller-manager/authentication/localresourceslice-controller/localresourceslice_controller.go b/pkg/liqo-controller-manager/authentication/localresourceslice-controller/localresourceslice_controller.go index be80e3547f..3f9a0d9f54 100644 --- a/pkg/liqo-controller-manager/authentication/localresourceslice-controller/localresourceslice_controller.go +++ b/pkg/liqo-controller-manager/authentication/localresourceslice-controller/localresourceslice_controller.go @@ -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, @@ -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 { @@ -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) } diff --git a/pkg/liqo-controller-manager/authentication/noncecreator-controller/noncecreator_controller.go b/pkg/liqo-controller-manager/authentication/noncecreator-controller/noncecreator_controller.go index 40c232afd6..226c0c35cb 100644 --- a/pkg/liqo-controller-manager/authentication/noncecreator-controller/noncecreator_controller.go +++ b/pkg/liqo-controller-manager/authentication/noncecreator-controller/noncecreator_controller.go @@ -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.CtrlNonceCreator). For(&corev1.Secret{}, builder.WithPredicates(filter)). Complete(r) } diff --git a/pkg/liqo-controller-manager/authentication/noncesigner-controller/noncesigner_controller.go b/pkg/liqo-controller-manager/authentication/noncesigner-controller/noncesigner_controller.go index fb0e4da2ac..b9e00679eb 100644 --- a/pkg/liqo-controller-manager/authentication/noncesigner-controller/noncesigner_controller.go +++ b/pkg/liqo-controller-manager/authentication/noncesigner-controller/noncesigner_controller.go @@ -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, @@ -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.CtrlNonceSigner). For(&corev1.Secret{}, builder.WithPredicates(filter)). Complete(r) } diff --git a/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller/remoteresourceslice_controller.go b/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller/remoteresourceslice_controller.go index ef3474a85d..b3712f595d 100644 --- a/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller/remoteresourceslice_controller.go +++ b/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller/remoteresourceslice_controller.go @@ -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, @@ -258,7 +256,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) @@ -301,7 +299,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 }) } diff --git a/pkg/liqo-controller-manager/authentication/tenant-controller/tenant_controller.go b/pkg/liqo-controller-manager/authentication/tenant-controller/tenant_controller.go index 639a7762e0..3df78e2b27 100644 --- a/pkg/liqo-controller-manager/authentication/tenant-controller/tenant_controller.go +++ b/pkg/liqo-controller-manager/authentication/tenant-controller/tenant_controller.go @@ -269,7 +269,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) diff --git a/pkg/liqo-controller-manager/foreigncluster-controller/foreigncluster_controller.go b/pkg/liqo-controller-manager/foreigncluster-controller/foreigncluster_controller.go index 6870a43e02..764df12403 100644 --- a/pkg/liqo-controller-manager/foreigncluster-controller/foreigncluster_controller.go +++ b/pkg/liqo-controller-manager/foreigncluster-controller/foreigncluster_controller.go @@ -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)). diff --git a/pkg/liqo-controller-manager/ipmapping/configuration_controller.go b/pkg/liqo-controller-manager/ipmapping/configuration_controller.go index 6ecf942a61..75a232abb5 100644 --- a/pkg/liqo-controller-manager/ipmapping/configuration_controller.go +++ b/pkg/liqo-controller-manager/ipmapping/configuration_controller.go @@ -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 @@ -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) } diff --git a/pkg/liqo-controller-manager/ipmapping/pod_controller.go b/pkg/liqo-controller-manager/ipmapping/pod_controller.go index 57a111f245..e300bb8bca 100644 --- a/pkg/liqo-controller-manager/ipmapping/pod_controller.go +++ b/pkg/liqo-controller-manager/ipmapping/pod_controller.go @@ -33,11 +33,6 @@ import ( "github.com/liqotech/liqo/pkg/consts" ) -const ( - // PodControllerName is the name of the controller. - PodControllerName = "IPMappingPod" -) - // OffloadedPodReconciler manage offloaded pods lifecycle. type OffloadedPodReconciler struct { client.Client @@ -93,7 +88,7 @@ func (r *OffloadedPodReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return fmt.Errorf("unable to create predicate: %w", err) } - return ctrl.NewControllerManagedBy(mgr).Named(PodControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPodIPMapping). For(&corev1.Pod{}, builder.WithPredicates(p)). Complete(r) } diff --git a/pkg/liqo-controller-manager/networking/external-network/client-operator/client_controller.go b/pkg/liqo-controller-manager/networking/external-network/client-operator/client_controller.go index 7cda778f4b..1bb66106a6 100644 --- a/pkg/liqo-controller-manager/networking/external-network/client-operator/client_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/client-operator/client_controller.go @@ -267,7 +267,7 @@ func (r *ClientReconciler) SetupWithManager(mgr ctrl.Manager) error { factorySource.ForResource(gvr) } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlGatewayClientExternal). WatchesRawSource(factorySource.Source(ownerEnqueuer)). For(&networkingv1beta1.GatewayClient{}). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go b/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go index 16aec0a4b8..803f323e77 100644 --- a/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go @@ -187,7 +187,7 @@ func isConfigurationConfigured(cfg *networkingv1beta1.Configuration) bool { // SetupWithManager register the ConfigurationReconciler to the manager. func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConfigurationExternal). For(&networkingv1beta1.Configuration{}). Owns(&ipamv1alpha1.Network{}). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go b/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go index 590c599663..34b530daa8 100644 --- a/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/remapping/configuration_controller.go @@ -29,6 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + "github.com/liqotech/liqo/pkg/consts" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" ) @@ -48,9 +49,6 @@ type RemappingReconciler struct { Options *Options } -// ConfigurationControllerName is the name of the controller. -const ConfigurationControllerName = "configurationRemapping" - // NewRemappingReconciler returns a new PublicKeysReconciler. func NewRemappingReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder) (*RemappingReconciler, error) { opts, err := NewOptions() @@ -104,7 +102,7 @@ func (r *RemappingReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr).Named(ConfigurationControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConfigurationRemapping). For(&networkingv1beta1.Configuration{}, builder.WithPredicates(filterByLabelsPredicate)). Complete(r) } diff --git a/pkg/liqo-controller-manager/networking/external-network/remapping/ip_controller.go b/pkg/liqo-controller-manager/networking/external-network/remapping/ip_controller.go index dafc93e851..4116545297 100644 --- a/pkg/liqo-controller-manager/networking/external-network/remapping/ip_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/remapping/ip_controller.go @@ -32,11 +32,6 @@ import ( "github.com/liqotech/liqo/pkg/consts" ) -const ( - // IPControllerName is the name of the controller. - IPControllerName = "ipMapping" -) - // IPReconciler manage IP. type IPReconciler struct { client.Client @@ -113,7 +108,7 @@ func (r *IPReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr).Named(IPControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlIPRemapping). For(&ipamv1alpha1.IP{}, builder.WithPredicates(predicate.Not(filterByLabelsPredicate))). Complete(r) } diff --git a/pkg/liqo-controller-manager/networking/external-network/route/configuration_controller.go b/pkg/liqo-controller-manager/networking/external-network/route/configuration_controller.go index 5badc6d90a..73d0dbf9cd 100644 --- a/pkg/liqo-controller-manager/networking/external-network/route/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/route/configuration_controller.go @@ -31,14 +31,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + "github.com/liqotech/liqo/pkg/consts" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" "github.com/liqotech/liqo/pkg/utils" "github.com/liqotech/liqo/pkg/utils/getters" ) -// ControllerName is the name of the controller. -const ControllerName = "externalConfiguration" - // ConfigurationReconciler manage Configuration. type ConfigurationReconciler struct { client.Client @@ -93,7 +91,7 @@ func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConfigurationRoute). For(&networkingv1beta1.Configuration{}, builder.WithPredicates(p)). Watches( &networkingv1beta1.GatewayServer{}, diff --git a/pkg/liqo-controller-manager/networking/external-network/server-operator/server_controller.go b/pkg/liqo-controller-manager/networking/external-network/server-operator/server_controller.go index f01dd37035..5cb3da658e 100644 --- a/pkg/liqo-controller-manager/networking/external-network/server-operator/server_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/server-operator/server_controller.go @@ -271,7 +271,7 @@ func (r *ServerReconciler) SetupWithManager(mgr ctrl.Manager) error { factorySource.ForResource(gvr) } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlGatewayServerExternal). WatchesRawSource(factorySource.Source(ownerEnqueuer)). For(&networkingv1beta1.GatewayServer{}). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go index 5024662514..cd8f28aa37 100644 --- a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayclient_controller.go @@ -158,7 +158,7 @@ func (r *WgGatewayClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ // SetupWithManager register the WgGatewayClientReconciler to the manager. func (r *WgGatewayClientReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlWGGatewayClient). For(&networkingv1beta1.WgGatewayClient{}). Owns(&appsv1.Deployment{}). Owns(&corev1.ServiceAccount{}). diff --git a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go index 5f1d3476be..fde1c09237 100644 --- a/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go +++ b/pkg/liqo-controller-manager/networking/external-network/wireguard/wggatewayserver_controller.go @@ -171,7 +171,7 @@ func (r *WgGatewayServerReconciler) Reconcile(ctx context.Context, req ctrl.Requ // SetupWithManager register the WgGatewayServerReconciler to the manager. func (r *WgGatewayServerReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlWGGatewayServer). For(&networkingv1beta1.WgGatewayServer{}). Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). diff --git a/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go b/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go index 7784e7d953..76c1ed7474 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/client-controller/client_controller.go @@ -35,11 +35,6 @@ import ( "github.com/liqotech/liqo/pkg/utils/getters" ) -const ( - // ControllerName is the name of the controller. - ControllerName = "internalClient" -) - // ClientReconciler manage GatewayClient lifecycle. type ClientReconciler struct { client.Client @@ -148,7 +143,7 @@ func (r *ClientReconciler) ensureInternalFabric(ctx context.Context, gwClient *n // SetupWithManager register the ClientReconciler to the manager. func (r *ClientReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlGatewayClientInternal). Owns(&networkingv1beta1.InternalFabric{}). For(&networkingv1beta1.GatewayClient{}). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/configuration_controller.go b/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/configuration_controller.go index 2822896e98..79cae8bd72 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/configuration_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/configuration-controller/configuration_controller.go @@ -27,12 +27,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + "github.com/liqotech/liqo/pkg/consts" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" ) -// ControllerName is the name of the controller. -const ControllerName = "internalConfiguration" - // ConfigurationReconciler manage Configuration lifecycle. type ConfigurationReconciler struct { client.Client @@ -91,7 +89,7 @@ func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlConfigurationInternal). For(&networkingv1beta1.Configuration{}, builder.WithPredicates(p)). Complete(r) } diff --git a/pkg/liqo-controller-manager/networking/internal-network/gw-masq-bypass/pod_controller.go b/pkg/liqo-controller-manager/networking/internal-network/gw-masq-bypass/pod_controller.go index 56c05c295c..32ba8d97c1 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/gw-masq-bypass/pod_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/gw-masq-bypass/pod_controller.go @@ -33,6 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" + "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/gateway" ) @@ -117,7 +118,7 @@ func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPodGwMasq). For(&corev1.Pod{}, builder.WithPredicates(p)). WatchesRawSource(NewLeftoverPodsSource(r.GenericEvents, NewLeftoverPodsEventHandler())). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/internal-network/internalfabric-controller/internalfabric_controller.go b/pkg/liqo-controller-manager/networking/internal-network/internalfabric-controller/internalfabric_controller.go index fbf87dd000..a80246d3dd 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/internalfabric-controller/internalfabric_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/internalfabric-controller/internalfabric_controller.go @@ -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) } diff --git a/pkg/liqo-controller-manager/networking/internal-network/node-controller/node_controller.go b/pkg/liqo-controller-manager/networking/internal-network/node-controller/node_controller.go index 4afda2c734..42b2dc0840 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/node-controller/node_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/node-controller/node_controller.go @@ -120,7 +120,7 @@ func (r *NodeReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlNode). Owns(&networkingv1beta1.InternalNode{}). For(&corev1.Node{}, builder.WithPredicates(predicate.Not(filterByLabelsPredicate))). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_controller.go b/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_controller.go index d31eb96dda..be54509baa 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/route/internalnode_controller.go @@ -31,6 +31,7 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/ipam/utils" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" "github.com/liqotech/liqo/pkg/utils/getters" @@ -150,7 +151,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.CtrlInternalNodeRoute). For(&networkingv1beta1.InternalNode{}). Watches(&networkingv1beta1.Configuration{}, handler.EnqueueRequestsFromMapFunc(r.genericEnqueuerfunc)). Watches(&ipamv1alpha1.IP{}, handler.EnqueueRequestsFromMapFunc(r.genericEnqueuerfunc)). diff --git a/pkg/liqo-controller-manager/networking/internal-network/route/pod_controller.go b/pkg/liqo-controller-manager/networking/internal-network/route/pod_controller.go index 3271f2f60d..5e2699b1e6 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/route/pod_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/route/pod_controller.go @@ -122,7 +122,7 @@ func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error { if err != nil { return err } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPodInternalNet). For(&corev1.Pod{}, builder.WithPredicates(predicate.Not(p))). WatchesRawSource(NewLeftoverPodsSource(r.GenericEvents, NewLeftoverPodsEventHandler())). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go b/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go index 0cc9515288..b94a5cbae6 100644 --- a/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go +++ b/pkg/liqo-controller-manager/networking/internal-network/server-controller/server_controller.go @@ -35,11 +35,6 @@ import ( "github.com/liqotech/liqo/pkg/utils/getters" ) -const ( - // ControllerName is the name of the controller. - ControllerName = "internalServer" -) - // ServerReconciler manage GatewayServer lifecycle. type ServerReconciler struct { client.Client @@ -149,7 +144,7 @@ func (r *ServerReconciler) ensureInternalFabric(ctx context.Context, gwServer *n // SetupWithManager register the ServerReconciler to the manager. func (r *ServerReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlGatewayServerInternal). Owns(&networkingv1beta1.InternalFabric{}). For(&networkingv1beta1.GatewayServer{}). Complete(r) diff --git a/pkg/liqo-controller-manager/networking/ip-controller/ip_controller.go b/pkg/liqo-controller-manager/networking/ip-controller/ip_controller.go index a10fb7694d..be0a234dba 100644 --- a/pkg/liqo-controller-manager/networking/ip-controller/ip_controller.go +++ b/pkg/liqo-controller-manager/networking/ip-controller/ip_controller.go @@ -34,6 +34,7 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" + "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/ipam" "github.com/liqotech/liqo/pkg/utils/getters" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" @@ -184,7 +185,7 @@ func (r *IPReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, w return requests } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlIP). For(&ipamv1alpha1.IP{}). Owns(&v1.Service{}). Owns(&discoveryv1.EndpointSlice{}). diff --git a/pkg/liqo-controller-manager/networking/network-controller/network_controller.go b/pkg/liqo-controller-manager/networking/network-controller/network_controller.go index d7eaf66c5a..4dba6f995f 100644 --- a/pkg/liqo-controller-manager/networking/network-controller/network_controller.go +++ b/pkg/liqo-controller-manager/networking/network-controller/network_controller.go @@ -27,6 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" + "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/ipam" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" ) @@ -92,7 +93,7 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // SetupWithManager monitors Network resources. func (r *NetworkReconciler) SetupWithManager(mgr ctrl.Manager, workers int) error { - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlNetwork). For(&ipamv1alpha1.Network{}). WithOptions(controller.Options{MaxConcurrentReconciles: workers}). Complete(r) diff --git a/pkg/liqo-controller-manager/offloading/namespacemap-controller/namespacemap_controller.go b/pkg/liqo-controller-manager/offloading/namespacemap-controller/namespacemap_controller.go index efa36a772b..ec9b09927b 100644 --- a/pkg/liqo-controller-manager/offloading/namespacemap-controller/namespacemap_controller.go +++ b/pkg/liqo-controller-manager/offloading/namespacemap-controller/namespacemap_controller.go @@ -33,7 +33,7 @@ import ( offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" "github.com/liqotech/liqo/internal/crdReplicator/reflection" - liqoconst "github.com/liqotech/liqo/pkg/consts" + "github.com/liqotech/liqo/pkg/consts" ) // NamespaceMapReconciler creates remote namespaces and updates NamespaceMaps Status. @@ -95,7 +95,7 @@ func (r *NamespaceMapReconciler) SetupWithManager(mgr ctrl.Manager) error { utilruntime.Must(err) enqueuer := func(_ context.Context, obj client.Object) []reconcile.Request { - nm, found := obj.GetAnnotations()[liqoconst.RemoteNamespaceManagedByAnnotationKey] + nm, found := obj.GetAnnotations()[consts.RemoteNamespaceManagedByAnnotationKey] if !found { return nil } @@ -109,7 +109,7 @@ func (r *NamespaceMapReconciler) SetupWithManager(mgr ctrl.Manager) error { return []reconcile.Request{{NamespacedName: types.NamespacedName{Namespace: namespace, Name: name}}} } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlNamespaceMap). For(&offloadingv1beta1.NamespaceMap{}, builder.WithPredicates(filter)). // It is not possible to use Owns, since a namespaced object cannot own a non-namespaced one, // and cross namespace owners are disallowed by design. diff --git a/pkg/liqo-controller-manager/offloading/namespaceoffloading-controller/namespaceoffloading_controller.go b/pkg/liqo-controller-manager/offloading/namespaceoffloading-controller/namespaceoffloading_controller.go index 2475b57ab2..1a986a682a 100644 --- a/pkg/liqo-controller-manager/offloading/namespaceoffloading-controller/namespaceoffloading_controller.go +++ b/pkg/liqo-controller-manager/offloading/namespaceoffloading-controller/namespaceoffloading_controller.go @@ -33,6 +33,7 @@ import ( liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" + "github.com/liqotech/liqo/pkg/consts" liqoconst "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/utils/syncset" ) @@ -131,7 +132,7 @@ func (r *NamespaceOffloadingReconciler) SetupWithManager(mgr ctrl.Manager) error return object.GetName() == liqoconst.DefaultNamespaceOffloadingName }) - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlNamespaceOffloading). For(&offloadingv1beta1.NamespaceOffloading{}, builder.WithPredicates(filter)). Watches(&offloadingv1beta1.NamespaceMap{}, r.namespaceMapHandlers()). Watches(&offloadingv1beta1.VirtualNode{}, r.enqueueAll()). diff --git a/pkg/liqo-controller-manager/offloading/nodefailure-controller/nodefailure_controller.go b/pkg/liqo-controller-manager/offloading/nodefailure-controller/nodefailure_controller.go index 3356499d6e..72777a78af 100644 --- a/pkg/liqo-controller-manager/offloading/nodefailure-controller/nodefailure_controller.go +++ b/pkg/liqo-controller-manager/offloading/nodefailure-controller/nodefailure_controller.go @@ -110,7 +110,7 @@ func getPodTerminatingEventHandler() handler.EventHandler { // SetupWithManager monitors updates on nodes and watch for pods that are terminating and managed by a ShadowPod. func (r *NodeFailureReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlNodeFailure). For(&corev1.Node{}). Watches(&corev1.Pod{}, getPodTerminatingEventHandler()). Complete(r) diff --git a/pkg/liqo-controller-manager/offloading/podstatus-controller/podstatus_controller.go b/pkg/liqo-controller-manager/offloading/podstatus-controller/podstatus_controller.go index e0b5df9068..d667d3bd9c 100644 --- a/pkg/liqo-controller-manager/offloading/podstatus-controller/podstatus_controller.go +++ b/pkg/liqo-controller-manager/offloading/podstatus-controller/podstatus_controller.go @@ -29,11 +29,6 @@ import ( "github.com/liqotech/liqo/pkg/utils/indexer" ) -const ( - // ControllerName is the name of the controller. - ControllerName = "podStatus" -) - // HasRemoteUnavailableLabel return true if the pod has the remote unavailable label. func HasRemoteUnavailableLabel(pod *corev1.Pod) bool { value, ok := pod.Labels[consts.RemoteUnavailableKey] @@ -115,7 +110,7 @@ func (r *PodStatusReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // SetupWithManager monitors updates on nodes. func (r *PodStatusReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlPodStatus). For(&corev1.Node{}). Complete(r) } diff --git a/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller.go b/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller.go index f6f1ab9c92..347bfb8ba7 100644 --- a/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller.go +++ b/pkg/liqo-controller-manager/offloading/shadowendpointslice-controller/shadowendpointslice_controller.go @@ -38,7 +38,7 @@ import ( liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1" offloadingv1beta1 "github.com/liqotech/liqo/apis/offloading/v1beta1" - liqoconsts "github.com/liqotech/liqo/pkg/consts" + "github.com/liqotech/liqo/pkg/consts" "github.com/liqotech/liqo/pkg/utils" clientutils "github.com/liqotech/liqo/pkg/utils/clients" foreigncluster "github.com/liqotech/liqo/pkg/utils/foreigncluster" @@ -113,7 +113,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu Name: shadowEps.Name, Namespace: shadowEps.Namespace, Labels: labels.Merge(shadowEps.Labels, labels.Set{ - liqoconsts.ManagedByLabelKey: liqoconsts.ManagedByShadowEndpointSliceValue}), + consts.ManagedByLabelKey: consts.ManagedByShadowEndpointSliceValue}), Annotations: shadowEps.Annotations, }, AddressType: shadowEps.Spec.Template.AddressType, @@ -244,7 +244,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, wor GenericFunc: func(_ event.GenericEvent) bool { return false }, } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlShadowEndpointSlice). For(&offloadingv1beta1.ShadowEndpointSlice{}). Owns(&discoveryv1.EndpointSlice{}). Watches(&liqov1beta1.ForeignCluster{}, diff --git a/pkg/liqo-controller-manager/offloading/shadowpod-controller/shadowpod_controller.go b/pkg/liqo-controller-manager/offloading/shadowpod-controller/shadowpod_controller.go index 6ba8427e62..16f1d788a2 100644 --- a/pkg/liqo-controller-manager/offloading/shadowpod-controller/shadowpod_controller.go +++ b/pkg/liqo-controller-manager/offloading/shadowpod-controller/shadowpod_controller.go @@ -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}). diff --git a/pkg/liqo-controller-manager/offloading/virtualnode-controller/virtualnode_controller.go b/pkg/liqo-controller-manager/offloading/virtualnode-controller/virtualnode_controller.go index 791ff31b5a..27d2f6f686 100644 --- a/pkg/liqo-controller-manager/offloading/virtualnode-controller/virtualnode_controller.go +++ b/pkg/liqo-controller-manager/offloading/virtualnode-controller/virtualnode_controller.go @@ -199,7 +199,7 @@ func (r *VirtualNodeReconciler) SetupWithManager(mgr ctrl.Manager) error { klog.Error(err) return err } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlVirtualNode). For(&offloadingv1beta1.VirtualNode{}). Watches(&appsv1.Deployment{}, deploymentHandler, builder.WithPredicates(deployPredicate)). Watches(&offloadingv1beta1.NamespaceMap{}, r.enqueFromNamespaceMap()). diff --git a/pkg/liqo-controller-manager/quotacreator-controller/quotacreator_controller.go b/pkg/liqo-controller-manager/quotacreator-controller/quotacreator_controller.go index a841604ab4..bcc0298b7c 100644 --- a/pkg/liqo-controller-manager/quotacreator-controller/quotacreator_controller.go +++ b/pkg/liqo-controller-manager/quotacreator-controller/quotacreator_controller.go @@ -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 @@ -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) } diff --git a/pkg/liqo-controller-manager/virtualnodecreator-controller/virtualnodecreator_controller.go b/pkg/liqo-controller-manager/virtualnodecreator-controller/virtualnodecreator_controller.go index 09c47132c4..a6146a486d 100644 --- a/pkg/liqo-controller-manager/virtualnodecreator-controller/virtualnodecreator_controller.go +++ b/pkg/liqo-controller-manager/virtualnodecreator-controller/virtualnodecreator_controller.go @@ -39,11 +39,6 @@ import ( "github.com/liqotech/liqo/pkg/utils/getters" ) -const ( - // ControllerName is the name of the controller. - ControllerName = "virtualNodeCreator" -) - // VirtualNodeCreatorReconciler create virtualnodes from resourceslice resources. type VirtualNodeCreatorReconciler struct { client.Client @@ -149,7 +144,7 @@ func (r *VirtualNodeCreatorReconciler) SetupWithManager(mgr ctrl.Manager) error klog.Error(err) return err } - return ctrl.NewControllerManagedBy(mgr).Named(ControllerName). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlVirtualNodeCreator). For(&authv1beta1.ResourceSlice{}, builder.WithPredicates(predicate.And(localResSliceFilter, withConditionsAccepeted()))). Owns(&offloadingv1beta1.VirtualNode{}). Owns(&authv1beta1.Identity{}). diff --git a/pkg/route/routeconfiguration_controller.go b/pkg/route/routeconfiguration_controller.go index bbcb2764b0..c91805524d 100644 --- a/pkg/route/routeconfiguration_controller.go +++ b/pkg/route/routeconfiguration_controller.go @@ -34,6 +34,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" ) @@ -191,7 +192,7 @@ func (r *RouteConfigurationReconciler) SetupWithManager(ctx context.Context, mgr return err } - return ctrl.NewControllerManagedBy(mgr). + return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlRouteConfiguration). For(&networkingv1beta1.RouteConfiguration{}, builder.WithPredicates(filterByLabelsPredicate)). WatchesRawSource(NewRouteWatchSource(src, NewRouteWatchEventHandler(r.Client, r.LabelsSets))). Complete(r)