Skip to content

Commit

Permalink
Merge pull request #65 from ykulazhenkov/pr-remove-migration-logic
Browse files Browse the repository at this point in the history
Remove migration logic for controller
  • Loading branch information
ykulazhenkov authored Nov 28, 2024
2 parents c5285cd + bcea9bd commit b87556e
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 1,158 deletions.
25 changes: 0 additions & 25 deletions cmd/ipam-controller/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
ctrlconf "sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand All @@ -49,7 +48,6 @@ import (
cidrpoolctrl "github.com/Mellanox/nvidia-k8s-ipam/pkg/ipam-controller/controllers/cidrpool"
ippoolctrl "github.com/Mellanox/nvidia-k8s-ipam/pkg/ipam-controller/controllers/ippool"
nodectrl "github.com/Mellanox/nvidia-k8s-ipam/pkg/ipam-controller/controllers/node"
"github.com/Mellanox/nvidia-k8s-ipam/pkg/ipam-controller/migrator"
"github.com/Mellanox/nvidia-k8s-ipam/pkg/version"
)

Expand Down Expand Up @@ -135,34 +133,12 @@ func RunController(ctx context.Context, config *rest.Config, opts *options.Optio
return err
}

k8sClient, err := client.New(config,
client.Options{Scheme: mgr.GetScheme(), Mapper: mgr.GetRESTMapper()})
if err != nil {
logger.Error(err, "failed to create k8sClient client")
os.Exit(1)
}

migrationChan := make(chan struct{})
m := migrator.Migrator{
IPPoolsNamespace: opts.IPPoolsNamespace,
K8sClient: k8sClient,
MigrationCh: migrationChan,
LeaderElection: opts.EnableLeaderElection,
Logger: logger.WithName("Migrator"),
}
err = mgr.Add(&m)
if err != nil {
logger.Error(err, "failed to add Migrator to the Manager")
os.Exit(1)
}

ipPoolNodeEventCH := make(chan event.GenericEvent, 1)
cidrPoolNodeEventCH := make(chan event.GenericEvent, 1)

if err = (&nodectrl.NodeReconciler{
IPPoolNodeEventCH: ipPoolNodeEventCH,
CIDRPoolNodeEventCH: cidrPoolNodeEventCH,
MigrationCh: migrationChan,
PoolsNamespace: opts.IPPoolsNamespace,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand All @@ -186,7 +162,6 @@ func RunController(ctx context.Context, config *rest.Config, opts *options.Optio
PoolsNamespace: opts.IPPoolsNamespace,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
MigrationCh: migrationChan,
}).SetupWithManager(mgr); err != nil {
logger.Error(err, "unable to create controller", "controller", "IPPool")
return err
Expand Down
78 changes: 0 additions & 78 deletions pkg/ipam-controller/config/config.go

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/ipam-controller/config/config_suite_test.go

This file was deleted.

65 changes: 0 additions & 65 deletions pkg/ipam-controller/config/config_test.go

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/ipam-controller/controllers/ippool/ippool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ import (
type IPPoolReconciler struct {
PoolsNamespace string
NodeEventCh chan event.GenericEvent
MigrationCh chan struct{}
client.Client
Scheme *runtime.Scheme
recorder record.EventRecorder
}

// Reconcile contains logic to sync IPPool objects
func (r *IPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
select {
case <-r.MigrationCh:
case <-ctx.Done():
return ctrl.Result{}, fmt.Errorf("canceled")
}
reqLog := log.FromContext(ctx)
if req.Namespace != r.PoolsNamespace {
// this should never happen because of the watcher configuration of the manager from controller-runtime pkg
Expand Down
7 changes: 0 additions & 7 deletions pkg/ipam-controller/controllers/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package controllers

import (
"context"
"fmt"

apiErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -35,18 +34,12 @@ type NodeReconciler struct {
PoolsNamespace string
IPPoolNodeEventCH chan event.GenericEvent
CIDRPoolNodeEventCH chan event.GenericEvent
MigrationCh chan struct{}
client.Client
Scheme *runtime.Scheme
}

// Reconcile contains logic to sync Node objects
func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
select {
case <-r.MigrationCh:
case <-ctx.Done():
return ctrl.Result{}, fmt.Errorf("canceled")
}
reqLog := log.FromContext(ctx)
reqLog.Info("Notification on Node", "name", req.Name)
node := &corev1.Node{}
Expand Down
Loading

0 comments on commit b87556e

Please sign in to comment.