Skip to content

Commit

Permalink
Sync from server repo (8f1d452d310)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Oct 31, 2024
1 parent b8f2c92 commit 2e666e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
10 changes: 5 additions & 5 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_revive_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 21 additions & 11 deletions commands/vcluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -281,29 +282,38 @@ 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]
}
n.DepotPath = vnode.DepotPath
}

// 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 {
nodeConfigMap[n.Name] = n
}

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...)
Expand Down

0 comments on commit 2e666e5

Please sign in to comment.