Skip to content

Commit

Permalink
Customize default number of free API slots for NDBAPI apps (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
asaintsever authored Mar 2, 2022
1 parent ec7dee4 commit 8d58e6b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deploy/charts/ndb-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: ndb-operator
version: 0.1.1
version: 0.1.2
kubeVersion: ">= 1.19.0"
description: A Helm chart for deploying the Oracle MySQL NDB Cluster Operator
appVersion: "8.0.26-0.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ spec:
spec:
description: NdbClusterSpec defines the desired state of MySQL Ndb Cluster
properties:
apiFreeSlots:
default: 3
description: Number of free API slots for other NDBAPI applications
format: int32
type: integer
dataMemory:
default: 98M
description: 'DataMemory specifies the space available per data node
Expand Down
5 changes: 5 additions & 0 deletions deploy/manifests/ndb-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ spec:
spec:
description: NdbClusterSpec defines the desired state of MySQL Ndb Cluster
properties:
apiFreeSlots:
default: 3
description: Number of free API slots for other NDBAPI applications
format: int32
type: integer
dataMemory:
default: 98M
description: 'DataMemory specifies the space available per data node
Expand Down
12 changes: 12 additions & 0 deletions docs/NdbCluster-CRD.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ Allowed values 1M - 1T. More info :
</tr>
<tr>
<td>
<code>apiFreeSlots</code><br/>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>Number of free API slots for other NDBAPI applications. Default is: 3</p>
</td>
</tr>
<tr>
<td>
<code>extraNdbdDefaultParams</code><br/>
<em>
string
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/ndbcontroller/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ type NdbClusterSpec struct {
// +kubebuilder:validation:Pattern="[0-9]+[MGT]"
DataMemory string `json:"dataMemory,omitempty"`

// Number of free API slots for other NDBAPI applications
// +kubebuilder:default=3
// +optional
ApiFreeSlots int32 `json:"apiFreeSlots,omitempty"`

// Extra ndbd default parameters to be added to [ndbd default] section of config.ini file.
// Exception: parameters DataMemory and NoOfReplicas should not be added as
// they are handled through CRD attributes dataMemory and redundancyLevel.
Expand Down
1 change: 1 addition & 0 deletions pkg/helpers/testutils/ndbtestcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewTestNdb(namespace string, name string, noOfNodes int32) *ndbcontroller.N
},
Spec: ndbcontroller.NdbClusterSpec{
NodeCount: noOfNodes,
ApiFreeSlots: 3,
RedundancyLevel: 2,
Mysqld: &ndbcontroller.NdbMysqldSpec{
NodeCount: noOfNodes,
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func GetConfigString(ndb *v1alpha1.NdbCluster, oldResourceContext *ResourceConte
}

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

tmpl := template.New("config.ini")
tmpl.Funcs(template.FuncMap{
Expand Down
88 changes: 88 additions & 0 deletions pkg/resources/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,91 @@ NodeId=148
}

}

func Test_GetConfigString_ApiFreeSlots(t *testing.T) {
ndb := testutils.NewTestNdb("default", "example-ndb-3", 1)
ndb.Spec.DataMemory = "80M"
ndb.Spec.ApiFreeSlots = 10
configString, err := GetConfigString(ndb, nil)
if err != nil {
t.Errorf("Failed to generate config string from Ndb : %s", err)
}

expectedConfigString := `# auto generated config.ini - do not edit
#
# ConfigHash=######
# NumOfMySQLServers=1
[system]
ConfigGenerationNumber=0
Name=example-ndb-3
[ndbd default]
NoOfReplicas=2
DataMemory=80M
# Use a fixed ServerPort for all data nodes
ServerPort=1186
[tcp default]
AllowUnresolvedHostnames=1
[ndb_mgmd]
NodeId=1
Hostname=example-ndb-3-mgmd-0.example-ndb-3-mgmd.default.svc.cluster.local
DataDir=/var/lib/ndb
[ndb_mgmd]
NodeId=2
Hostname=example-ndb-3-mgmd-1.example-ndb-3-mgmd.default.svc.cluster.local
DataDir=/var/lib/ndb
[ndbd]
NodeId=3
Hostname=example-ndb-3-ndbd-0.example-ndb-3-ndbd.default.svc.cluster.local
DataDir=/var/lib/ndb
[api]
NodeId=145
[api]
NodeId=146
[api]
NodeId=147
[api]
NodeId=148
[api]
NodeId=149
[api]
NodeId=150
[api]
NodeId=151
[api]
NodeId=152
[api]
NodeId=153
[api]
NodeId=154
[api]
NodeId=155
`
// replace the config hash
re := regexp.MustCompile(`ConfigHash=.*`)
configString = re.ReplaceAllString(configString, "ConfigHash=######")

if configString != expectedConfigString {
t.Error("The generated config string does not match the expected value")
t.Errorf("Expected :\n%s\n", expectedConfigString)
t.Errorf("Generated :\n%s\n", configString)
}

}

0 comments on commit 8d58e6b

Please # to comment.