Skip to content

Commit

Permalink
Merge pull request #835 from signal18/provision
Browse files Browse the repository at this point in the history
Fix failed provision in opensvc for proxies
  • Loading branch information
svaroqui authored Sep 6, 2024
2 parents 4495117 + cf62bb5 commit 1fdcdaf
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (cluster *Cluster) InitFromConf() {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlErr, "Could not set proxy list %s", err)
}
//Loading configuration compliances
err = cluster.Configurator.Init(cluster.Conf)
err = cluster.Configurator.Init(cluster.Conf, cluster.Logrus)
if err != nil {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, config.LvlErr, "Could not initialize configurator %s", err)
log.Fatal("missing important file, giving up")
Expand Down
3 changes: 2 additions & 1 deletion cluster/cluster_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ func (cluster *Cluster) SetClusterCredentialsFromConfig() {
cluster.SetClusterMonitorCredentialsFromConfig()
cluster.SetClusterReplicationCredentialsFromConfig()
cluster.SetClusterProxyCredentialsFromConfig()
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModConfigLoad, config.LvlDbg, "Reveal Secrets %v", cluster.Conf.Secrets)
// This is not needed! Only for debug!
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModConfigLoad, config.LvlDbg, "Reveal Secrets %v", cluster.Conf.Secrets)
}

