Skip to content

Commit

Permalink
chore: filter events to reconcile by CRD API version
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf committed Nov 25, 2024
1 parent 269d4ff commit cd9c5a2
Show file tree
Hide file tree
Showing 33 changed files with 182 additions and 37 deletions.
2 changes: 1 addition & 1 deletion controllers/apps/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,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, &appsv1.Cluster{}, &appsv1.Component{}).
For(&appsv1.Cluster{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(math.Ceil(viper.GetFloat64(constant.CfgKBReconcileWorkers) / 4)),
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 @@ -96,7 +96,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, &appsv1.ClusterDefinition{}).
For(&appsv1.ClusterDefinition{}).
Complete(r)
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (r *ComponentReconciler) SetupWithManager(mgr ctrl.Manager, multiClusterMgr
}

func (r *ComponentReconciler) setupWithManager(mgr ctrl.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr, &appsv1.Component{}, &workloads.InstanceSet{}).
For(&appsv1.Component{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: viper.GetInt(constant.CfgKBReconcileWorkers),
Expand All @@ -220,7 +220,7 @@ func (r *ComponentReconciler) setupWithManager(mgr ctrl.Manager) error {
}

func (r *ComponentReconciler) setupWithMultiClusterManager(mgr ctrl.Manager, multiClusterMgr multicluster.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr, &appsv1.Component{}, &workloads.InstanceSet{}).
For(&appsv1.Component{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: viper.GetInt(constant.CfgKBReconcileWorkers),
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r *ComponentDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.

// SetupWithManager sets up the controller with the Manager.
func (r *ComponentDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &appsv1.ComponentDefinition{}).
For(&appsv1.ComponentDefinition{}).
Complete(r)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/componentversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *ComponentVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req

// SetupWithManager sets up the controller with the Manager.
func (r *ComponentVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &appsv1.ComponentVersion{}, &appsv1.ComponentDefinition{}).
For(&appsv1.ComponentVersion{}).
Watches(&appsv1.ComponentDefinition{}, handler.EnqueueRequestsFromMapFunc(r.compatibleCompVersion)).
Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *ConfigConstraintReconciler) Reconcile(ctx context.Context, req ctrl.Req

// SetupWithManager sets up the controller with the Manager.
func (r *ConfigConstraintReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1beta1.ConfigConstraint{}).
// for other resource
Owns(&corev1.ConfigMap{}). // TODO(leon)
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/configuration/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (r *ConfigurationReconciler) runTasks(taskCtx TaskContext, tasks []Task) (e

// SetupWithManager sets up the controller with the Manager.
func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager, multiClusterMgr multicluster.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1alpha1.Configuration{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(math.Ceil(viper.GetFloat64(constant.CfgKBReconcileWorkers) / 2)),
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/configuration/reconfigure_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *ReconfigureReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *ReconfigureReconciler) SetupWithManager(mgr ctrl.Manager, multiClusterMgr multicluster.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&corev1.ConfigMap{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(math.Ceil(viper.GetFloat64(constant.CfgKBReconcileWorkers) / 4)),
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/servicedescriptor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *ServiceDescriptorReconciler) Reconcile(ctx context.Context, req ctrl.Re

// SetupWithManager sets up the controller with the Manager.
func (r *ServiceDescriptorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1.ServiceDescriptor{}).
Complete(r)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/shardingdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *ShardingDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.R

// SetupWithManager sets up the controller with the Manager.
func (r *ShardingDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1.ShardingDefinition{}).
Complete(r)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/sidecardefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *SidecarDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Re

// SetupWithManager sets up the controller with the Manager.
func (r *SidecarDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&appsv1.SidecarDefinition{}).
Watches(&appsv1.ComponentDefinition{}, handler.EnqueueRequestsFromMapFunc(r.matchedCompDefinition)).
Complete(r)
Expand Down
53 changes: 49 additions & 4 deletions controllers/apps/transformer_cluster_normalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package apps
import (
"fmt"

"golang.org/x/exp/maps"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -79,9 +80,7 @@ func (t *clusterNormalizationTransformer) Transform(ctx graph.TransformContext,
}

// write-back the resolved definitions and service versions to cluster spec.
t.writeBackCompNShardingSpecs(transCtx)

return nil
return t.writeBackCompNShardingSpecs(transCtx)
}

func (t *clusterNormalizationTransformer) resolveCompsNShardings(transCtx *clusterTransformContext) ([]*appsv1.ClusterComponentSpec, []*appsv1.ClusterSharding, error) {
Expand Down Expand Up @@ -393,19 +392,65 @@ func (t *clusterNormalizationTransformer) validateShardingShards(transCtx *clust
return nil
}

func (t *clusterNormalizationTransformer) writeBackCompNShardingSpecs(transCtx *clusterTransformContext) {
func (t *clusterNormalizationTransformer) writeBackCompNShardingSpecs(transCtx *clusterTransformContext) error {
if len(transCtx.components) > 0 {
comps := make([]appsv1.ClusterComponentSpec, 0)
for i := range transCtx.components {
comps = append(comps, *transCtx.components[i])
}
transCtx.Cluster.Spec.ComponentSpecs = comps
}

if len(transCtx.shardings) > 0 {
shardings := make([]appsv1.ClusterSharding, 0)
for i := range transCtx.shardings {
shardings = append(shardings, *transCtx.shardings[i])
}
transCtx.Cluster.Spec.Shardings = shardings
}

return t.patchCRDAPIVersionKey(transCtx)
}

func (t *clusterNormalizationTransformer) patchCRDAPIVersionKey(transCtx *clusterTransformContext) error {
apiVersions := map[string][]string{}

add := func(k, v string) {
if _, ok := apiVersions[k]; !ok {
apiVersions[k] = []string{}
}
apiVersions[k] = append(apiVersions[k], v)
}

from := func(name string, annotations map[string]string) {
if annotations == nil {
add("", name)
} else {
add(annotations[constant.CRDAPIVersionAnnotationKey], name)
}
}

if transCtx.clusterDef != nil {
from(transCtx.clusterDef.Name, transCtx.clusterDef.Annotations)
} else {
for _, compDef := range transCtx.componentDefs {
from(compDef.Name, compDef.Annotations)
}
for _, shardingDef := range transCtx.shardingDefs {
from(shardingDef.Name, shardingDef.Annotations)
}
}

switch len(apiVersions) {
case 0:
return nil
case 1:
if transCtx.Cluster.Annotations == nil {
transCtx.Cluster.Annotations = make(map[string]string)
}
transCtx.Cluster.Annotations[constant.CRDAPIVersionAnnotationKey] = maps.Keys(apiVersions)[0]
return nil
default:
return fmt.Errorf("multiple CRD API versions found: %v", apiVersions)
}
}
2 changes: 1 addition & 1 deletion controllers/dataprotection/actionset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *ActionSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

// SetupWithManager sets up the controller with the Manager.
func (r *ActionSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.ActionSet{}).
Complete(r)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

// SetupWithManager sets up the controller with the Manager.
func (r *BackupReconciler) SetupWithManager(mgr ctrl.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.Backup{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: viper.GetInt(dptypes.CfgDataProtectionReconcileWorkers),
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/backuppolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r *BackupPolicyReconciler) validateBackupPolicy(backupPolicy *dpv1alpha1.B

// SetupWithManager sets up the controller with the Manager.
func (r *BackupPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.BackupPolicy{}).
Complete(r)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,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).
For(&dpv1alpha1.BackupPolicyTemplate{}).
Watches(&appsv1.ComponentDefinition{}, handler.EnqueueRequestsFromMapFunc(r.compatibleBackupPolicyTemplate)).
Complete(r)
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/backuprepo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
}); err != nil {
return err
}
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.BackupRepo{}).
Watches(&dpv1alpha1.StorageProvider{}, handler.EnqueueRequestsFromMapFunc(r.mapProviderToRepos)).
Watches(&dpv1alpha1.Backup{}, handler.EnqueueRequestsFromMapFunc(r.mapBackupToRepo)).
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/backupschedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *BackupScheduleReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// SetupWithManager sets up the controller with the Manager.
func (r *BackupScheduleReconciler) SetupWithManager(mgr ctrl.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.BackupSchedule{})

// Compatible with kubernetes versions prior to K8s 1.21, only supports batch v1beta1.
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/gc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewGCReconciler(mgr ctrl.Manager) *GCReconciler {
// taken care of. Other events will be filtered to decrease the load on the controller.
func (r *GCReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := dputils.NewPeriodicalEnqueueSource(mgr.GetClient(), &dpv1alpha1.BackupList{}, r.frequency, dputils.PeriodicalEnqueueSourceOption{})
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.Backup{}, builder.WithPredicates(predicate.NewPredicateFuncs(func(client.Object) bool { return false }))).
WatchesRawSource(s, nil).
Complete(r)
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/log_collection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *LogCollectionReconciler) Reconcile(ctx context.Context, req ctrl.Reques

// SetupWithManager sets up the controller with the Manager.
func (r *LogCollectionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&batchv1.Job{}, builder.WithPredicates(
failedJobUpdatePredicate{
Funcs: predicate.NewPredicateFuncs(func(object client.Object) bool { return false }),
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (r *RestoreReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

// SetupWithManager sets up the controller with the Manager.
func (r *RestoreReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.Restore{}).
Owns(&batchv1.Job{}).
Watches(&batchv1.Job{}, handler.EnqueueRequestsFromMapFunc(r.parseRestoreJob)).
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/storageprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r *StorageProviderReconciler) deleteExternalResources(

// SetupWithManager sets up the controller with the Manager.
func (r *StorageProviderReconciler) SetupWithManager(mgr ctrl.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&dpv1alpha1.StorageProvider{})

mapCSIDriverToProvider := handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/volumepopulator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r *VolumePopulatorReconciler) Reconcile(ctx context.Context, req ctrl.Requ

// SetupWithManager sets up the controller with the Manager.
func (r *VolumePopulatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&corev1.PersistentVolumeClaim{}).
Owns(&batchv1.Job{}).
Complete(r)
Expand Down
3 changes: 2 additions & 1 deletion controllers/experimental/nodecountscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
experimental "github.com/apecloud/kubeblocks/apis/experimental/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/controller/kubebuilderx"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
)

// NodeCountScalerReconciler reconciles a NodeCountScaler object
Expand Down Expand Up @@ -69,7 +70,7 @@ func (r *NodeCountScalerReconciler) Reconcile(ctx context.Context, req ctrl.Requ

// SetupWithManager sets up the controller with the Manager.
func (r *NodeCountScalerReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&experimental.NodeCountScaler{}).
Watches(&corev1.Node{}, &nodeScalingHandler{r.Client}).
Watches(&appsv1.Cluster{}, &clusterHandler{r.Client}).
Expand Down
2 changes: 1 addition & 1 deletion controllers/extensions/addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *AddonReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl

// SetupWithManager sets up the controller with the Manager.
func (r *AddonReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&extensionsv1alpha1.Addon{}).
Watches(&batchv1.Job{}, handler.EnqueueRequestsFromMapFunc(r.findAddonJobs)).
WithOptions(controller.Options{
Expand Down
2 changes: 1 addition & 1 deletion controllers/k8score/event_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *EventReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl

// SetupWithManager sets up the controller with the Manager.
func (r *EventReconciler) SetupWithManager(mgr ctrl.Manager, multiClusterMgr multicluster.Manager) error {
b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr).
For(&corev1.Event{})

if multiClusterMgr != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/operations/opsdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (r *OpsDefinitionReconciler) updateStatusUnavailable(reqCtx intctrlutil.Req

// SetupWithManager sets up the controller with the Manager.
func (r *OpsDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&opsv1alpha1.OpsDefinition{}).
Complete(r)
}
2 changes: 1 addition & 1 deletion controllers/operations/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *OpsRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// SetupWithManager sets up the controller with the Manager.
func (r *OpsRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr).
For(&opsv1alpha1.OpsRequest{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: int(math.Ceil(viper.GetFloat64(constant.CfgKBReconcileWorkers) / 2)),
Expand Down
4 changes: 2 additions & 2 deletions controllers/workloads/instanceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *InstanceSetReconciler) SetupWithManager(mgr ctrl.Manager, multiClusterM
func (r *InstanceSetReconciler) setupWithManager(mgr ctrl.Manager, ctx *handler.FinderContext) error {
itsFinder := handler.NewLabelFinder(&workloads.InstanceSet{}, instanceset.WorkloadsManagedByLabelKey, workloads.Kind, instanceset.WorkloadsInstanceLabelKey)
podHandler := handler.NewBuilder(ctx).AddFinder(itsFinder).Build()
return intctrlutil.NewNamespacedControllerManagedBy(mgr).
return intctrlutil.NewControllerManagedBy(mgr, &workloads.InstanceSet{}).
For(&workloads.InstanceSet{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: viper.GetInt(constant.CfgKBReconcileWorkers),
Expand All @@ -132,7 +132,7 @@ func (r *InstanceSetReconciler) setupWithMultiClusterManager(mgr ctrl.Manager,
// TODO: modify handler.getObjectFromKey to support running Job in data clusters
jobHandler := handler.NewBuilder(ctx).AddFinder(delegatorFinder).Build()

b := intctrlutil.NewNamespacedControllerManagedBy(mgr).
b := intctrlutil.NewControllerManagedBy(mgr, &workloads.InstanceSet{}).
For(&workloads.InstanceSet{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: viper.GetInt(constant.CfgKBReconcileWorkers),
Expand Down
3 changes: 3 additions & 0 deletions pkg/constant/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package constant

// annotations defined by KubeBlocks
const (
// CRDAPIVersionAnnotationKey indicates the CRD API version of the object.
CRDAPIVersionAnnotationKey = "kubeblocks.io/crd-api-version"

ClusterSnapshotAnnotationKey = "kubeblocks.io/cluster-snapshot" // ClusterSnapshotAnnotationKey saves the snapshot of cluster.
EncryptedSystemAccountsAnnotationKey = "kubeblocks.io/encrypted-system-accounts" // EncryptedSystemAccountsAnnotationKey saves the encrypted system accounts.
OpsRequestAnnotationKey = "kubeblocks.io/ops-request" // OpsRequestAnnotationKey OpsRequest annotation key in Cluster
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func BuildComponent(cluster *appsv1.Cluster, compSpec *appsv1.ClusterComponentSp
}
compBuilder := builder.NewComponentBuilder(cluster.Namespace, FullName(cluster.Name, compSpec.Name), compSpec.ComponentDef).
AddAnnotations(constant.KubeBlocksGenerationKey, strconv.FormatInt(cluster.Generation, 10)).
AddAnnotations(constant.CRDAPIVersionAnnotationKey, appsv1.GroupVersion.String()).
AddAnnotations(constant.KBAppClusterUIDKey, string(cluster.UID)).
AddAnnotationsInMap(inheritedAnnotations(cluster)).
AddAnnotationsInMap(annotations). // annotations added by the cluster controller
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, component
AddLabelsInMap(constant.GetCompLabels(clusterName, compName)).
AddLabelsInMap(synthesizedComp.StaticLabels).
AddAnnotations(constant.KubeBlocksGenerationKey, synthesizedComp.Generation).
AddAnnotations(constant.CRDAPIVersionAnnotationKey, workloads.GroupVersion.String()).
AddAnnotationsInMap(map[string]string{
constant.AppComponentLabelKey: compDefName,
constant.KBAppServiceVersionKey: synthesizedComp.ServiceVersion,
Expand Down
Loading

0 comments on commit cd9c5a2

Please sign in to comment.