Skip to content

Commit

Permalink
chore: refactor parameters partII: refactor template render (#8588)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Dec 11, 2024
1 parent ad4c4c2 commit 248487d
Show file tree
Hide file tree
Showing 37 changed files with 695 additions and 566 deletions.
2 changes: 1 addition & 1 deletion cmd/reloader/template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func main() {
}

mergePolicy, err := configuration.NewTemplateMerger(configRenderMeta.LegacyRenderedConfigSpec.ConfigTemplateExtension,
context.TODO(), nil, nil, *configRenderMeta.ComponentConfigSpec, &appsv1beta1.ConfigConstraintSpec{
nil, *configRenderMeta.ComponentConfigSpec, &appsv1beta1.ConfigConstraintSpec{
FileFormatConfig: &configRenderMeta.FormatterConfig,
})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/configuration/config_reconcile_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
"github.com/apecloud/kubeblocks/pkg/controller/component"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
"github.com/apecloud/kubeblocks/pkg/generics"
)

Expand All @@ -45,7 +46,7 @@ type configReconcileContext struct {
}

func newConfigReconcileContext(ctx context.Context,
resourceCtx *configctrl.ResourceCtx,
resourceCtx *render.ResourceCtx,
cm *corev1.ConfigMap,
configSpecName string,
matchingLabels client.MatchingLabels) *configReconcileContext {
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/configuration/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/controller/component"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/multicluster"
"github.com/apecloud/kubeblocks/pkg/controller/render"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)
Expand Down Expand Up @@ -96,7 +96,7 @@ func (r *ConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

fetcherTask := &Task{}
err = fetcherTask.Init(&configctrl.ResourceCtx{
err = fetcherTask.Init(&render.ResourceCtx{
Context: ctx,
Client: r.Client,
Namespace: config.Namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/configuration/core"
cfgutil "github.com/apecloud/kubeblocks/pkg/configuration/util"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ var _ = Describe("Configuration Controller", func() {

By("wait for configuration status to be init phase.")
Eventually(checkCfgStatus(appsv1alpha1.CInitPhase)).Should(BeFalse())
Expect(initConfiguration(&configctrl.ResourceCtx{
Expect(initConfiguration(&render.ResourceCtx{
Client: k8sClient,
Context: ctx,
Namespace: testCtx.DefaultNamespace,
Expand Down Expand Up @@ -99,7 +99,7 @@ var _ = Describe("Configuration Controller", func() {
Namespace: testCtx.DefaultNamespace,
}

Expect(initConfiguration(&configctrl.ResourceCtx{
Expect(initConfiguration(&render.ResourceCtx{
Client: k8sClient,
Context: ctx,
Namespace: testCtx.DefaultNamespace,
Expand Down Expand Up @@ -140,7 +140,7 @@ var _ = Describe("Configuration Controller", func() {

By("wait for configuration status to be init phase.")
Eventually(checkCfgStatus(appsv1alpha1.CInitPhase)).Should(BeFalse())
Expect(initConfiguration(&configctrl.ResourceCtx{
Expect(initConfiguration(&render.ResourceCtx{
Client: k8sClient,
Context: ctx,
Namespace: testCtx.DefaultNamespace,
Expand Down
5 changes: 3 additions & 2 deletions controllers/apps/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/apecloud/kubeblocks/pkg/controller/builder"
"github.com/apecloud/kubeblocks/pkg/controller/component"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
"github.com/apecloud/kubeblocks/pkg/generics"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
)
Expand Down Expand Up @@ -151,11 +152,11 @@ func mockReconcileResource() (*corev1.ConfigMap, *appsv1beta1.ConfigConstraint,
return configmap, constraint, clusterObj, compObj, synthesizedComp
}

func initConfiguration(resourceCtx *configctrl.ResourceCtx,
func initConfiguration(resourceCtx *render.ResourceCtx,
synthesizedComponent *component.SynthesizedComponent,
clusterObj *appsv1.Cluster,
componentObj *appsv1.Component) error {
return configctrl.NewCreatePipeline(configctrl.ReconcileCtx{
return configctrl.NewCreatePipeline(render.ReconcileCtx{
ResourceCtx: resourceCtx,
Component: componentObj,
SynthesizedComponent: synthesizedComponent,
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/configuration/reconcile_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/apecloud/kubeblocks/pkg/controller/builder"
"github.com/apecloud/kubeblocks/pkg/controller/component"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
)

Expand Down Expand Up @@ -98,7 +99,7 @@ func syncImpl(fetcher *Task,
synthesizedComponent *component.SynthesizedComponent,
revision string,
configSpec *appsv1.ComponentConfigSpec) (err error) {
err = configctrl.NewReconcilePipeline(configctrl.ReconcileCtx{
err = configctrl.NewReconcilePipeline(render.ReconcileCtx{
ResourceCtx: fetcher.ResourceCtx,
Cluster: fetcher.ClusterObj,
Component: fetcher.ComponentObj,
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/configuration/reconfigure_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import (
cfgcm "github.com/apecloud/kubeblocks/pkg/configuration/config_manager"
"github.com/apecloud/kubeblocks/pkg/configuration/core"
"github.com/apecloud/kubeblocks/pkg/constant"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/multicluster"
"github.com/apecloud/kubeblocks/pkg/controller/render"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)
Expand Down Expand Up @@ -185,7 +185,7 @@ func (r *ReconfigureReconciler) sync(reqCtx intctrlutil.RequestCtx, configMap *c

reconcileContext := newConfigReconcileContext(
reqCtx.Ctx,
&configctrl.ResourceCtx{
&render.ResourceCtx{
Context: reqCtx.Ctx,
Client: r.Client,
Namespace: configMap.Namespace,
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/configuration/relatedresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
"github.com/apecloud/kubeblocks/pkg/constant"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/render"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
)

Expand All @@ -55,7 +56,7 @@ func prepareRelatedResource(reqCtx intctrlutil.RequestCtx, client client.Client,
componentName: cm.Labels[constant.KBAppComponentLabelKey],
}

fetcher := configctrl.NewResourceFetcher(&configctrl.ResourceCtx{
fetcher := configctrl.NewResourceFetcher(&render.ResourceCtx{
Context: reqCtx.Ctx,
Client: client,
Namespace: cm.Namespace,
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/transformer_component_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/apecloud/kubeblocks/pkg/common"
configctrl "github.com/apecloud/kubeblocks/pkg/controller/configuration"
"github.com/apecloud/kubeblocks/pkg/controller/graph"
"github.com/apecloud/kubeblocks/pkg/controller/model"
"github.com/apecloud/kubeblocks/pkg/controller/plan"
"github.com/apecloud/kubeblocks/pkg/controller/render"
)

// componentConfigurationTransformer handles component configuration render
Expand Down Expand Up @@ -70,7 +70,7 @@ func (t *componentConfigurationTransformer) Transform(ctx graph.TransformContext

// configuration render
if err := plan.RenderConfigNScriptFiles(
&configctrl.ResourceCtx{
&render.ResourceCtx{
Context: transCtx.Context,
Client: t.Client,
Namespace: comp.GetNamespace(),
Expand Down
97 changes: 0 additions & 97 deletions pkg/controller/configuration/config_template.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/controller/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const (
mysqlConfigName = "mysql-component-config"
mysqlConfigConstraintName = "mysql8.0-config-constraints"
mysqlScriptsTemplateName = "apecloud-mysql-scripts"
testConfigContent = "test-config-content"
)

func allFieldsCompDefObj(create bool) *appsv1.ComponentDefinition {
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/configuration/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ import (

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
"github.com/apecloud/kubeblocks/pkg/controller/component"
"github.com/apecloud/kubeblocks/pkg/controller/render"
)

type configOperator struct {
ReconcileCtx
render.ReconcileCtx
}

func NewConfigReconcileTask(resourceCtx *ResourceCtx,
func NewConfigReconcileTask(resourceCtx *render.ResourceCtx,
cluster *appsv1.Cluster,
component *appsv1.Component,
synthesizedComponent *component.SynthesizedComponent,
podSpec *corev1.PodSpec,
localObjs []client.Object,
) *configOperator {
return &configOperator{
ReconcileCtx{
render.ReconcileCtx{
ResourceCtx: resourceCtx,
Cluster: cluster,
Component: component,
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/configuration/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
cfgcore "github.com/apecloud/kubeblocks/pkg/configuration/core"
"github.com/apecloud/kubeblocks/pkg/controller/builder"
"github.com/apecloud/kubeblocks/pkg/controller/component"
"github.com/apecloud/kubeblocks/pkg/controller/render"
testapps "github.com/apecloud/kubeblocks/pkg/testutil/apps"
testutil "github.com/apecloud/kubeblocks/pkg/testutil/k8s"
)
Expand All @@ -51,7 +52,7 @@ var _ = Describe("ConfigurationOperatorTest", func() {
var k8sMockClient *testutil.K8sClientMockHelper

createConfigReconcileTask := func() *configOperator {
task := NewConfigReconcileTask(&ResourceCtx{
task := NewConfigReconcileTask(&render.ResourceCtx{
Client: k8sMockClient.Client(),
Context: ctx,
Namespace: testCtx.DefaultNamespace,
Expand Down
Loading

0 comments on commit 248487d

Please sign in to comment.