Skip to content

Commit a4e4088

Browse files
committed
feat: support unmanaged parameter updates
1 parent 373f487 commit a4e4088

File tree

12 files changed

+675
-99
lines changed

12 files changed

+675
-99
lines changed

apis/parameters/v1alpha1/componentparameter_types.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ type ParameterUpdate struct {
203203
Value *string `json:"value,omitempty"`
204204
}
205205

206-
// UnmanagedParameterUpdate describes unmanaged parameter updates scoped to a target template, file, and optional section.
206+
// UnmanagedParameterUpdate describes unmanaged parameter updates scoped to a target template and file.
207207
type UnmanagedParameterUpdate struct {
208208
// Template is the target config template name.
209209
//
@@ -215,12 +215,20 @@ type UnmanagedParameterUpdate struct {
215215
// +kubebuilder:validation:Required
216216
File string `json:"file"`
217217

218+
// Updates are the unmanaged parameter changes to apply within the target file scope.
219+
//
220+
// +optional
221+
Updates []UnmanagedParameterSectionUpdate `json:"updates,omitempty"`
222+
}
223+
224+
// UnmanagedParameterSectionUpdate describes unmanaged parameter updates scoped to an optional section within a file.
225+
type UnmanagedParameterSectionUpdate struct {
218226
// Section optionally identifies a nested scope for formats that support it.
219227
//
220228
// +optional
221229
Section *string `json:"section,omitempty"`
222230

223-
// Updates are the unmanaged parameter changes to apply within the target file scope.
231+
// Updates are the unmanaged parameter changes to apply within the target section scope.
224232
//
225233
// +optional
226234
Updates []ParameterUpdate `json:"updates,omitempty"`

apis/parameters/v1alpha1/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ type ParametersInFile struct {
104104
//
105105
// +optional
106106
Parameters map[string]*string `json:"parameters,omitempty"`
107+
108+
// Represents unmanaged parameter updates for a single configuration file.
109+
//
110+
// +optional
111+
UnmanagedUpdates []UnmanagedParameterSectionUpdate `json:"unmanagedUpdates,omitempty"`
107112
}
108113

109114
type ComponentParameters map[string]*string

apis/parameters/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/parameters.kubeblocks.io_componentparameters.yaml

Lines changed: 97 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,43 @@ spec:
102102
description: Represents the updated parameters for a single
103103
configuration file.
104104
type: object
105+
unmanagedUpdates:
106+
description: Represents unmanaged parameter updates for
107+
a single configuration file.
108+
items:
109+
description: UnmanagedParameterSectionUpdate describes
110+
unmanaged parameter updates scoped to an optional
111+
section within a file.
112+
properties:
113+
section:
114+
description: Section optionally identifies a nested
115+
scope for formats that support it.
116+
type: string
117+
updates:
118+
description: Updates are the unmanaged parameter
119+
changes to apply within the target section scope.
120+
items:
121+
description: ParameterUpdate is an explicit parameter
122+
update.
123+
properties:
124+
key:
125+
description: Key is the logical parameter
126+
key defined in ParametersDefinition.
127+
type: string
128+
type:
129+
description: Type defines the update type.
130+
type: string
131+
value:
132+
description: Value is used by set/update style
133+
operations.
134+
type: string
135+
required:
136+
- key
137+
- type
138+
type: object
139+
type: array
140+
type: object
141+
type: array
105142
type: object
106143
description: |-
107144
Specifies the user-defined configuration parameters.
@@ -701,39 +738,50 @@ spec:
701738
not defined in ParametersDefinition.
702739
items:
703740
description: UnmanagedParameterUpdate describes unmanaged parameter
704-
updates scoped to a target template, file, and optional section.
741+
updates scoped to a target template and file.
705742
properties:
706743
file:
707744
description: File is the target config file name under the
708745
template.
709746
type: string
710-
section:
711-
description: Section optionally identifies a nested scope
712-
for formats that support it.
713-
type: string
714747
template:
715748
description: Template is the target config template name.
716749
type: string
717750
updates:
718751
description: Updates are the unmanaged parameter changes
719752
to apply within the target file scope.
720753
items:
721-
description: ParameterUpdate is an explicit parameter
722-
update.
754+
description: UnmanagedParameterSectionUpdate describes
755+
unmanaged parameter updates scoped to an optional section
756+
within a file.
723757
properties:
724-
key:
725-
description: Key is the logical parameter key defined
726-
in ParametersDefinition.
727-
type: string
728-
type:
729-
description: Type defines the update type.
758+
section:
759+
description: Section optionally identifies a nested
760+
scope for formats that support it.
730761
type: string
731-
value:
732-
description: Value is used by set/update style operations.
733-
type: string
734-
required:
735-
- key
736-
- type
762+
updates:
763+
description: Updates are the unmanaged parameter changes
764+
to apply within the target section scope.
765+
items:
766+
description: ParameterUpdate is an explicit parameter
767+
update.
768+
properties:
769+
key:
770+
description: Key is the logical parameter key
771+
defined in ParametersDefinition.
772+
type: string
773+
type:
774+
description: Type defines the update type.
775+
type: string
776+
value:
777+
description: Value is used by set/update style
778+
operations.
779+
type: string
780+
required:
781+
- key
782+
- type
783+
type: object
784+
type: array
737785
type: object
738786
type: array
739787
required:
@@ -808,39 +856,50 @@ spec:
808856
not defined in ParametersDefinition.
809857
items:
810858
description: UnmanagedParameterUpdate describes unmanaged parameter
811-
updates scoped to a target template, file, and optional section.
859+
updates scoped to a target template and file.
812860
properties:
813861
file:
814862
description: File is the target config file name under the
815863
template.
816864
type: string
817-
section:
818-
description: Section optionally identifies a nested scope
819-
for formats that support it.
820-
type: string
821865
template:
822866
description: Template is the target config template name.
823867
type: string
824868
updates:
825869
description: Updates are the unmanaged parameter changes
826870
to apply within the target file scope.
827871
items:
828-
description: ParameterUpdate is an explicit parameter
829-
update.
872+
description: UnmanagedParameterSectionUpdate describes
873+
unmanaged parameter updates scoped to an optional section
874+
within a file.
830875
properties:
831-
key:
832-
description: Key is the logical parameter key defined
833-
in ParametersDefinition.
876+
section:
877+
description: Section optionally identifies a nested
878+
scope for formats that support it.
834879
type: string
835-
type:
836-
description: Type defines the update type.
837-
type: string
838-
value:
839-
description: Value is used by set/update style operations.
840-
type: string
841-
required:
842-
- key
843-
- type
880+
updates:
881+
description: Updates are the unmanaged parameter changes
882+
to apply within the target section scope.
883+
items:
884+
description: ParameterUpdate is an explicit parameter
885+
update.
886+
properties:
887+
key:
888+
description: Key is the logical parameter key
889+
defined in ParametersDefinition.
890+
type: string
891+
type:
892+
description: Type defines the update type.
893+
type: string
894+
value:
895+
description: Value is used by set/update style
896+
operations.
897+
type: string
898+
required:
899+
- key
900+
- type
901+
type: object
902+
type: array
844903
type: object
845904
type: array
846905
required:

config/crd/bases/parameters.kubeblocks.io_parameters.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,46 @@ spec:
227227
description: Represents the updated parameters for
228228
a single configuration file.
229229
type: object
230+
unmanagedUpdates:
231+
description: Represents unmanaged parameter updates
232+
for a single configuration file.
233+
items:
234+
description: UnmanagedParameterSectionUpdate describes
235+
unmanaged parameter updates scoped to an optional
236+
section within a file.
237+
properties:
238+
section:
239+
description: Section optionally identifies
240+
a nested scope for formats that support
241+
it.
242+
type: string
243+
updates:
244+
description: Updates are the unmanaged parameter
245+
changes to apply within the target section
246+
scope.
247+
items:
248+
description: ParameterUpdate is an explicit
249+
parameter update.
250+
properties:
251+
key:
252+
description: Key is the logical parameter
253+
key defined in ParametersDefinition.
254+
type: string
255+
type:
256+
description: Type defines the update
257+
type.
258+
type: string
259+
value:
260+
description: Value is used by set/update
261+
style operations.
262+
type: string
263+
required:
264+
- key
265+
- type
266+
type: object
267+
type: array
268+
type: object
269+
type: array
230270
type: object
231271
description: Contains the updated parameters.
232272
type: object

controllers/parameters/componentparameter_controller_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,51 @@ var _ = Describe("ComponentParameter Controller", func() {
232232
})).Should(Succeed())
233233
})
234234

