Skip to content

Commit f55667e

Browse files
sophon-ztapecloud-bot
authored andcommitted
chore: add new properties formatter for nebula addon (#9528)
(cherry picked from commit ae7016a)
1 parent c571e64 commit f55667e

6 files changed

Lines changed: 55 additions & 33 deletions

File tree

apis/parameters/v1alpha1/types.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ const (
2929

3030
// CfgFileFormat defines formatter of configuration files.
3131
// +enum
32-
// +kubebuilder:validation:Enum={xml,ini,yaml,json,hcl,dotenv,toml,properties,redis,props-plus}
32+
// +kubebuilder:validation:Enum={xml,ini,yaml,json,hcl,dotenv,toml,properties,redis,props-plus,props-ultra}
3333
type CfgFileFormat string
3434

3535
const (
36-
Ini CfgFileFormat = "ini"
37-
YAML CfgFileFormat = "yaml"
38-
JSON CfgFileFormat = "json"
39-
XML CfgFileFormat = "xml"
40-
HCL CfgFileFormat = "hcl"
41-
Dotenv CfgFileFormat = "dotenv"
42-
TOML CfgFileFormat = "toml"
43-
Properties CfgFileFormat = "properties"
44-
RedisCfg CfgFileFormat = "redis"
45-
PropertiesPlus CfgFileFormat = "props-plus"
36+
Ini CfgFileFormat = "ini"
37+
YAML CfgFileFormat = "yaml"
38+
JSON CfgFileFormat = "json"
39+
XML CfgFileFormat = "xml"
40+
HCL CfgFileFormat = "hcl"
41+
Dotenv CfgFileFormat = "dotenv"
42+
TOML CfgFileFormat = "toml"
43+
Properties CfgFileFormat = "properties"
44+
RedisCfg CfgFileFormat = "redis"
45+
PropertiesPlus CfgFileFormat = "props-plus"
46+
PropertiesUltra CfgFileFormat = "props-ultra"
4647
)
4748

4849
// DynamicReloadType defines reload method.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ spec:
109109
- properties
110110
- redis
111111
- props-plus
112+
- props-ultra
112113
type: string
113114
iniConfig:
114115
description: Holds options specific to the 'ini' file format.

deploy/helm/crds/parameters.kubeblocks.io_paramconfigrenderers.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ spec:
109109
- properties
110110
- redis
111111
- props-plus
112+
- props-ultra
112113
type: string
113114
iniConfig:
114115
description: Holds options specific to the 'ini' file format.

docs/developer_docs/api-reference/parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ string
670670
<td></td>
671671
</tr><tr><td><p>&#34;props-plus&#34;</p></td>
672672
<td></td>
673+
</tr><tr><td><p>&#34;props-ultra&#34;</p></td>
674+
<td></td>
673675
</tr><tr><td><p>&#34;redis&#34;</p></td>
674676
<td></td>
675677
</tr><tr><td><p>&#34;toml&#34;</p></td>

pkg/unstructured/properties.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import (
3131
type propertiesConfig struct {
3232
name string
3333
Properties *properties.Properties
34+
35+
// Specifies the separator of key and value while writing the properties, default " = "
36+
writeSeparator string
3437
}
3538

3639
const commentPrefix = "# "
@@ -39,6 +42,9 @@ func init() {
3942
CfgObjectRegistry().RegisterConfigCreator(parametersv1alpha1.PropertiesPlus, func(name string) ConfigObject {
4043
return &propertiesConfig{name: name}
4144
})
45+
CfgObjectRegistry().RegisterConfigCreator(parametersv1alpha1.PropertiesUltra, func(name string) ConfigObject {
46+
return &propertiesConfig{name: name, writeSeparator: "="}
47+
})
4248
}
4349

4450
func (p *propertiesConfig) Update(key string, value any) error {
@@ -83,6 +89,10 @@ func (p *propertiesConfig) Marshal() (string, error) {
8389
return "", nil
8490
}
8591

92+
if p.writeSeparator != "" {
93+
p.Properties.WriteSeparator = p.writeSeparator
94+
}
95+
8696
var buf bytes.Buffer
8797
_, err := p.Properties.WriteComment(&buf, commentPrefix, properties.UTF8)
8898
if err != nil {

pkg/unstructured/properties_test.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import (
2828
)
2929

3030
func TestPropertiesFormat(t *testing.T) {
31-
const propsContext = `
31+
32+
testProperties := func(formatter parametersv1alpha1.CfgFileFormat) {
33+
34+
const propsContext = `
3235
# Time of inactivity after which the broker will discard the deduplication information
3336
# relative to a disconnected producer. Default is 6 hours.
3437
brokerDeduplicationProducerInactivityTimeoutMinutes=360
@@ -53,34 +56,38 @@ brokerMaxConnections=0
5356
# The maximum number of connections per IP. If it exceeds, new connections are rejected.
5457
brokerMaxConnectionsPerIp=0
5558
`
56-
propsConfigObj, err := LoadConfig("props_test", propsContext, parametersv1alpha1.PropertiesPlus)
57-
assert.Nil(t, err)
59+
propsConfigObj, err := LoadConfig("props_test", propsContext, formatter)
60+
assert.Nil(t, err)
5861

59-
assert.EqualValues(t, propsConfigObj.Get("brokerDeduplicationProducerInactivityTimeoutMinutes"), "360")
60-
assert.EqualValues(t, propsConfigObj.Get("maxNamespacesPerTenant.brokerMaxConnections.threadMethod"), "660")
62+
assert.EqualValues(t, propsConfigObj.Get("brokerDeduplicationProducerInactivityTimeoutMinutes"), "360")
63+
assert.EqualValues(t, propsConfigObj.Get("maxNamespacesPerTenant.brokerMaxConnections.threadMethod"), "660")
6164

62-
v, _ := propsConfigObj.GetString("defaultNumberOfNamespaceBundles")
63-
assert.EqualValues(t, v, "4")
64-
v, _ = propsConfigObj.GetString("brokerMaxConnectionsPerIp")
65-
assert.EqualValues(t, v, "0")
65+
v, _ := propsConfigObj.GetString("defaultNumberOfNamespaceBundles")
66+
assert.EqualValues(t, v, "4")
67+
v, _ = propsConfigObj.GetString("brokerMaxConnectionsPerIp")
68+
assert.EqualValues(t, v, "0")
6669

67-
v, err = propsConfigObj.GetString("profiles.web.xxxx")
68-
assert.Nil(t, err)
69-
assert.EqualValues(t, v, "")
70+
v, err = propsConfigObj.GetString("profiles.web.xxxx")
71+
assert.Nil(t, err)
72+
assert.EqualValues(t, v, "")
7073

71-
dumpContext, err := propsConfigObj.Marshal()
72-
assert.Nil(t, err)
73-
newObj, err := LoadConfig("props_test", dumpContext, parametersv1alpha1.PropertiesPlus)
74-
assert.Nil(t, err)
75-
assert.EqualValues(t, newObj.GetAllParameters(), propsConfigObj.GetAllParameters())
74+
dumpContext, err := propsConfigObj.Marshal()
75+
assert.Nil(t, err)
76+
newObj, err := LoadConfig("props_test", dumpContext, parametersv1alpha1.PropertiesPlus)
77+
assert.Nil(t, err)
78+
assert.EqualValues(t, newObj.GetAllParameters(), propsConfigObj.GetAllParameters())
79+
80+
assert.EqualValues(t, newObj.SubConfig("test"), nil)
7681

77-
assert.EqualValues(t, newObj.SubConfig("test"), nil)
82+
assert.Nil(t, propsConfigObj.Update("profiles.web.timeout_before_checking_execution_speed", 200))
83+
assert.EqualValues(t, propsConfigObj.Get("profiles.web.timeout_before_checking_execution_speed"), "200")
7884

79-
assert.Nil(t, propsConfigObj.Update("profiles.web.timeout_before_checking_execution_speed", 200))
80-
assert.EqualValues(t, propsConfigObj.Get("profiles.web.timeout_before_checking_execution_speed"), "200")
85+
assert.Nil(t, propsConfigObj.Update("defaultNumberOfNamespaceBundles", "600"))
86+
assert.EqualValues(t, propsConfigObj.Get("defaultNumberOfNamespaceBundles"), "600")
87+
}
8188

82-
assert.Nil(t, propsConfigObj.Update("defaultNumberOfNamespaceBundles", "600"))
83-
assert.EqualValues(t, propsConfigObj.Get("defaultNumberOfNamespaceBundles"), "600")
89+
testProperties(parametersv1alpha1.PropertiesPlus)
90+
testProperties(parametersv1alpha1.PropertiesUltra)
8491
}
8592

8693
func TestPropertiesEmpty(t *testing.T) {

0 commit comments

Comments
 (0)