Skip to content

Commit 8d58e6b

Browse files
authored
Customize default number of free API slots for NDBAPI apps (#3)
1 parent ec7dee4 commit 8d58e6b

File tree

8 files changed

+119
-3
lines changed

8 files changed

+119
-3
lines changed

deploy/charts/ndb-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: ndb-operator
3-
version: 0.1.1
3+
version: 0.1.2
44
kubeVersion: ">= 1.19.0"
55
description: A Helm chart for deploying the Oracle MySQL NDB Cluster Operator
66
appVersion: "8.0.26-0.1.0"

deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ spec:
4242
spec:
4343
description: NdbClusterSpec defines the desired state of MySQL Ndb Cluster
4444
properties:
45+
apiFreeSlots:
46+
default: 3
47+
description: Number of free API slots for other NDBAPI applications
48+
format: int32
49+
type: integer
4550
dataMemory:
4651
default: 98M
4752
description: 'DataMemory specifies the space available per data node

deploy/manifests/ndb-operator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ spec:
4141
spec:
4242
description: NdbClusterSpec defines the desired state of MySQL Ndb Cluster
4343
properties:
44+
apiFreeSlots:
45+
default: 3
46+
description: Number of free API slots for other NDBAPI applications
47+
format: int32
48+
type: integer
4449
dataMemory:
4550
default: 98M
4651
description: 'DataMemory specifies the space available per data node

docs/NdbCluster-CRD.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ Allowed values 1M - 1T. More info :
135135
</tr>
136136
<tr>
137137
<td>
138+
<code>apiFreeSlots</code><br/>
139+
<em>
140+
int32
141+
</em>
142+
</td>
143+
<td>
144+
<em>(Optional)</em>
145+
<p>Number of free API slots for other NDBAPI applications. Default is: 3</p>
146+
</td>
147+
</tr>
148+
<tr>
149+
<td>
138150
<code>extraNdbdDefaultParams</code><br/>
139151
<em>
140152
string

pkg/apis/ndbcontroller/v1alpha1/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type NdbClusterSpec struct {
8484
// +kubebuilder:validation:Pattern="[0-9]+[MGT]"
8585
DataMemory string `json:"dataMemory,omitempty"`
8686

87+
// Number of free API slots for other NDBAPI applications
88+
// +kubebuilder:default=3
89+
// +optional
90+
ApiFreeSlots int32 `json:"apiFreeSlots,omitempty"`
91+
8792
// Extra ndbd default parameters to be added to [ndbd default] section of config.ini file.
8893
// Exception: parameters DataMemory and NoOfReplicas should not be added as
8994
// they are handled through CRD attributes dataMemory and redundancyLevel.

pkg/helpers/testutils/ndbtestcreator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func NewTestNdb(namespace string, name string, noOfNodes int32) *ndbcontroller.N
2222
},
2323
Spec: ndbcontroller.NdbClusterSpec{
2424
NodeCount: noOfNodes,
25+
ApiFreeSlots: 3,
2526
RedundancyLevel: 2,
2627
Mysqld: &ndbcontroller.NdbMysqldSpec{
2728
NodeCount: noOfNodes,

pkg/resources/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func GetConfigString(ndb *v1alpha1.NdbCluster, oldResourceContext *ResourceConte
9090
}
9191

9292
// Calculate the total number of API slots to be set in the config.
93-
// slots required for mysql servers + 3 free slot for other NDBAPi apps
94-
requiredNumOfAPISlots := requiredNumOfSlotsForMySQLServer + 3
93+
// slots required for mysql servers + free slot for other NDBAPi apps
94+
requiredNumOfAPISlots := requiredNumOfSlotsForMySQLServer + ndb.Spec.ApiFreeSlots
9595

9696
tmpl := template.New("config.ini")
9797
tmpl.Funcs(template.FuncMap{

pkg/resources/config_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,91 @@ NodeId=148
205205
}
206206

207207
}
208+
209+
func Test_GetConfigString_ApiFreeSlots(t *testing.T) {
210+
ndb := testutils.NewTestNdb("default", "example-ndb-3", 1)
211+
ndb.Spec.DataMemory = "80M"
212+
ndb.Spec.ApiFreeSlots = 10
213+
configString, err := GetConfigString(ndb, nil)
214+
if err != nil {
215+
t.Errorf("Failed to generate config string from Ndb : %s", err)
216+
}
217+
218+
expectedConfigString := `# auto generated config.ini - do not edit
219+
#
220+
# ConfigHash=######
221+
# NumOfMySQLServers=1
222+
223+
[system]
224+
ConfigGenerationNumber=0
225+
Name=example-ndb-3
226+
227+
[ndbd default]
228+
NoOfReplicas=2
229+
DataMemory=80M
230+
# Use a fixed ServerPort for all data nodes
231+
ServerPort=1186
232+
233+
[tcp default]
234+
AllowUnresolvedHostnames=1
235+
236+
[ndb_mgmd]
237+
NodeId=1
238+
Hostname=example-ndb-3-mgmd-0.example-ndb-3-mgmd.default.svc.cluster.local
239+
DataDir=/var/lib/ndb
240+
241+
[ndb_mgmd]
242+
NodeId=2
243+
Hostname=example-ndb-3-mgmd-1.example-ndb-3-mgmd.default.svc.cluster.local
244+
DataDir=/var/lib/ndb
245+
246+
[ndbd]
247+
NodeId=3
248+
Hostname=example-ndb-3-ndbd-0.example-ndb-3-ndbd.default.svc.cluster.local
249+
DataDir=/var/lib/ndb
250+
251+
[api]
252+
NodeId=145
253+
254+
[api]
255+
NodeId=146
256+
257+
[api]
258+
NodeId=147
259+
260+
[api]
261+
NodeId=148
262+
263+
[api]
264+
NodeId=149
265+
266+
[api]
267+
NodeId=150
268+
269+
[api]
270+
NodeId=151
271+
272+
[api]
273+
NodeId=152
274+
275+
[api]
276+
NodeId=153
277+
278+
[api]
279+
NodeId=154
280+
281+
[api]
282+
NodeId=155
283+
284+
`
285+
// replace the config hash
286+
re := regexp.MustCompile(`ConfigHash=.*`)
287+
configString = re.ReplaceAllString(configString, "ConfigHash=######")
288+
289+
if configString != expectedConfigString {
290+
t.Error("The generated config string does not match the expected value")
291+
t.Errorf("Expected :\n%s\n", expectedConfigString)
292+
t.Errorf("Generated :\n%s\n", configString)
293+
}
294+
295+
}

0 commit comments

Comments
 (0)