235+
It("should project desired unmanaged updates into file content", func() {
236+
_, _, _, _, _ = mockReconcileResource()
237+
238+
cfgKey := client.ObjectKey{
239+
Namespace: testCtx.DefaultNamespace,
240+
Name: core.GenerateComponentConfigurationName(clusterName, defaultCompName),
241+
}
242+
Eventually(testapps.GetAndChangeObj(&testCtx, cfgKey, func(cfg *parametersv1alpha1.ComponentParameter) {
243+
cfg.Spec.Desired = &parametersv1alpha1.ParameterInputs{
244+
Assignments: map[string]*string{
245+
"max_connections": cfgutil.ToPointer("2000"),
246+
},
247+
UnmanagedUpdates: []parametersv1alpha1.UnmanagedParameterUpdate{{
248+
Template: configSpecName,
249+
File: testparameters.MysqlConfigFile,
250+
Updates: []parametersv1alpha1.UnmanagedParameterSectionUpdate{{
251+
Section: cfgutil.ToPointer("mysqld"),
252+
Updates: []parametersv1alpha1.ParameterUpdate{
253+
{
254+
Type: parametersv1alpha1.ParameterUpdateSet,
255+
Key: "custom_local",
256+
Value: cfgutil.ToPointer("on"),
257+
},
258+
{
259+
Type: parametersv1alpha1.ParameterUpdateRemove,
260+
Key: "gtid_mode",
261+
},
262+
},
263+
}},
264+
}},
265+
}
266+
})).Should(Succeed())
267+
268+
Eventually(testapps.CheckObj(&testCtx, cfgKey, func(g Gomega, cfg *parametersv1alpha1.ComponentParameter) {
269+
item := parameters.GetConfigTemplateItem(&cfg.Spec, configSpecName)
270+
g.Expect(item).ShouldNot(BeNil())
271+
g.Expect(item.ConfigFileParams).Should(HaveKey(testparameters.MysqlConfigFile))
272+
fileParams := item.ConfigFileParams[testparameters.MysqlConfigFile]
273+
g.Expect(fileParams.UnmanagedUpdates).Should(HaveLen(1))
274+
g.Expect(fileParams.UnmanagedUpdates[0].Section).Should(Equal(cfgutil.ToPointer("mysqld")))
275+
g.Expect(fileParams.UnmanagedUpdates[0].Updates).Should(HaveLen(2))
276+
g.Expect(fileParams.Parameters).Should(HaveKeyWithValue("max_connections", cfgutil.ToPointer("2000")))
277+
})).Should(Succeed())
278+
})
279+
235280
It("should render both new PD and legacy PCR files in mixed mode", func() {
236281
templateObj, _, compObj, _, _ := mockReconcileResource()
237282

0 commit comments

Comments
 (0)