Skip to content

Commit

Permalink
fixup! tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli committed Oct 4, 2023
1 parent 838fe87 commit aa7aadf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apis/networking/v1alpha1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ClusterConfig struct {
// ConfigurationSpec defines the desired state of Configuration.
type ConfigurationSpec struct {
// Local network configuration (the cluster where the resource is created).
Local ClusterConfig `json:"local,omitempty"`
Local *ClusterConfig `json:"local,omitempty"`
// Remote network configuration (the other cluster).
Remote ClusterConfig `json:"remote,omitempty"`
}
Expand Down
8 changes: 6 additions & 2 deletions apis/networking/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cmd/liqo-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func main() {
"The frequency of the ForeignCluster API server readiness check. Set 0 to disable the check")
foreignClusterPingTimeout := flag.Duration("foreign-cluster-ping-timeout", 5*time.Second,
"The timeout of the ForeignCluster API server readiness check")
var podCIDR argsutils.CIDR
flag.Var(&podCIDR, "pod-cidr", "The CIDR used to assign IP addresses to pods")
var externalCIDR argsutils.CIDR
flag.Var(&externalCIDR, "external-cidr", "The CIDR used to assign IP addresses to services")

// Discovery parameters
autoJoin := flag.Bool("auto-join-discovered-clusters", true, "Whether to automatically peer with discovered clusters")
Expand Down Expand Up @@ -626,7 +630,11 @@ func main() {
klog.Errorf("Unable to start the ipReconciler", err)
os.Exit(1)
}
cfgr := configurationcontroller.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("configuration-controller"))
cfgr := configurationcontroller.NewConfigurationReconciler(mgr.GetClient(), mgr.GetScheme(), mgr.GetEventRecorderFor("configuration-controller"),
networkingv1alpha1.ClusterConfigCIDR{
Pod: networkingv1alpha1.CIDR(podCIDR.String()),
External: networkingv1alpha1.CIDR(externalCIDR.String()),
})
if err = cfgr.SetupWithManager(mgr); err != nil {
klog.Errorf("unable to create controller ConfigurationReconciler: %s", err)
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ type ConfigurationReconciler struct {
client.Client
Scheme *runtime.Scheme
EventsRecorder record.EventRecorder

localCIDR networkingv1alpha1.ClusterConfigCIDR
}

// NewConfigurationReconciler returns a new ConfigurationReconciler.
func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder) *ConfigurationReconciler {
func NewConfigurationReconciler(cl client.Client, s *runtime.Scheme, er record.EventRecorder,
localCIDR networkingv1alpha1.ClusterConfigCIDR) *ConfigurationReconciler {
return &ConfigurationReconciler{
Client: cl,
Scheme: s,
EventsRecorder: er,

localCIDR: localCIDR,
}
}

Expand All @@ -62,6 +67,14 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
return ctrl.Result{}, fmt.Errorf("unable to get the configuration %q: %w", req.NamespacedName, err)
}

if configuration.Spec.Local == nil {
err := r.DefaultLocalNetwork(ctx, configuration)
if err != nil {
return ctrl.Result{}, err
}
}

events.Event(r.EventsRecorder, configuration, "Processing")

err := r.RemapConfiguration(ctx, configuration, r.EventsRecorder)
Expand All @@ -82,6 +95,13 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}

func (r *ConfigurationReconciler) DefaultLocalNetwork(ctx context.Context, cfg *networkingv1alpha1.Configuration) error {
cfg.Spec.Local = &networkingv1alpha1.ClusterConfig{
CIDR: r.localCIDR,
}
return r.Client.Update(ctx, cfg)
}

// RemapConfiguration remap the configuration using ipamv1alpha1.Network.
func (r *ConfigurationReconciler) RemapConfiguration(ctx context.Context, cfg *networkingv1alpha1.Configuration,
er record.EventRecorder) error {
Expand Down

0 comments on commit aa7aadf

Please sign in to comment.