Skip to content

Commit

Permalink
Merge branch 'main' into fix/subtract-previous-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Apr 11, 2023
2 parents 8a1ec05 + fac013d commit 53e0b14
Show file tree
Hide file tree
Showing 35 changed files with 3,030 additions and 1,856 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
35 changes: 35 additions & 0 deletions cmd/controller-manager/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"k8s.io/klog/v2"

fedcorev1a1 "github.com/kubewharf/kubeadmiral/pkg/apis/core/v1alpha1"
"github.com/kubewharf/kubeadmiral/pkg/client/generic"
"github.com/kubewharf/kubeadmiral/pkg/controllers/automigration"
controllercontext "github.com/kubewharf/kubeadmiral/pkg/controllers/context"
"github.com/kubewharf/kubeadmiral/pkg/controllers/federate"
"github.com/kubewharf/kubeadmiral/pkg/controllers/federatedcluster"
Expand Down Expand Up @@ -191,3 +193,36 @@ func startFederateController(
go federateController.Run(ctx)
return nil
}

func startAutoMigrationController(
ctx context.Context,
controllerCtx *controllercontext.Context,
typeConfig *fedcorev1a1.FederatedTypeConfig,
) error {
if typeConfig.Spec.AutoMigration == nil || !typeConfig.Spec.AutoMigration.Enabled {
klog.Infof("Auto migration controller disabled for FederatedTypeConfig %s", typeConfig.Name)
return nil
}

genericClient, err := generic.New(controllerCtx.RestConfig)
if err != nil {
return fmt.Errorf("error creating generic client: %w", err)
}

federatedAPIResource := typeConfig.GetFederatedType()
federatedGVR := schemautil.APIResourceToGVR(&federatedAPIResource)

federateController, err := automigration.NewAutoMigrationController(
controllerConfigFromControllerContext(controllerCtx),
typeConfig,
genericClient,
controllerCtx.KubeClientset,
controllerCtx.DynamicClientset.Resource(federatedGVR),
controllerCtx.DynamicInformerFactory.ForResource(federatedGVR),
)
if err != nil {
return fmt.Errorf("error creating auto-migration controller: %w", err)
}
go federateController.Run(ctx)
return nil
}
11 changes: 7 additions & 4 deletions cmd/controller-manager/app/ftcmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import (
)

const (
FederateControllerName = "federate-controller"
GlobalSchedulerName = "global-scheduler"
FederateControllerName = "federate-controller"
GlobalSchedulerName = "global-scheduler"
AutoMigrationControllerName = "auto-migration-controller"
)

var knownFTCSubControllers = map[string]StartFTCSubControllerFunc{
GlobalSchedulerName: startGlobalScheduler,
FederateControllerName: startFederateController,
GlobalSchedulerName: startGlobalScheduler,
FederateControllerName: startFederateController,
AutoMigrationControllerName: startAutoMigrationController,
}

// StartFTCSubControllerFunc is responsible for constructing and starting a FTC subcontroller. A FTC subcontroller is started/stopped
Expand Down Expand Up @@ -162,6 +164,7 @@ func (m *FederatedTypeConfigManager) processQueueItem(ctx context.Context) {
continue
}

// TODO[ftcmanager]: handle controllers that do not need to be started for certain FTCs
if err := startFunc(subControllerCtx, m.controllerCtx, typeConfig); err != nil {
keyedLogger.Error(err, "Failed to start subcontrolelr")
} else {
Expand Down
438 changes: 208 additions & 230 deletions config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions config/crds/core.kubeadmiral.io_federatedtypeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ spec:
type: object
spec:
properties:
autoMigration:
description: Configurations for auto migration.
properties:
enabled:
description: Whether or not to enable auto migration.
type: boolean
required:
- enabled
type: object
controllers:
description: The controllers that must run before the resource can
be propagated to member clusters. Each inner slice specifies a step.
Expand Down
Loading

0 comments on commit 53e0b14

Please sign in to comment.