Skip to content

Commit 9305522

Browse files
committed
refactor: updated Configuration controller for new Ipam
1 parent 1654760 commit 9305522

File tree

3 files changed

+32
-46
lines changed

3 files changed

+32
-46
lines changed

cmd/liqo-controller-manager/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
"github.com/liqotech/liqo/cmd/liqo-controller-manager/modules"
4848
"github.com/liqotech/liqo/pkg/consts"
4949
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
50-
ipam "github.com/liqotech/liqo/pkg/ipamold"
50+
"github.com/liqotech/liqo/pkg/ipam"
5151
remoteresourceslicecontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication/remoteresourceslice-controller"
5252
foreignclustercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/core/foreigncluster-controller"
5353
ipmapping "github.com/liqotech/liqo/pkg/liqo-controller-manager/ipmapping"
@@ -248,7 +248,7 @@ func main() {
248248
// NETWORKING MODULE
249249
if *networkingEnabled {
250250
// Connect to the IPAM server if specified.
251-
var ipamClient ipam.IpamClient
251+
var ipamClient ipam.IPAMClient
252252
if *ipamServer != "" {
253253
klog.Infof("connecting to the IPAM server %q", *ipamServer)
254254
conn, err := grpc.NewClient(*ipamServer, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -257,7 +257,7 @@ func main() {
257257
os.Exit(1)
258258
}
259259
defer conn.Close()
260-
ipamClient = ipam.NewIpamClient(conn)
260+
ipamClient = ipam.NewIPAMClient(conn)
261261
}
262262

263263
if err := modules.SetupNetworkingModule(ctx, mgr, &modules.NetworkingOption{

cmd/liqo-controller-manager/modules/networking.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"k8s.io/klog/v2"
2222
"sigs.k8s.io/controller-runtime/pkg/manager"
2323

24-
ipam "github.com/liqotech/liqo/pkg/ipamold"
24+
"github.com/liqotech/liqo/pkg/ipam"
2525
clientoperator "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/client-operator"
2626
configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration"
2727
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/remapping"
@@ -35,8 +35,6 @@ import (
3535
nodecontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/node-controller"
3636
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/route"
3737
internalservercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/internal-network/server-controller"
38-
ipctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/ip-controller"
39-
networkctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/network-controller"
4038
dynamicutils "github.com/liqotech/liqo/pkg/utils/dynamic"
4139
)
4240

@@ -46,7 +44,7 @@ type NetworkingOption struct {
4644
Factory *dynamicutils.RunnableFactory
4745

4846
LiqoNamespace string
49-
IpamClient ipam.IpamClient
47+
IpamClient ipam.IPAMClient
5048

5149
GatewayServerResources []string
5250
GatewayClientResources []string
@@ -61,21 +59,23 @@ type NetworkingOption struct {
6159
}
6260

6361
// SetupNetworkingModule setup the networking module and initializes its controllers .
64-
func SetupNetworkingModule(ctx context.Context, mgr manager.Manager, opts *NetworkingOption) error {
65-
networkReconciler := networkctrl.NewNetworkReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient)
66-
if err := networkReconciler.SetupWithManager(mgr, opts.NetworkWorkers); err != nil {
67-
klog.Errorf("Unable to start the networkReconciler: %v", err)
68-
return err
69-
}
70-
71-
ipReconciler := ipctrl.NewIPReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient)
72-
if err := ipReconciler.SetupWithManager(ctx, mgr, opts.IPWorkers); err != nil {
73-
klog.Errorf("Unable to start the ipReconciler: %v", err)
74-
return err
75-
}
62+
func SetupNetworkingModule(_ context.Context, mgr manager.Manager, opts *NetworkingOption) error {
63+
// TODO: refactor network reconciler with the new IPAM client.
64+
// networkReconciler := networkctrl.NewNetworkReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient)
65+
// if err := networkReconciler.SetupWithManager(mgr, opts.NetworkWorkers); err != nil {
66+
// klog.Errorf("Unable to start the networkReconciler: %v", err)
67+
// return err
68+
// }
69+
70+
// TODO: refactor IP reconciler with the new IPAM client.
71+
// ipReconciler := ipctrl.NewIPReconciler(mgr.GetClient(), mgr.GetScheme(), opts.IpamClient)
72+
// if err := ipReconciler.SetupWithManager(ctx, mgr, opts.IPWorkers); err != nil {
73+
// klog.Errorf("Unable to start the ipReconciler: %v", err)
74+
// return err
75+
// }
7676

7777
cfgReconciler := configuration.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(),
78-
mgr.GetEventRecorderFor("configuration-controller"), opts.IpamClient)
78+
mgr.GetEventRecorderFor("configuration-controller"))
7979
if err := cfgReconciler.SetupWithManager(mgr); err != nil {
8080
klog.Errorf("unable to create controller configurationReconciler: %s", err)
8181
return err

pkg/liqo-controller-manager/networking/external-network/configuration/configuration_controller.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1"
2929
networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
3030
"github.com/liqotech/liqo/pkg/consts"
31-
ipam "github.com/liqotech/liqo/pkg/ipamold"
3231
"github.com/liqotech/liqo/pkg/utils/events"
3332
ipamutils "github.com/liqotech/liqo/pkg/utils/ipam"
3433
)
@@ -39,19 +38,17 @@ type ConfigurationReconciler struct {
3938
Scheme *runtime.Scheme
4039
EventsRecorder record.EventRecorder
4140

42-
localCIDR *networkingv1beta1.ClusterConfigCIDR
43-
ipamClient ipam.IpamClient
41+
localCIDR *networkingv1beta1.ClusterConfigCIDR
4442
}
4543

4644
// NewConfigurationReconciler returns a new ConfigurationReconciler.
47-
func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder, ipamClient ipam.IpamClient) *ConfigurationReconciler {
45+
func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder) *ConfigurationReconciler {
4846
return &ConfigurationReconciler{
4947
Client: cl,
5048
Scheme: s,
5149
EventsRecorder: er,
5250

53-
localCIDR: nil,
54-
ipamClient: ipamClient,
51+
localCIDR: nil,
5552
}
5653
}
5754

@@ -73,42 +70,31 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
7370
}
7471

7572
if configuration.Spec.Local == nil {
76-
err := r.defaultLocalNetwork(ctx, configuration)
77-
if err != nil {
73+
if err := r.defaultLocalNetwork(ctx, configuration); err != nil {
7874
return ctrl.Result{}, err
7975
}
8076
}
8177

82-
events.Event(r.EventsRecorder, configuration, "Processing")
78+
events.Event(r.EventsRecorder, configuration, "Processing configuration")
8379

84-
err := r.RemapConfiguration(ctx, configuration, r.EventsRecorder)
85-
if err != nil {
80+
if err := r.RemapConfiguration(ctx, configuration, r.EventsRecorder); err != nil {
8681
return ctrl.Result{}, err
8782
}
8883

89-
if err = r.UpdateConfigurationStatus(ctx, configuration); err != nil {
84+
if err := r.UpdateConfigurationStatus(ctx, configuration); err != nil {
9085
return ctrl.Result{}, err
9186
}
9287

9388
if !isConfigurationConfigured(configuration) {
94-
events.Event(r.EventsRecorder, configuration, "Waiting for the network to be ready")
89+
events.Event(r.EventsRecorder, configuration, "Waiting for all networks to be ready")
9590
} else {
96-
// Set the subnets for the remote cluster.
97-
if configuration.Labels != nil && configuration.Labels[consts.RemoteClusterID] != "" {
98-
if _, err := r.ipamClient.SetSubnetsPerCluster(ctx, &ipam.SetSubnetsPerClusterRequest{
99-
RemappedPodCIDR: configuration.Status.Remote.CIDR.Pod.String(),
100-
RemappedExternalCIDR: configuration.Status.Remote.CIDR.External.String(),
101-
ClusterID: configuration.Labels[consts.RemoteClusterID],
102-
}); err != nil {
103-
return ctrl.Result{}, fmt.Errorf("unable to set subnets per cluster: %w", err)
104-
}
105-
}
106-
10791
events.Event(r.EventsRecorder, configuration, "Configuration remapped")
108-
err = SetConfigurationConfigured(ctx, r.Client, configuration)
92+
if err := SetConfigurationConfigured(ctx, r.Client, configuration); err != nil {
93+
return ctrl.Result{}, fmt.Errorf("unable to set configuration %q as configured: %w", req.NamespacedName, err)
94+
}
10995
}
11096

111-
return ctrl.Result{}, err
97+
return ctrl.Result{}, nil
11298
}
11399

114100
func (r *ConfigurationReconciler) defaultLocalNetwork(ctx context.Context, cfg *networkingv1beta1.Configuration) error {

0 commit comments

Comments
 (0)