diff --git a/cmd/liqo-controller-manager/main.go b/cmd/liqo-controller-manager/main.go index 45ebc85cb1..48add3e4df 100644 --- a/cmd/liqo-controller-manager/main.go +++ b/cmd/liqo-controller-manager/main.go @@ -47,7 +47,7 @@ import ( "github.com/liqotech/liqo/cmd/liqo-controller-manager/modules" "github.com/liqotech/liqo/pkg/consts" identitymanager "github.com/liqotech/liqo/pkg/identityManager" - ipam "github.com/liqotech/liqo/pkg/ipamold" + "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/core/foreigncluster-controller" ipmapping "github.com/liqotech/liqo/pkg/liqo-controller-manager/ipmapping" @@ -248,7 +248,7 @@ func main() { // NETWORKING MODULE if *networkingEnabled { // Connect to the IPAM server if specified. - var ipamClient ipam.IpamClient + var ipamClient ipam.IPAMClient if *ipamServer != "" { klog.Infof("connecting to the IPAM server %q", *ipamServer) conn, err := grpc.NewClient(*ipamServer, grpc.WithTransportCredentials(insecure.NewCredentials())) @@ -257,7 +257,7 @@ func main() { os.Exit(1) } defer conn.Close() - ipamClient = ipam.NewIpamClient(conn) + ipamClient = ipam.NewIPAMClient(conn) } if err := modules.SetupNetworkingModule(ctx, mgr, &modules.NetworkingOption{ diff --git a/cmd/liqo-controller-manager/modules/networking.go b/cmd/liqo-controller-manager/modules/networking.go index eef9619e81..69397723fc 100644 --- a/cmd/liqo-controller-manager/modules/networking.go +++ b/cmd/liqo-controller-manager/modules/networking.go @@ -21,7 +21,7 @@ import ( "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/manager" - ipam "github.com/liqotech/liqo/pkg/ipamold" + "github.com/liqotech/liqo/pkg/ipam" clientoperator "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/client-operator" configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration" "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/remapping" @@ -35,8 +35,6 @@ import ( nodecontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/node-controller" "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/route" internalservercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/server-controller" - ipctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/ip-controller" - networkctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/network-controller" dynamicutils "github.com/liqotech/liqo/pkg/utils/dynamic" ) @@ -46,7 +44,7 @@ type NetworkingOption struct { Factory *dynamicutils.RunnableFactory LiqoNamespace string - IpamClient ipam.IpamClient + IpamClient ipam.IPAMClient GatewayServerResources []string GatewayClientResources []string @@ -61,21 +59,23 @@ type NetworkingOption struct { } // SetupNetworkingModule setup the networking module and initializes its controllers . -func SetupNetworkingModule(ctx context.Context, mgr manager.Manager, opts *NetworkingOption) error { - networkReconciler := networkctrl.NewNetworkReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient) - if err := networkReconciler.SetupWithManager(mgr, opts.NetworkWorkers); err != nil { - klog.Errorf("Unable to start the networkReconciler: %v", err) - return err - } - - ipReconciler := ipctrl.NewIPReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient) - if err := ipReconciler.SetupWithManager(ctx, mgr, opts.IPWorkers); err != nil { - klog.Errorf("Unable to start the ipReconciler: %v", err) - return err - } +func SetupNetworkingModule(_ context.Context, mgr manager.Manager, opts *NetworkingOption) error { + // TODO: refactor network reconciler with the new IPAM client. + // networkReconciler := networkctrl.NewNetworkReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient) + // if err := networkReconciler.SetupWithManager(mgr, opts.NetworkWorkers); err != nil { + // klog.Errorf("Unable to start the networkReconciler: %v", err) + // return err + // } + + // TODO: refactor IP reconciler with the new IPAM client. + // ipReconciler := ipctrl.NewIPReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient) + // if err := ipReconciler.SetupWithManager(ctx, mgr, opts.IPWorkers); err != nil { + // klog.Errorf("Unable to start the ipReconciler: %v", err) + // return err + // } cfgReconciler := configuration.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), - mgr.GetEventRecorderFor("configuration-controller"), opts.IpamClient) + mgr.GetEventRecorderFor("configuration-controller")) if err := cfgReconciler.SetupWithManager(mgr); err != nil { klog.Errorf("unable to create controller configurationReconciler: %s", err) return err 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 ba453b4e35..07b7a7eab1 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 @@ -28,7 +28,6 @@ import ( ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1" "github.com/liqotech/liqo/pkg/consts" - ipam "github.com/liqotech/liqo/pkg/ipamold" "github.com/liqotech/liqo/pkg/utils/events" ipamutils "github.com/liqotech/liqo/pkg/utils/ipam" ) @@ -39,19 +38,17 @@ type ConfigurationReconciler struct { Scheme *runtime.Scheme EventsRecorder record.EventRecorder - localCIDR *networkingv1beta1.ClusterConfigCIDR - ipamClient ipam.IpamClient + localCIDR *networkingv1beta1.ClusterConfigCIDR } // NewConfigurationReconciler returns a new ConfigurationReconciler. -func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder, ipamClient ipam.IpamClient) *ConfigurationReconciler { +func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder) *ConfigurationReconciler { return &ConfigurationReconciler{ Client: cl, Scheme: s, EventsRecorder: er, - localCIDR: nil, - ipamClient: ipamClient, + localCIDR: nil, } } @@ -73,42 +70,31 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques } if configuration.Spec.Local == nil { - err := r.defaultLocalNetwork(ctx, configuration) - if err != nil { + if err := r.defaultLocalNetwork(ctx, configuration); err != nil { return ctrl.Result{}, err } } - events.Event(r.EventsRecorder, configuration, "Processing") + events.Event(r.EventsRecorder, configuration, "Processing configuration") - err := r.RemapConfiguration(ctx, configuration, r.EventsRecorder) - if err != nil { + if err := r.RemapConfiguration(ctx, configuration, r.EventsRecorder); err != nil { return ctrl.Result{}, err } - if err = r.UpdateConfigurationStatus(ctx, configuration); err != nil { + if err := r.UpdateConfigurationStatus(ctx, configuration); err != nil { return ctrl.Result{}, err } if !isConfigurationConfigured(configuration) { - events.Event(r.EventsRecorder, configuration, "Waiting for the network to be ready") + events.Event(r.EventsRecorder, configuration, "Waiting for all networks to be ready") } else { - // Set the subnets for the remote cluster. - if configuration.Labels != nil && configuration.Labels[consts.RemoteClusterID] != "" { - if _, err := r.ipamClient.SetSubnetsPerCluster(ctx, &ipam.SetSubnetsPerClusterRequest{ - RemappedPodCIDR: configuration.Status.Remote.CIDR.Pod.String(), - RemappedExternalCIDR: configuration.Status.Remote.CIDR.External.String(), - ClusterID: configuration.Labels[consts.RemoteClusterID], - }); err != nil { - return ctrl.Result{}, fmt.Errorf("unable to set subnets per cluster: %w", err) - } - } - events.Event(r.EventsRecorder, configuration, "Configuration remapped") - err = SetConfigurationConfigured(ctx, r.Client, configuration) + if err := SetConfigurationConfigured(ctx, r.Client, configuration); err != nil { + return ctrl.Result{}, fmt.Errorf("unable to set configuration %q as configured: %w", req.NamespacedName, err) + } } - return ctrl.Result{}, err + return ctrl.Result{}, nil } func (r *ConfigurationReconciler) defaultLocalNetwork(ctx context.Context, cfg *networkingv1beta1.Configuration) error {