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

chore: filter events to reconcile by CRD API version #8084

Merged
merged 3 commits into from
Oct 31, 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
187 changes: 98 additions & 89 deletions cmd/dataprotection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const (
multiClusterContextsDisabledFlagKey flagName = "multi-cluster-contexts-disabled"

userAgentFlagKey flagName = "user-agent"

// dual-operators-mode indicates whether the operator runs in dual-operators mode.
// If it's true, the operator will degrade to a secondary operator and only manage the resources dedicated to releases prior to v1.0.
dualOperatorsModeFlag flagName = "dual-operators-mode"
)

var (
Expand Down Expand Up @@ -148,6 +152,8 @@ func main() {

flag.String(userAgentFlagKey.String(), "", "User agent of the operator.")

flag.Bool(dualOperatorsModeFlag.String(), false, "Whether the operator runs in dual-operators mode.")

flag.String(constant.ManagedNamespacesFlag, "",
"The namespaces that the operator will manage, multiple namespaces are separated by commas.")

Expand Down Expand Up @@ -273,105 +279,108 @@ func main() {
client = multiClusterMgr.GetClient()
}

if err = (&dpcontrollers.ActionSetReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("actionset-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ActionSet")
os.Exit(1)
}
dualOperatorsMode := viper.GetBool(dualOperatorsModeFlag.viperName())
if !dualOperatorsMode {
if err = (&dpcontrollers.ActionSetReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("actionset-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ActionSet")
os.Exit(1)
}

if err = (&dpcontrollers.BackupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Backup")
os.Exit(1)
}
if err = (&dpcontrollers.BackupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Backup")
os.Exit(1)
}

if err = (&dpcontrollers.RestoreReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("restore-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Restore")
os.Exit(1)
}
if err = (&dpcontrollers.RestoreReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("restore-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Restore")
os.Exit(1)
}

if err = (&dpcontrollers.VolumePopulatorReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("volume-populator-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "VolumePopulator")
os.Exit(1)
}
if err = (&dpcontrollers.VolumePopulatorReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("volume-populator-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "VolumePopulator")
os.Exit(1)
}

if err = (&dpcontrollers.BackupPolicyReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-policy-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupPolicy")
os.Exit(1)
}
if err = (&dpcontrollers.BackupPolicyReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-policy-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupPolicy")
os.Exit(1)
}

if err = (&dpcontrollers.BackupScheduleReconciler{
Client: dputils.NewCompatClient(mgr.GetClient()),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-schedule-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupSchedule")
os.Exit(1)
}
if err = (&dpcontrollers.BackupScheduleReconciler{
Client: dputils.NewCompatClient(mgr.GetClient()),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-schedule-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupSchedule")
os.Exit(1)
}

if err = (&dpcontrollers.BackupRepoReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-repo-controller"),
RestConfig: mgr.GetConfig(),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupRepo")
os.Exit(1)
}
if err = (&dpcontrollers.BackupRepoReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("backup-repo-controller"),
RestConfig: mgr.GetConfig(),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupRepo")
os.Exit(1)
}

if err = (&storagecontrollers.StorageProviderReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("storage-provider-controller"),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StorageProvider")
os.Exit(1)
}
if err = (&storagecontrollers.StorageProviderReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("storage-provider-controller"),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StorageProvider")
os.Exit(1)
}

if err = (&dpcontrollers.StorageProviderReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("storage-provider-controller"),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StorageProvider")
os.Exit(1)
}
if err = (&dpcontrollers.StorageProviderReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("storage-provider-controller"),
MultiClusterMgr: multiClusterMgr,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StorageProvider")
os.Exit(1)
}

if err = (&dpcontrollers.LogCollectionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("log-collection-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "logCollectionController")
os.Exit(1)
}
if err = (&dpcontrollers.LogCollectionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("log-collection-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "logCollectionController")
os.Exit(1)
}

if err = dpcontrollers.NewGCReconciler(mgr).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GarbageCollection")
os.Exit(1)
if err = dpcontrollers.NewGCReconciler(mgr).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GarbageCollection")
os.Exit(1)
}
}

// +kubebuilder:scaffold:builder
Expand Down
43 changes: 25 additions & 18 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
experimentalv1alpha1 "github.com/apecloud/kubeblocks/apis/experimental/v1alpha1"
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
storagev1alpha1 "github.com/apecloud/kubeblocks/apis/storage/v1alpha1"
"github.com/apecloud/kubeblocks/apis/workloads/legacy"
workloadsv1alpha1 "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
appscontrollers "github.com/apecloud/kubeblocks/controllers/apps"
Expand Down Expand Up @@ -84,15 +83,19 @@ const (

// switch flags key for API groups
appsFlagKey flagName = "apps"
extensionsFlagKey flagName = "extensions"
workloadsFlagKey flagName = "workloads"
extensionsFlagKey flagName = "extensions"
experimentalFlagKey flagName = "experimental"

multiClusterKubeConfigFlagKey flagName = "multi-cluster-kubeconfig"
multiClusterContextsFlagKey flagName = "multi-cluster-contexts"
multiClusterContextsDisabledFlagKey flagName = "multi-cluster-contexts-disabled"

userAgentFlagKey flagName = "user-agent"

// dual-operators-mode indicates whether the operator runs in dual-operators mode.
// If it's true, the operator will degrade to a secondary operator and only manage the resources dedicated to releases prior to v1.0.
dualOperatorsModeFlag flagName = "dual-operators-mode"
)

var (
Expand All @@ -109,7 +112,6 @@ func init() {
utilruntime.Must(snapshotv1beta1.AddToScheme(scheme))
utilruntime.Must(extensionsv1alpha1.AddToScheme(scheme))
utilruntime.Must(workloadsv1alpha1.AddToScheme(scheme))
utilruntime.Must(storagev1alpha1.AddToScheme(scheme))
utilruntime.Must(appsv1beta1.AddToScheme(scheme))
utilruntime.Must(legacy.AddToScheme(scheme))
utilruntime.Must(apiextv1.AddToScheme(scheme))
Expand Down Expand Up @@ -173,10 +175,10 @@ func setupFlags() {

flag.Bool(appsFlagKey.String(), true,
"Enable the apps controller manager.")
flag.Bool(extensionsFlagKey.String(), true,
"Enable the extensions controller manager.")
flag.Bool(workloadsFlagKey.String(), true,
"Enable the workloads controller manager.")
flag.Bool(extensionsFlagKey.String(), true,
"Enable the extensions controller manager.")
flag.Bool(experimentalFlagKey.String(), false,
"Enable the experimental controller manager.")

Expand All @@ -189,6 +191,8 @@ func setupFlags() {

flag.String(userAgentFlagKey.String(), "", "User agent of the operator.")

flag.Bool(dualOperatorsModeFlag.String(), false, "Whether the operator runs in dual-operators mode.")

opts := zap.Options{
Development: false,
}
Expand Down Expand Up @@ -521,18 +525,6 @@ func main() {
}
}

if viper.GetBool(extensionsFlagKey.viperName()) {
if err = (&extensionscontrollers.AddonReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("addon-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Addon")
os.Exit(1)
}
}

if viper.GetBool(workloadsFlagKey.viperName()) {
if err = (&workloadscontrollers.InstanceSetReconciler{
Client: client,
Expand All @@ -544,7 +536,21 @@ func main() {
}
}

if viper.GetBool(experimentalFlagKey.viperName()) {
dualOperatorsMode := viper.GetBool(dualOperatorsModeFlag.viperName())

if !dualOperatorsMode && viper.GetBool(extensionsFlagKey.viperName()) {
if err = (&extensionscontrollers.AddonReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("addon-controller"),
RestConfig: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Addon")
os.Exit(1)
}
}

if !dualOperatorsMode && viper.GetBool(experimentalFlagKey.viperName()) {
if err = (&experimentalcontrollers.NodeCountScalerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand All @@ -554,6 +560,7 @@ func main() {
os.Exit(1)
}
}

// +kubebuilder:scaffold:builder

if viper.GetBool("enable_webhooks") {
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/backuppolicytemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *BackupPolicyTemplateReconciler) compatibleBackupPolicyTemplate(ctx cont

// SetupWithManager sets up the controller with the Manager.
func (r *BackupPolicyTemplateReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &appsv1alpha1.BackupPolicyTemplate{}, &appsv1alpha1.ComponentDefinition{}).
For(&appsv1alpha1.BackupPolicyTemplate{}).
Watches(&appsv1alpha1.ComponentDefinition{}, handler.EnqueueRequestsFromMapFunc(r.compatibleBackupPolicyTemplate)).
Complete(r)
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/class_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *ComponentClassReconciler) Reconcile(ctx context.Context, req reconcile.

// SetupWithManager sets up the controller with the Manager.
func (r *ComponentClassReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1alpha1.ComponentClassDefinition{}).
Complete(r)
}
2 changes: 1 addition & 1 deletion controllers/apps/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

// SetupWithManager sets up the controller with the Manager.
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &appsv1alpha1.Cluster{}, &appsv1alpha1.Component{}).
For(&appsv1alpha1.Cluster{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(math.Ceil(viper.GetFloat64(constant.CfgKBReconcileWorkers) / 4)),
Expand Down
2 changes: 0 additions & 2 deletions controllers/apps/cluster_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
storagev1alpha1 "github.com/apecloud/kubeblocks/apis/storage/v1alpha1"
workloadsv1alpha1 "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/controller/graph"
Expand Down Expand Up @@ -121,7 +120,6 @@ func init() {
model.AddScheme(snapshotv1beta1.AddToScheme)
model.AddScheme(extensionsv1alpha1.AddToScheme)
model.AddScheme(workloadsv1alpha1.AddToScheme)
model.AddScheme(storagev1alpha1.AddToScheme)
model.AddScheme(appsv1beta1.AddToScheme)
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/clusterdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r *ClusterDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Re

// SetupWithManager sets up the controller with the Manager.
func (r *ClusterDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &appsv1alpha1.ClusterDefinition{}).
For(&appsv1alpha1.ClusterDefinition{}).
Complete(r)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/clusterversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// SetupWithManager sets up the controller with the Manager.
func (r *ClusterVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1alpha1.ClusterVersion{}).
Complete(r)
}
Expand Down
Loading
Loading