Skip to content

Commit

Permalink
chore: decouple apps dependence on parameters and tidy up parameters …
Browse files Browse the repository at this point in the history
…controller
  • Loading branch information
sophon-zt committed Dec 11, 2024
1 parent 0d108f2 commit 6f0dff5
Show file tree
Hide file tree
Showing 44 changed files with 1,073 additions and 1,915 deletions.
1 change: 0 additions & 1 deletion controllers/apps/clusterdefinition_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var _ = Describe("ClusterDefinition Controller", func() {
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ClusterDefinitionSignature, true, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ShardingDefinitionSignature, true, ml)
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ComponentDefinitionSignature, true, ml)
testapps.ClearResources(&testCtx, intctrlutil.ConfigConstraintSignature, ml)

// namespaced
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ConfigMapSignature, true, inNS, ml)
Expand Down
26 changes: 3 additions & 23 deletions controllers/apps/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
"github.com/apecloud/kubeblocks/pkg/constant"
Expand Down Expand Up @@ -152,14 +151,12 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
&componentAccountTransformer{},
// handle the TLS configuration
&componentTLSTransformer{Client: r.Client},
// rerender parameters after v-scale and h-scale
&componentRelatedParametersTransformer{Client: r.Client},
// resolve and build vars for template and Env
&componentVarsTransformer{},
// provision component system accounts, depend on vars
&componentAccountProvisionTransformer{},
// render component configurations
&componentConfigurationTransformer{Client: r.Client},
&componentReloadActionSidecarTransformer{Client: r.Client},
// handle restore before workloads transform
&componentRestoreTransformer{Client: r.Client},
// handle the component workload
Expand Down Expand Up @@ -207,8 +204,7 @@ func (r *ComponentReconciler) setupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.Secret{}).
Owns(&corev1.ConfigMap{}).
Watches(&dpv1alpha1.Restore{}, handler.EnqueueRequestsFromMapFunc(r.filterComponentResources)).
Watches(&corev1.PersistentVolumeClaim{}, handler.EnqueueRequestsFromMapFunc(r.filterComponentResources)).
Watches(&appsv1alpha1.Configuration{}, handler.EnqueueRequestsFromMapFunc(r.configurationEventHandler))
Watches(&corev1.PersistentVolumeClaim{}, handler.EnqueueRequestsFromMapFunc(r.filterComponentResources))

if viper.GetBool(constant.EnableRBACManager) {
b.Owns(&rbacv1.RoleBinding{}).
Expand All @@ -228,8 +224,7 @@ func (r *ComponentReconciler) setupWithMultiClusterManager(mgr ctrl.Manager, mul
MaxConcurrentReconciles: viper.GetInt(constant.CfgKBReconcileWorkers),
}).
Owns(&workloads.InstanceSet{}).
Watches(&dpv1alpha1.Restore{}, handler.EnqueueRequestsFromMapFunc(r.filterComponentResources)).
Watches(&appsv1alpha1.Configuration{}, handler.EnqueueRequestsFromMapFunc(r.configurationEventHandler))
Watches(&dpv1alpha1.Restore{}, handler.EnqueueRequestsFromMapFunc(r.filterComponentResources))

eventHandler := handler.EnqueueRequestsFromMapFunc(r.filterComponentResources)
multiClusterMgr.Watch(b, &corev1.Service{}, eventHandler).
Expand Down Expand Up @@ -263,18 +258,3 @@ func (r *ComponentReconciler) filterComponentResources(ctx context.Context, obj
},
}
}

func (r *ComponentReconciler) configurationEventHandler(_ context.Context, obj client.Object) []reconcile.Request {
cr, ok := obj.(*appsv1alpha1.Configuration)
if !ok {
return []reconcile.Request{}
}
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Namespace: obj.GetNamespace(),
Name: constant.GenerateClusterComponentName(cr.Spec.ClusterRef, cr.Spec.ComponentName),
},
},
}
}
1 change: 0 additions & 1 deletion controllers/apps/componentdefinition_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var _ = Describe("ComponentDefinition Controller", func() {

// non-namespaced
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ComponentDefinitionSignature, true, ml)
testapps.ClearResources(&testCtx, intctrlutil.ConfigConstraintSignature, ml)

// namespaced
testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.ConfigMapSignature, true, inNS, ml)
Expand Down
17 changes: 7 additions & 10 deletions controllers/apps/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
opsv1alpha1 "github.com/apecloud/kubeblocks/apis/operations/v1alpha1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
Expand Down Expand Up @@ -123,18 +121,10 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

err = appsv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
model.AddScheme(appsv1alpha1.AddToScheme)

err = opsv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
model.AddScheme(opsv1alpha1.AddToScheme)

err = appsv1beta1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
model.AddScheme(appsv1beta1.AddToScheme)

err = appsv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
model.AddScheme(appsv1.AddToScheme)
Expand Down Expand Up @@ -255,6 +245,13 @@ var _ = BeforeSuite(func() {
}).SetupWithManager(k8sManager, nil)
Expect(err).ToNot(HaveOccurred())

err = (&parameters.ComponentDrivenParameterReconciler{
Client: k8sManager.GetClient(),
Scheme: k8sManager.GetScheme(),
Recorder: k8sManager.GetEventRecorderFor("component-parameter-controller"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

err = (&parameters.ParametersDefinitionReconciler{
Client: k8sManager.GetClient(),
Scheme: k8sManager.GetScheme(),
Expand Down
88 changes: 0 additions & 88 deletions controllers/apps/transformer_component_configuration.go

This file was deleted.

4 changes: 2 additions & 2 deletions controllers/apps/transformer_component_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/controller/component"
Expand Down Expand Up @@ -169,7 +169,7 @@ func compOwnedKinds() []client.ObjectList {
&corev1.SecretList{},
&corev1.ConfigMapList{},
&corev1.PersistentVolumeClaimList{},
&appsv1alpha1.ConfigurationList{},
&parametersv1alpha1.ComponentParameterList{},
&corev1.ServiceAccountList{},
&rbacv1.RoleBindingList{},
}
Expand Down
62 changes: 0 additions & 62 deletions controllers/apps/transformer_component_parameters.go

This file was deleted.

Loading

0 comments on commit 6f0dff5

Please sign in to comment.