From 2e666e5ef6e2a60a12798764a717d71fb0608bdc Mon Sep 17 00:00:00 2001 From: releng Date: Thu, 31 Oct 2024 11:32:24 -0400 Subject: [PATCH] Sync from server repo (8f1d452d310) --- commands/cmd_create_db.go | 10 +++++----- commands/cmd_revive_db.go | 2 +- commands/vcluster_config.go | 32 +++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/commands/cmd_create_db.go b/commands/cmd_create_db.go index ef84be9..f2972cd 100644 --- a/commands/cmd_create_db.go +++ b/commands/cmd_create_db.go @@ -253,11 +253,11 @@ func (c *CmdCreateDB) validateParse(logger vlog.Printer) error { return err } - if !c.usePassword() { - err = c.getCertFilesFromCertPaths(&c.createDBOptions.DatabaseOptions) - if err != nil { - return err - } + // for creating a database, db password is mandatory input + // we need to read certs for connecting to node management agent + err = c.getCertFilesFromCertPaths(&c.createDBOptions.DatabaseOptions) + if err != nil { + return err } err = c.setDBPassword(&c.createDBOptions.DatabaseOptions) diff --git a/commands/cmd_revive_db.go b/commands/cmd_revive_db.go index edc03ef..63126af 100644 --- a/commands/cmd_revive_db.go +++ b/commands/cmd_revive_db.go @@ -215,7 +215,7 @@ func (c *CmdReviveDB) Run(vcc vclusterops.ClusterCommands) error { // config file already exists. This could happen if we have partially revived the db(sandbox or main cluster) already // In this case, we update the existing config file instead of overwriting it. dbConfig = *dbConfigPtr - updateConfig(vdb, &dbConfig) + UpdateDBConfig(vdb, &dbConfig, c.reviveDBOptions.Sandbox, c.reviveDBOptions.MainCluster) writeErr := dbConfig.write(c.reviveDBOptions.ConfigPath, true /*forceOverwrite*/) if writeErr != nil { vcc.DisplayWarning("Fail to update config file: %s", writeErr) diff --git a/commands/vcluster_config.go b/commands/vcluster_config.go index b83f594..00004b9 100644 --- a/commands/vcluster_config.go +++ b/commands/vcluster_config.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "sort" + "strings" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -235,7 +236,7 @@ func readVDBToDBConfig(vdb *vclusterops.VCoordinationDatabase) (DatabaseConfig, return dbConfig, fmt.Errorf("cannot find host %s from HostNodeMap", host) } - nodeConfig := buildNodeConfig(vnode, vdb) + nodeConfig := BuildNodeConfig(vnode, vdb) dbConfig.Nodes = append(dbConfig.Nodes, &nodeConfig) } @@ -248,7 +249,7 @@ func readVDBToDBConfig(vdb *vclusterops.VCoordinationDatabase) (DatabaseConfig, return dbConfig, nil } -func buildNodeConfig(vnode *vclusterops.VCoordinationNode, +func BuildNodeConfig(vnode *vclusterops.VCoordinationNode, vdb *vclusterops.VCoordinationDatabase) NodeConfig { nodeConfig := NodeConfig{} nodeConfig.Name = vnode.Name @@ -281,7 +282,14 @@ func updateNodeConfig(vnode *vclusterops.VCoordinationNode, n.Address = vnode.Address n.Subcluster = vnode.Subcluster n.Sandbox = vnode.Sandbox - n.CatalogPath = vnode.CatalogPath + if n.CatalogPath == "" { + if strings.HasSuffix(vnode.CatalogPath, "/Catalog") { + // Remove the "/Catalog" suffix and assign the remaining path to catalogPath + n.CatalogPath = strings.TrimSuffix(vnode.CatalogPath, "/Catalog") + } else { + n.CatalogPath = vnode.CatalogPath + } + } if vdb.DataPrefix == "" && len(vnode.StorageLocations) > 0 && n.DataPath == "" { n.DataPath = vnode.StorageLocations[0] } @@ -289,7 +297,7 @@ func updateNodeConfig(vnode *vclusterops.VCoordinationNode, } // update the input dbConfig -func updateConfig(vdb *vclusterops.VCoordinationDatabase, dbConfig *DatabaseConfig) { +func UpdateDBConfig(vdb *vclusterops.VCoordinationDatabase, dbConfig *DatabaseConfig, sandbox string, mainClusterOnly bool) { var newNodes []*NodeConfig nodeConfigMap := make(map[string]*NodeConfig) for _, n := range dbConfig.Nodes { @@ -297,13 +305,15 @@ func updateConfig(vdb *vclusterops.VCoordinationDatabase, dbConfig *DatabaseConf } for _, vnode := range vdb.HostNodeMap { - if n, exists := nodeConfigMap[vnode.Name]; exists { - // If found, update the existing node configuration - updateNodeConfig(vnode, vdb, n) - } else { - // If not found, build and append a new node configuration - n := buildNodeConfig(vnode, vdb) - newNodes = append(newNodes, &n) + if sandbox == vnode.Sandbox || (mainClusterOnly && vnode.Sandbox == util.MainClusterSandbox) { + if n, exists := nodeConfigMap[vnode.Name]; exists { + // If found, update the existing node configuration + updateNodeConfig(vnode, vdb, n) + } else { + // If not found, build and append a new node configuration + n := BuildNodeConfig(vnode, vdb) + newNodes = append(newNodes, &n) + } } } dbConfig.Nodes = append(dbConfig.Nodes, newNodes...)