Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPAM] Refactor configuration controller #2807

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/liqo-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()))
Expand All @@ -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{
Expand Down
34 changes: 17 additions & 17 deletions cmd/liqo-controller-manager/modules/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

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

LiqoNamespace string
IpamClient ipam.IpamClient
IpamClient ipam.IPAMClient

GatewayServerResources []string
GatewayClientResources []string
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
}
}

Expand All @@ -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 {
Expand Down