You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/06/01 11:06:42 UTC
[shardingsphere-on-cloud] branch main updated: fix(storage-node): fix get username and password from dbClass
This is an automated email from the ASF dual-hosted git repository.
miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
The following commit(s) were added to refs/heads/main by this push:
new 1b50b85 fix(storage-node): fix get username and password from dbClass
new c9473aa Merge pull request #386 from yikuaibro/db_class
1b50b85 is described below
commit 1b50b853a348700ef35fcfcc3c0ea3367c82b67d
Author: li <13...@qq.com>
AuthorDate: Thu Jun 1 14:52:28 2023 +0800
fix(storage-node): fix get username and password from dbClass
---
.../pkg/controllers/storage_ndoe_controller_test.go | 18 +++++++++++++++++-
.../pkg/controllers/storage_node_controller.go | 10 ++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go b/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
index 87e2fba..d165f62 100644
--- a/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
+++ b/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
@@ -625,6 +625,9 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
dbmeshv1alpha1.AnnotationsInstanceDBName: testName,
},
},
+ Spec: v1alpha1.StorageNodeSpec{
+ DatabaseClassName: defaultTestDBClass,
+ },
Status: v1alpha1.StorageNodeStatus{
Phase: v1alpha1.StorageNodePhaseReady,
Instances: []v1alpha1.InstanceStatus{
@@ -636,11 +639,24 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
},
}
+ dbClass := &dbmeshv1alpha1.DatabaseClass{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: defaultTestDBClass,
+ },
+ Spec: dbmeshv1alpha1.DatabaseClassSpec{
+ Provisioner: dbmeshv1alpha1.ProvisionerAWSRDSInstance,
+ Parameters: map[string]string{
+ "masterUsername": testName,
+ "masterUserPassword": testName,
+ },
+ },
+ }
+
mockSS.EXPECT().CreateDatabase(gomock.Any()).Return(nil)
mockSS.EXPECT().Close().Return(nil)
mockSS.EXPECT().RegisterStorageUnit(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
- Expect(reconciler.registerStorageUnit(ctx, sn)).To(BeNil())
+ Expect(reconciler.registerStorageUnit(ctx, sn, dbClass)).To(BeNil())
Expect(sn.Status.Registered).To(BeTrue())
})
diff --git a/shardingsphere-operator/pkg/controllers/storage_node_controller.go b/shardingsphere-operator/pkg/controllers/storage_node_controller.go
index 3c99383..6ac2242 100644
--- a/shardingsphere-operator/pkg/controllers/storage_node_controller.go
+++ b/shardingsphere-operator/pkg/controllers/storage_node_controller.go
@@ -166,7 +166,7 @@ func (r *StorageNodeReconciler) reconcile(ctx context.Context, dbClass *dbmeshv1
}
// register storage unit if needed.
- if err := r.registerStorageUnit(ctx, node); err != nil {
+ if err := r.registerStorageUnit(ctx, node, dbClass); err != nil {
r.Recorder.Eventf(node, corev1.EventTypeWarning, "RegisterStorageUnitFailed", "unable to register storage unit %s/%s", node.GetNamespace(), node.GetName())
return ctrl.Result{Requeue: true}, err
}
@@ -463,7 +463,7 @@ func (r *StorageNodeReconciler) deleteAWSRDSInstance(ctx context.Context, client
}
// registerStorageUnit
-func (r *StorageNodeReconciler) registerStorageUnit(ctx context.Context, node *v1alpha1.StorageNode) error {
+func (r *StorageNodeReconciler) registerStorageUnit(ctx context.Context, node *v1alpha1.StorageNode, dbClass *dbmeshv1alpha1.DatabaseClass) error {
// if register storage unit is not enabled, return
if node.Annotations[AnnotationKeyRegisterStorageUnitEnabled] != "true" {
return nil
@@ -505,7 +505,13 @@ func (r *StorageNodeReconciler) registerStorageUnit(ctx context.Context, node *v
host := ins.Endpoint.Address
port := ins.Endpoint.Port
username := node.Annotations[dbmeshv1alpha1.AnnotationsMasterUsername]
+ if username == "" {
+ username = dbClass.Spec.Parameters["masterUsername"]
+ }
password := node.Annotations[dbmeshv1alpha1.AnnotationsMasterUserPassword]
+ if password == "" {
+ password = dbClass.Spec.Parameters["masterUserPassword"]
+ }
// TODO how to set ds name?
if err := ssServer.RegisterStorageUnit(logicDBName, "ds_0", host, uint(port), dbName, username, password); err != nil {