Skip to content

Commit

Permalink
refactor: vcluster manager start
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Jul 15, 2024
1 parent bb51943 commit 28b729e
Show file tree
Hide file tree
Showing 51 changed files with 372 additions and 1,083 deletions.
8 changes: 7 additions & 1 deletion cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error {
return fmt.Errorf("start integrations: %w", err)
}

// start managers
syncers, err := setup.StartManagers(controllerCtx)
if err != nil {
return fmt.Errorf("start managers: %w", err)
}

// start proxy
err = setup.StartProxy(controllerCtx)
if err != nil {
Expand Down Expand Up @@ -133,7 +139,7 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error {

// start leader election + controllers
err = StartLeaderElection(controllerCtx, func() error {
return setup.StartControllers(controllerCtx)
return setup.StartControllers(controllerCtx, syncers)
})
if err != nil {
return fmt.Errorf("start controllers: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/constants/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const (
PausedReplicasAnnotation = "loft.sh/paused-replicas"
PausedDateAnnotation = "loft.sh/paused-date"

HostClusterPersistentVolumeAnnotation = "vcluster.loft.sh/host-pv"

HostClusterVSCAnnotation = "vcluster.loft.sh/host-volumesnapshotcontent"

// NodeSuffix is the dns suffix for our nodes
NodeSuffix = "nodes.vcluster.com"

Expand Down
29 changes: 20 additions & 9 deletions pkg/controllers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func isEnabled(enabled bool, fn BuildController) BuildController {
return nil
}

func Create(ctx *config.ControllerContext) ([]syncertypes.Object, error) {
func CreateSyncers(ctx *config.ControllerContext) ([]syncertypes.Object, error) {
registerContext := util.ToRegisterContext(ctx)

// register controllers for resource synchronization
Expand Down Expand Up @@ -159,6 +159,7 @@ func RegisterIndices(ctx *config.ControllerContext, syncers []syncertypes.Object
func RegisterControllers(ctx *config.ControllerContext, syncers []syncertypes.Object) error {
registerContext := util.ToRegisterContext(ctx)

// start default endpoint controller
err := k8sdefaultendpoint.Register(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -190,6 +191,7 @@ func RegisterControllers(ctx *config.ControllerContext, syncers []syncertypes.Ob
return err
}

// register generic sync controllers
err = RegisterGenericSyncController(ctx)
if err != nil {
return err
Expand All @@ -204,14 +206,23 @@ func RegisterControllers(ctx *config.ControllerContext, syncers []syncertypes.Ob
if err != nil {
return errors.Wrapf(err, "start %s syncer", v.Name())
}
} else {
// real syncer?
realSyncer, ok := v.(syncertypes.Syncer)
if ok {
err = syncer.RegisterSyncer(registerContext, realSyncer)
if err != nil {
return errors.Wrapf(err, "start %s syncer", v.Name())
}
}

// real syncer?
realSyncer, ok := v.(syncertypes.Syncer)
if ok {
err = syncer.RegisterSyncer(registerContext, realSyncer)
if err != nil {
return errors.Wrapf(err, "start %s syncer", v.Name())
}
}

// custom syncer?
customSyncer, ok := v.(syncertypes.ControllerStarter)
if ok {
err = customSyncer.Register(registerContext)
if err != nil {
return errors.Wrapf(err, "start %s syncer", v.Name())
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/resources/events/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
generictesting "github.com/loft-sh/vcluster/pkg/controllers/syncer/testing"
"github.com/loft-sh/vcluster/pkg/mappings/resources"
"github.com/loft-sh/vcluster/pkg/util/translate"
"gotest.tools/assert"
corev1 "k8s.io/api/core/v1"
Expand All @@ -15,10 +14,6 @@ import (
)

func newFakeSyncer(t *testing.T, ctx *synccontext.RegisterContext) (*synccontext.SyncContext, *eventSyncer) {
// we need that index here as well otherwise we wouldn't find the related pod
err := resources.RegisterPodsMapper(ctx)
assert.NilError(t, err)

syncContext, object := generictesting.FakeStartSyncer(t, ctx, New)
return syncContext, object.(*eventSyncer)
}
Expand Down
77 changes: 0 additions & 77 deletions pkg/controllers/resources/ingresses/legacy/syncer.go

This file was deleted.

Loading

0 comments on commit 28b729e

Please sign in to comment.