func (cluster *Cluster) SetClusterProxyCredentialsFromConfig() {
Expand Down
6 changes: 3 additions & 3 deletions cluster/cluster_tgl.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (cluster *Cluster) SwitchInteractive() {

func (cluster *Cluster) SwitchReadOnly() {
cluster.Conf.ReadOnly = !cluster.Conf.ReadOnly
cluster.Configurator.Init(cluster.Conf)
cluster.Configurator.Init(cluster.Conf, cluster.Logrus)
}

func (cluster *Cluster) SwitchRplChecks() {
Expand Down Expand Up @@ -331,12 +331,12 @@ func (cluster *Cluster) SwitchProxyServersBackendCompression() {

func (cluster *Cluster) SwitchProxyServersReadOnMaster() {
cluster.Conf.PRXServersReadOnMaster = !cluster.Conf.PRXServersReadOnMaster
cluster.Configurator.Init(cluster.Conf)
cluster.Configurator.Init(cluster.Conf, cluster.Logrus)
}

func (cluster *Cluster) SwitchProxyServersReadOnMasterNoSlave() {
cluster.Conf.PRXServersReadOnMasterNoSlave = !cluster.Conf.PRXServersReadOnMasterNoSlave
cluster.Configurator.Init(cluster.Conf)
cluster.Configurator.Init(cluster.Conf, cluster.Logrus)
}

func (cluster *Cluster) SwitchProxySQL() {
Expand Down
98 changes: 62 additions & 36 deletions cluster/configurator/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
v3 "github.com/signal18/replication-manager/repmanv3"
"github.com/signal18/replication-manager/share"
"github.com/signal18/replication-manager/utils/misc"
"github.com/sirupsen/logrus"
)

type Configurator struct {
ClusterConfig config.Config `json:"-"`
ClusterConfigDiscover config.Config `json:"-"`
DBModule config.Compliance `json:"-"`
ProxyModule config.Compliance `json:"-"`
Logger *logrus.Logger `json:"-"`
ConfigDBTags []v3.Tag `json:"configTags"` //from module
ConfigPrxTags []v3.Tag `json:"configPrxTags"` //from module
DBTags []string `json:"dbServersTags"` //from conf
Expand All @@ -38,8 +40,9 @@ type Configurator struct {
WorkingDir string `json:"-"` // working dir is the place to generate the all cluster config
}

func (configurator *Configurator) Init(conf config.Config) error {
func (configurator *Configurator) Init(conf config.Config, logger *logrus.Logger) error {
var err error
configurator.SetLogger(logger)
configurator.SetConfig(conf)

err = configurator.LoadDBModules()
Expand Down Expand Up @@ -472,10 +475,9 @@ func (configurator *Configurator) GenerateProxyConfig(Datadir string, ClusterDir
var f Link
json.Unmarshal([]byte(variable.Value), &f)
fpath := strings.Replace(f.Symlink, "%%ENV:SVC_CONF_ENV_BASE_DIR%%/%%ENV:POD%%", Datadir+"/init", -1)
/* if proxy.ClusterGroup.Conf.LogLevel > 2 {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config symlink %s", fpath)
}
*/
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config symlink %s", fpath)
}
os.Symlink(f.Target, fpath)

}
Expand Down Expand Up @@ -538,6 +540,7 @@ func (configurator *Configurator) GenerateDatabaseConfig(Datadir string, Cluster
} else {
os.RemoveAll(Datadir + "/init")
}

for _, rule := range configurator.DBModule.Rulesets {
if strings.Contains(rule.Name, "mariadb.svc.mrm.db.cnf") {

Expand All @@ -564,9 +567,9 @@ func (configurator *Configurator) GenerateDatabaseConfig(Datadir string, Cluster
var f Link
json.Unmarshal([]byte(variable.Value), &f)
fpath := strings.Replace(f.Symlink, "%%ENV:SVC_CONF_ENV_BASE_DIR%%/%%ENV:POD%%", Datadir+"/init", -1)
/* if configurator.ClusterConfig.LogLevel > 2 {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config symlink %s", fpath)
} */
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config symlink %s", fpath)
}
os.Symlink(f.Target, fpath)
// keys := strings.Split(variable.Value, " ")
}
Expand Down Expand Up @@ -609,18 +612,26 @@ func (configurator *Configurator) GetDatabaseDynamicConfig(filter string, cmd st
for _, variable := range rule.Variables {
if variable.Class == "symlink" {
if configurator.IsFilterInDBTags(rule.Filter) || rule.Name == "mariadb.svc.mrm.db.cnf.generic" {
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "content %s %s", filter, rule.Filter)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("content %s %s", filter, rule.Filter)
}
if filter == "" || strings.Contains(rule.Filter, filter) {
var f Link
json.Unmarshal([]byte(variable.Value), &f)
fpath := Datadir + "/init/etc/mysql/conf.d/"
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config symlink %s , %s", fpath, f.Target)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config symlink %s , %s", fpath, f.Target)
}

file, err := os.Open(fpath + f.Target)
if err == nil {
r, _ := regexp.Compile(cmd)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "content: %s", scanner.Text())
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("content: %s", scanner.Text())
}

if r.MatchString(scanner.Text()) {
mydynamicconf = mydynamicconf + strings.Split(scanner.Text(), ":")[1]
}
Expand Down Expand Up @@ -651,12 +662,16 @@ func (configurator *Configurator) GetDatabaseConfig(filter string, datadir strin
for _, variable := range rule.Variables {
if variable.Class == "symlink" {
if configurator.IsFilterInDBTags(rule.Filter) || rule.Name == "mariadb.svc.mrm.db.cnf.generic" {
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "content %s %s", filter, rule.Filter)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("content %s %s", filter, rule.Filter)
}
if filter == "" || strings.Contains(rule.Filter, filter) {
var f Link
json.Unmarshal([]byte(variable.Value), &f)
fpath := datadir + "/init/etc/mysql/conf.d/"
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config symlink %s , %s", fpath, f.Target)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config symlink %s , %s", fpath, f.Target)
}
file, err := os.Open(fpath + f.Target)
if err == nil {
scanner := bufio.NewScanner(file)
Expand Down Expand Up @@ -689,10 +704,10 @@ func (configurator *Configurator) WriteDatabaseConfigFile(Datadir string, Remote
json.Unmarshal([]byte(variable.Value), &f)
fpath := strings.Replace(f.Path, "%%ENV:SVC_CONF_ENV_BASE_DIR%%/%%ENV:POD%%", Datadir+"/init", -1)
dir := filepath.Dir(fpath)
/* if server.ClusterGroup.Conf.LogLevel > 2 {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config create %s", fpath)
}
*/
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config create %s", fpath)
}

// create directory
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, os.FileMode(0775))
Expand Down Expand Up @@ -740,7 +755,9 @@ func (configurator *Configurator) WriteDatabaseConfigFile(Datadir string, Remote
outFile.Close()
return fmt.Errorf("Compliance writing file failed %q: %s", fpath, err)
}
//cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Variable name %s", variable.Name)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Variable name %s", variable.Name)
}
}

}
Expand All @@ -759,35 +776,44 @@ func (configurator *Configurator) WriteProxyConfigFile(Datadir string, TemplateE
json.Unmarshal([]byte(variable.Value), &f)
fpath := strings.Replace(f.Path, "%%ENV:SVC_CONF_ENV_BASE_DIR%%/%%ENV:POD%%", Datadir+"/init", -1)
dir := filepath.Dir(fpath)
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Config create %s", fpath)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Config create %s", fpath)
}

// create directory
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, os.FileMode(0775))
if err != nil {
return fmt.Errorf("Compliance create directory %q: %s", dir, err)
}
}
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "rule %s filter %s %t", rule.Name, rule.Filter, proxy.IsFilterInTags(rule.Filter))
if fpath[len(fpath)-1:] != "/" && (configurator.IsFilterInProxyTags(rule.Filter) || rule.Filter == "") {

if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("rule %s filter %s %t", rule.Name, rule.Filter, configurator.IsFilterInProxyTags(rule.Filter))
}
content := misc.ExtractKey(f.Content, TemplateEnv)
outFile, err := os.Create(fpath)
if err != nil {
return fmt.Errorf("Compliance create file failed %q: %s", fpath, err)
} else {
_, err = outFile.WriteString(fmt.Sprintf("# Generated by Signal18 replication-manager %s on %s \n", RepMgrVersion, ts))
if err != nil {
outFile.Close()
return fmt.Errorf("Compliance writing file failed %q: %s", fpath, err)
}
_, err = outFile.WriteString(content)

if fpath[len(fpath)-1:] != "/" && (configurator.IsFilterInProxyTags(rule.Filter) || rule.Filter == "") {
content := misc.ExtractKey(f.Content, TemplateEnv)
outFile, err := os.Create(fpath)
if err != nil {
outFile.Close()
return fmt.Errorf("Compliance writing file failed %q: %s", fpath, err)
}
return fmt.Errorf("Compliance create file failed %q: %s", fpath, err)
} else {
_, err = outFile.WriteString(fmt.Sprintf("# Generated by Signal18 replication-manager %s on %s \n", RepMgrVersion, ts))
if err != nil {
outFile.Close()
return fmt.Errorf("Compliance writing file failed %q: %s", fpath, err)
}
_, err = outFile.WriteString(content)
if err != nil {
outFile.Close()
return fmt.Errorf("Compliance writing file failed %q: %s", fpath, err)
}

//cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,LvlInfo, "Variable name %s", variable.Name)
if configurator.ClusterConfig.IsEligibleForPrinting(config.ConstLogModConfigLoad, config.LvlDbg) || configurator.ClusterConfig.Verbose {
configurator.Logger.Debugf("Variable name %s", variable.Name)
}
}
}

return nil
}
5 changes: 5 additions & 0 deletions cluster/configurator/configurator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/signal18/replication-manager/config"
"github.com/sirupsen/logrus"
)

func (configurator *Configurator) SetConfig(conf config.Config) {
Expand All @@ -19,6 +20,10 @@ func (configurator *Configurator) SetConfig(conf config.Config) {
configurator.ProxyTags = strings.Split(conf.ProvProxTags, ",")
}

func (configurator *Configurator) SetLogger(logger *logrus.Logger) {
configurator.Logger = logger
}

func (configurator *Configurator) SetDBTags(newtags []string) {
configurator.DBTags = newtags
}
Expand Down
2 changes: 0 additions & 2 deletions share/dashboard/static/configurator/opensvc/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ function help {
[ -z $REPLICATION_MANAGER_HOST_NAME ] && help && exit 1
[ -z $REPLICATION_MANAGER_HOST_PORT ] && help && exit 1

SET -x

GET="wget -q --no-check-certificate -O- --header Content-Type:application/json"
AUTH_DATA="{\"username\": \"$REPLICATION_MANAGER_USER\", \"password\": \"$REPLICATION_MANAGER_PASSWORD\"}"
TOKEN=$($GET --post-data "$AUTH_DATA" --header Accept:text/html $REPLICATION_MANAGER_URL/api/login)
Expand Down

0 comments on commit 1fdcdaf

Please sign in to comment.