From 8a1627f4f9bb58c4cb7ee558733efd247216ca19 Mon Sep 17 00:00:00 2001
From: TheAlain <43777839+asaintsever@users.noreply.github.com>
Date: Wed, 2 Mar 2022 21:00:37 +0100
Subject: [PATCH] Customize default number of free API slots for NDBAPI apps
---
deploy/charts/ndb-operator/Chart.yaml | 2 +-
.../crds/mysql.oracle.com_ndbclusters.yaml | 5 ++
deploy/manifests/ndb-operator.yaml | 5 ++
docs/NdbCluster-CRD.md | 12 +++
pkg/apis/ndbcontroller/v1alpha1/types.go | 5 ++
pkg/helpers/testutils/ndbtestcreator.go | 1 +
pkg/resources/config.go | 4 +-
pkg/resources/config_test.go | 88 +++++++++++++++++++
8 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/deploy/charts/ndb-operator/Chart.yaml b/deploy/charts/ndb-operator/Chart.yaml
index 304aa96..1965a36 100644
--- a/deploy/charts/ndb-operator/Chart.yaml
+++ b/deploy/charts/ndb-operator/Chart.yaml
@@ -1,6 +1,6 @@
apiVersion: v2
name: ndb-operator
-version: 0.1.0
+version: 0.1.1
kubeVersion: ">= 1.19.0"
description: A Helm chart for deploying the Oracle MySQL NDB Cluster Operator
appVersion: "8.0.26-0.1.0"
diff --git a/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml b/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml
index dc880ca..3e49265 100644
--- a/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml
+++ b/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml
@@ -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
diff --git a/deploy/manifests/ndb-operator.yaml b/deploy/manifests/ndb-operator.yaml
index c4d28a7..4802d1d 100644
--- a/deploy/manifests/ndb-operator.yaml
+++ b/deploy/manifests/ndb-operator.yaml
@@ -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
diff --git a/docs/NdbCluster-CRD.md b/docs/NdbCluster-CRD.md
index 2b73064..6d9f0c9 100644
--- a/docs/NdbCluster-CRD.md
+++ b/docs/NdbCluster-CRD.md
@@ -135,6 +135,18 @@ Allowed values 1M - 1T. More info :
+apiFreeSlots
+
+int32
+
+ |
+
+(Optional)
+ Number of free API slots for other NDBAPI applications. Default is: 3
+ |
+
+
+
image
string
diff --git a/pkg/apis/ndbcontroller/v1alpha1/types.go b/pkg/apis/ndbcontroller/v1alpha1/types.go
index 6da8dd4..5237ea8 100644
--- a/pkg/apis/ndbcontroller/v1alpha1/types.go
+++ b/pkg/apis/ndbcontroller/v1alpha1/types.go
@@ -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"`
+
// The name of the MySQL Ndb Cluster image to be used.
// If not specified, "mysql/mysql-cluster:latest" will be used.
// Lowest supported version is 8.0.26.
diff --git a/pkg/helpers/testutils/ndbtestcreator.go b/pkg/helpers/testutils/ndbtestcreator.go
index a88c5dd..edaa633 100644
--- a/pkg/helpers/testutils/ndbtestcreator.go
+++ b/pkg/helpers/testutils/ndbtestcreator.go
@@ -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,
diff --git a/pkg/resources/config.go b/pkg/resources/config.go
index 46917da..ec33de7 100644
--- a/pkg/resources/config.go
+++ b/pkg/resources/config.go
@@ -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{
diff --git a/pkg/resources/config_test.go b/pkg/resources/config_test.go
index 2f1cc0e..608927a 100644
--- a/pkg/resources/config_test.go
+++ b/pkg/resources/config_test.go
@@ -134,3 +134,91 @@ NodeId=149
}
}
+
+func Test_GetConfigString_ApiFreeSlots(t *testing.T) {
+ ndb := testutils.NewTestNdb("default", "example-ndb-2", 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-2
+
+[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-2-mgmd-0.example-ndb-2-mgmd.default.svc.cluster.local
+DataDir=/var/lib/ndb
+
+[ndb_mgmd]
+NodeId=2
+Hostname=example-ndb-2-mgmd-1.example-ndb-2-mgmd.default.svc.cluster.local
+DataDir=/var/lib/ndb
+
+[ndbd]
+NodeId=3
+Hostname=example-ndb-2-ndbd-0.example-ndb-2-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)
+ }
+
+}
|