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: refactor parameters partV: decouple apps dependence on parameters and tidy up #8620

Draft
wants to merge 7 commits into
base: support/improvement-parameters-api-part2
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion apis/parameters/v1alpha1/paramconfigrenderer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:resource:categories={kubeblocks},scope=Cluster,shortName=paramstemplate
// +kubebuilder:resource:categories={kubeblocks},scope=Cluster,shortName=pcr
// +kubebuilder:printcolumn:name="COMPD",type="string",JSONPath=".spec.componentDef",description="componentdefinition name"
// +kubebuilder:printcolumn:name="PHASE",type="string",JSONPath=".status.phase",description="status phase"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down
10 changes: 8 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import (

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"
experimentalv1alpha1 "github.com/apecloud/kubeblocks/apis/experimental/v1alpha1"
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
Expand Down Expand Up @@ -114,7 +113,6 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(appsv1alpha1.AddToScheme(scheme))
utilruntime.Must(appsv1beta1.AddToScheme(scheme))
utilruntime.Must(appsv1.AddToScheme(scheme))
utilruntime.Must(opsv1alpha1.AddToScheme(scheme))
utilruntime.Must(dpv1alpha1.AddToScheme(scheme))
Expand Down Expand Up @@ -606,6 +604,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Parameter")
os.Exit(1)
}
if err = (&parameterscontrollers.ComponentDrivenParameterReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("component-driven-parameter-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ComponentParameter")
os.Exit(1)
}
if err = (&parameterscontrollers.ComponentParameterReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
listKind: ParamConfigRendererList
plural: paramconfigrenderers
shortNames:
- paramstemplate
- pcr
singular: paramconfigrenderer
scope: Cluster
versions:
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 @@ -38,7 +38,6 @@ import (

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"
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
workloadsv1 "github.com/apecloud/kubeblocks/apis/workloads/v1"
Expand Down Expand Up @@ -169,7 +168,6 @@ func (c *clusterTransformContext) traverse(f func(spec *appsv1.ClusterComponentS

func init() {
model.AddScheme(appsv1alpha1.AddToScheme)
model.AddScheme(appsv1beta1.AddToScheme)
model.AddScheme(appsv1.AddToScheme)
model.AddScheme(dpv1alpha1.AddToScheme)
model.AddScheme(snapshotv1.AddToScheme)
Expand Down
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
2 changes: 0 additions & 2 deletions controllers/apps/transform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

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"
extensionsv1alpha1 "github.com/apecloud/kubeblocks/apis/extensions/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
Expand All @@ -43,7 +42,6 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(rscheme))
utilruntime.Must(appsv1alpha1.AddToScheme(rscheme))
utilruntime.Must(appsv1beta1.AddToScheme(rscheme))
utilruntime.Must(appsv1.AddToScheme(rscheme))
utilruntime.Must(dpv1alpha1.AddToScheme(rscheme))
utilruntime.Must(snapshotv1.AddToScheme(rscheme))
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
Loading