From a45df5ffd4d6eb3c59894c8e0b79435daf7971d9 Mon Sep 17 00:00:00 2001 From: Alain Saint-Sever Date: Sun, 6 Feb 2022 12:38:10 +0100 Subject: [PATCH] Add support for extra NDBD default parameters in config.ini --- .../crds/mysql.oracle.com_ndbclusters.yaml | 6 ++ deploy/manifests/ndb-operator.yaml | 6 ++ docs/NdbCluster-CRD.md | 15 ++++ .../example-ndb-extra-default-params.yaml | 21 ++++++ pkg/apis/ndbcontroller/v1alpha1/types.go | 7 ++ pkg/resources/config.go | 2 +- pkg/resources/config_test.go | 71 +++++++++++++++++++ 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 docs/examples/example-ndb-extra-default-params.yaml 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..9dca7ff 100644 --- a/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml +++ b/deploy/charts/ndb-operator/crds/mysql.oracle.com_ndbclusters.yaml @@ -173,6 +173,12 @@ spec: backing this claim. type: string type: object + extraNdbdDefaultParams: + description: '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. List of parameters: https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-ndbd-definition.html' + type: string image: default: mysql/mysql-cluster:latest description: The name of the MySQL Ndb Cluster image to be used. If diff --git a/deploy/manifests/ndb-operator.yaml b/deploy/manifests/ndb-operator.yaml index c4d28a7..ef07d08 100644 --- a/deploy/manifests/ndb-operator.yaml +++ b/deploy/manifests/ndb-operator.yaml @@ -172,6 +172,12 @@ spec: backing this claim. type: string type: object + extraNdbdDefaultParams: + description: '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. List of parameters: https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-ndbd-definition.html' + type: string image: default: mysql/mysql-cluster:latest description: The name of the MySQL Ndb Cluster image to be used. If diff --git a/docs/NdbCluster-CRD.md b/docs/NdbCluster-CRD.md index 2b73064..bf93356 100644 --- a/docs/NdbCluster-CRD.md +++ b/docs/NdbCluster-CRD.md @@ -135,6 +135,21 @@ Allowed values 1M - 1T. More info : +extraNdbdDefaultParams
+ +string + + + +(Optional) +

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. List of parameters : +https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-ndbd-definition.html

+ + + + image
string diff --git a/docs/examples/example-ndb-extra-default-params.yaml b/docs/examples/example-ndb-extra-default-params.yaml new file mode 100644 index 0000000..313fc45 --- /dev/null +++ b/docs/examples/example-ndb-extra-default-params.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Secret +metadata: + name: ndbop-mysql-secret +type: Opaque +stringData: + password: ndbpass +--- +apiVersion: mysql.oracle.com/v1alpha1 +kind: NdbCluster +metadata: + name: example-ndb +spec: + nodeCount: 2 + redundancyLevel: 2 + extraNdbdDefaultParams: | + MaxNoOfAttributes=8000 + MaxNoOfTables=10000 + MaxNoOfOrderedIndexes=10000 + mysqld: + nodeCount: 2 diff --git a/pkg/apis/ndbcontroller/v1alpha1/types.go b/pkg/apis/ndbcontroller/v1alpha1/types.go index 6da8dd4..f3c78da 100644 --- a/pkg/apis/ndbcontroller/v1alpha1/types.go +++ b/pkg/apis/ndbcontroller/v1alpha1/types.go @@ -84,6 +84,13 @@ type NdbClusterSpec struct { // +kubebuilder:validation:Pattern="[0-9]+[MGT]" DataMemory string `json:"dataMemory,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. + // List of parameters: https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-ndbd-definition.html + // +optional + ExtraNdbdDefaultParams string `json:"extraNdbdDefaultParams,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/resources/config.go b/pkg/resources/config.go index 46917da..91eb27f 100644 --- a/pkg/resources/config.go +++ b/pkg/resources/config.go @@ -28,7 +28,7 @@ NoOfReplicas={{.Spec.RedundancyLevel}} DataMemory={{.Spec.DataMemory}} # Use a fixed ServerPort for all data nodes ServerPort=1186 - +{{if .Spec.ExtraNdbdDefaultParams -}}{{println .Spec.ExtraNdbdDefaultParams}}{{end}} [tcp default] AllowUnresolvedHostnames=1 diff --git a/pkg/resources/config_test.go b/pkg/resources/config_test.go index 2f1cc0e..84fd4aa 100644 --- a/pkg/resources/config_test.go +++ b/pkg/resources/config_test.go @@ -134,3 +134,74 @@ NodeId=149 } } + +func Test_GetConfigString_ExtraNdbDefaultParams(t *testing.T) { + ndb := testutils.NewTestNdb("default", "example-ndb-2", 1) + ndb.Spec.DataMemory = "80M" + ndb.Spec.ExtraNdbdDefaultParams = + `MaxNoOfAttributes=8000 +MaxNoOfTables=10000` + 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 +MaxNoOfAttributes=8000 +MaxNoOfTables=10000 + +[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 + +` + // 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) + } + +}