Skip to content

Commit dee99c2

Browse files
committed
rebase and fix license header
1 parent a1be329 commit dee99c2

File tree

8 files changed

+145
-48
lines changed

8 files changed

+145
-48
lines changed

controllers/apps/transformer_component_reconfigure.go renamed to controllers/apps/component/transformer_component_reload_sidecar.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
44
This file is part of KubeBlocks project
55
@@ -17,16 +17,19 @@ You should have received a copy of the GNU Affero General Public License
1717
along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
package apps
20+
package component
2121

2222
import (
2323
"context"
2424

25+
"github.com/pkg/errors"
2526
corev1 "k8s.io/api/core/v1"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
28+
"k8s.io/apimachinery/pkg/types"
2729
"sigs.k8s.io/controller-runtime/pkg/client"
2830

2931
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
32+
appsutil "github.com/apecloud/kubeblocks/controllers/apps/util"
3033
"github.com/apecloud/kubeblocks/pkg/common"
3134
"github.com/apecloud/kubeblocks/pkg/configuration/core"
3235
"github.com/apecloud/kubeblocks/pkg/controller/component"
@@ -48,9 +51,8 @@ func (t *componentReloadActionSidecarTransformer) Transform(ctx graph.TransformC
4851
transCtx, _ := ctx.(*componentTransformContext)
4952

5053
comp := transCtx.Component
51-
cluster := transCtx.Cluster
5254
compOrig := transCtx.ComponentOrig
53-
synthesizeComp := transCtx.SynthesizeComponent
55+
builtinComp := transCtx.SynthesizeComponent
5456

5557
if model.IsObjectDeleting(compOrig) {
5658
return nil
@@ -61,18 +63,30 @@ func (t *componentReloadActionSidecarTransformer) Transform(ctx graph.TransformC
6163
return nil
6264
}
6365

66+
clusterKey := types.NamespacedName{
67+
Namespace: builtinComp.Namespace,
68+
Name: builtinComp.ClusterName,
69+
}
70+
cluster := &appsv1.Cluster{}
71+
if err := t.Client.Get(transCtx, clusterKey, cluster); err != nil {
72+
if apierrors.IsNotFound(err) {
73+
return nil
74+
}
75+
return errors.Wrap(err, "obtain the cluster object error for restore")
76+
}
77+
6478
reconcileCtx := &render.ResourceCtx{
6579
Context: transCtx.Context,
6680
Client: t.Client,
6781
Namespace: comp.GetNamespace(),
68-
ClusterName: synthesizeComp.ClusterName,
69-
ComponentName: synthesizeComp.Name,
82+
ClusterName: builtinComp.ClusterName,
83+
ComponentName: builtinComp.Name,
7084
}
7185

7286
var configmaps []*corev1.ConfigMap
7387
cachedObjs := resolveRerenderDependOnObjects(dag)
74-
for _, tpls := range [][]appsv1.ComponentTemplateSpec{synthesizeComp.ScriptTemplates, synthesizeComp.ConfigTemplates} {
75-
objects, err := render.RenderTemplate(reconcileCtx, cluster, synthesizeComp, comp, cachedObjs, tpls)
88+
for _, tpls := range [][]appsv1.ComponentTemplateSpec{builtinComp.ScriptTemplates, builtinComp.ConfigTemplates} {
89+
objects, err := render.RenderTemplate(reconcileCtx, cluster, builtinComp, comp, cachedObjs, tpls)
7690
if err != nil {
7791
return err
7892
}
@@ -83,14 +97,14 @@ func (t *componentReloadActionSidecarTransformer) Transform(ctx graph.TransformC
8397
if err := ensureConfigMapsPresence(transCtx, graphCli, dag, configmaps...); err != nil {
8498
return err
8599
}
86-
if err := updatePodVolumes(synthesizeComp.PodSpec, synthesizeComp); err != nil {
100+
if err := updatePodVolumes(builtinComp.PodSpec, builtinComp); err != nil {
87101
return err
88102
}
89-
if len(synthesizeComp.ConfigTemplates) == 0 {
103+
if len(builtinComp.ConfigTemplates) == 0 {
90104
return nil
91105
}
92106

93-
return configctrl.BuildReloadActionContainer(reconcileCtx, cluster, synthesizeComp, transCtx.CompDef, configmaps)
107+
return configctrl.BuildReloadActionContainer(reconcileCtx, cluster, builtinComp, transCtx.CompDef, configmaps)
94108
}
95109

96110
func ensureConfigMapsPresence(ctx context.Context, cli model.GraphClient, dag *graph.DAG, configmaps ...*corev1.ConfigMap) error {
@@ -100,7 +114,7 @@ func ensureConfigMapsPresence(ctx context.Context, cli model.GraphClient, dag *g
100114
if !apierrors.IsNotFound(err) {
101115
return err
102116
}
103-
cli.Create(dag, configmap, inDataContext4G())
117+
cli.Create(dag, configmap, appsutil.InDataContext4G())
104118
}
105119
}
106120
return nil

controllers/parameters/componentdrivenparameter_controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
44
This file is part of KubeBlocks project
55
@@ -200,9 +200,7 @@ func buildComponentParameter(reqCtx intctrlutil.RequestCtx, reader client.Reader
200200
AddLabelsInMap(constant.GetCompLabelsWithDef(clusterName, componentName, cmpd.Name)).
201201
ClusterRef(clusterName).
202202
Component(componentName).
203-
SetConfigurationItem(configctrl.ClassifyParamsFromConfigTemplate(
204-
intctrlutil.TransformComponentParameters(comp.Spec.InitParameters),
205-
cmpd, paramsDefs, tpls)).
203+
SetConfigurationItem(configctrl.ClassifyParamsFromConfigTemplate(nil, cmpd, paramsDefs, tpls)).
206204
GetObject()
207205
if err = intctrlutil.SetOwnerReference(comp, parameterObj); err != nil {
208206
return nil, err

controllers/parameters/componentdrivenparameter_controller_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
This file is part of KubeBlocks project
75
8-
http://www.apache.org/licenses/LICENSE-2.0
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
910
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
1518
*/
1619

1720
package parameters

pkg/controller/configuration/config_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
44
This file is part of KubeBlocks project
55

pkg/controller/configuration/template_render.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
This file is part of KubeBlocks project
75
8-
http://www.apache.org/licenses/LICENSE-2.0
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
910
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
1518
*/
1619

1720
package configuration

pkg/controller/configuration/template_render_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
This file is part of KubeBlocks project
75
8-
http://www.apache.org/licenses/LICENSE-2.0
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
910
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
1518
*/
1619

1720
package configuration

pkg/controller/configuration/template_validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2022-2024 ApeCloud Co., Ltd
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
33
44
This file is part of KubeBlocks project
55

pkg/controller/render/render_utils.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Copyright (C) 2022-2025 ApeCloud Co., Ltd
3+
4+
This file is part of KubeBlocks project
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package render
21+
22+
import (
23+
corev1 "k8s.io/api/core/v1"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
26+
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
27+
"github.com/apecloud/kubeblocks/pkg/configuration/core"
28+
"github.com/apecloud/kubeblocks/pkg/controller/component"
29+
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
30+
)
31+
32+
// RenderTemplate renders multiple component templates into Kubernetes ConfigMap objects.
33+
//
34+
// Parameters:
35+
// - resourceCtx: The context for resource operations.
36+
// - cluster: The cluster being reconciled.
37+
// - synthesizedComponent: Details of the synthesized component.
38+
// - comp: The component being reconciled.
39+
// - localObjs: A cache of client objects.
40+
// - tpls: A list of component template specifications.
41+
//
42+
// Returns:
43+
// - A slice of pointers to the rendered ConfigMap objects.
44+
// - An error if the rendering or validation fails.
45+
func RenderTemplate(resourceCtx *ResourceCtx,
46+
cluster *appsv1.Cluster,
47+
synthesizedComponent *component.SynthesizedComponent,
48+
comp *appsv1.Component,
49+
localObjs []client.Object,
50+
tpls []appsv1.ComponentTemplateSpec) ([]*corev1.ConfigMap, error) {
51+
var err error
52+
var configMap *corev1.ConfigMap
53+
54+
reconcileCtx := &ReconcileCtx{
55+
ResourceCtx: resourceCtx,
56+
Cluster: cluster,
57+
Component: comp,
58+
SynthesizedComponent: synthesizedComponent,
59+
PodSpec: synthesizedComponent.PodSpec,
60+
Cache: localObjs,
61+
}
62+
63+
tplBuilder := NewTemplateBuilder(reconcileCtx)
64+
configMaps := make([]*corev1.ConfigMap, 0, len(tpls))
65+
for _, template := range tpls {
66+
cmName := core.GetComponentCfgName(cluster.Name, synthesizedComponent.Name, template.Name)
67+
if configMap, err = tplBuilder.RenderComponentTemplate(template, cmName, nil); err != nil {
68+
return nil, err
69+
}
70+
if err = intctrlutil.SetOwnerReference(comp, configMap); err != nil {
71+
return nil, err
72+
}
73+
configMaps = append(configMaps, configMap)
74+
}
75+
return configMaps, nil
76+
}

0 commit comments

Comments
 (0)