Skip to content

Commit

Permalink
#470 fix Replication manager pro don't start if account.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaloubersac committed Feb 24, 2023
1 parent 5854eab commit f6327a9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
8 changes: 8 additions & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type Cluster struct {
WaitingFailover int `json:"waitingFailover"`
Configurator configurator.Configurator `json:"configurator"`
DiffVariables []VariableDiff `json:"diffVariables"`
insideInitNodes bool `json:"-"`
sync.Mutex
crcTable *crc64.Table
}
Expand Down Expand Up @@ -359,8 +360,15 @@ func (cluster *Cluster) Init(conf config.Config, cfgGroup string, tlog *s18log.T

return nil
}

func (cluster *Cluster) initOrchetratorNodes() {
if cluster.insideInitNodes {
return
}
cluster.insideInitNodes = true
defer func() { cluster.insideInitNodes = false }()

//defer cluster.insideInitNodes = false
//cluster.LogPrintf(LvlInfo, "Loading nodes from orchestrator %s", cluster.Conf.ProvOrchestrator)
switch cluster.GetOrchestrator() {
case config.ConstOrchestratorOpenSVC:
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ type Config struct {
ProvOpensvcP12Certificate string `mapstructure:"opensvc-p12-certificate" toml:"opensvc-p12-certificat" json:"opensvcP12Certificate"`
ProvOpensvcP12Secret string `mapstructure:"opensvc-p12-secret" toml:"opensvc-p12-secret" json:"opensvcP12Secret"`
ProvOpensvcUseCollectorAPI bool `mapstructure:"opensvc-use-collector-api" toml:"opensvc-use-collector-api" json:"opensvcUseCollectorApi"`
ProvOpensvcCollectorAccount string `mapstructure:"opensvc-collector-account" toml:"opensvc-collector-account" json:"opensvcCollectorAccount"`
ProvRegister bool `mapstructure:"opensvc-register" toml:"opensvc-register" json:"opensvcRegister"`
ProvAdminUser string `mapstructure:"opensvc-admin-user" toml:"opensvc-admin-user" json:"opensvcAdminUser"`
ProvUser string `mapstructure:"opensvc-user" toml:"opensvc-user" json:"opensvcUser"`
Expand Down Expand Up @@ -529,7 +530,7 @@ type ConfigVariableType struct {
Label string `json:"label"`
}

//Compliance created in OpenSVC collector and exported as JSON
// Compliance created in OpenSVC collector and exported as JSON
type Compliance struct {
Filtersets []struct {
ID uint `json:"id"`
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const (
ConstMonitorStandby string = "S"
)

//Unused in server still used in client cmd line
// Unused in server still used in client cmd line
type Settings struct {
Enterprise string `json:"enterprise"`
Interactive string `json:"interactive"`
Expand Down Expand Up @@ -573,7 +573,7 @@ func (repman *ReplicationManager) Run() error {
repman.OpenSVC.CertsDERSecret = repman.Conf.ProvOpensvcP12Secret
err := repman.OpenSVC.LoadCert(repman.Conf.ProvOpensvcP12Certificate)
if err != nil {
log.Printf("Cannot load OpenSVC cluster certificate %s ", err)
log.Fatalf("Cannot load OpenSVC cluster certificate %s ", err)
}
}
//don't Bootstrap opensvc to speedup test
Expand Down
26 changes: 11 additions & 15 deletions server/server_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,26 +519,22 @@ func init() {
monitorCmd.Flags().StringVar(&conf.ProvOpensvcP12Certificate, "opensvc-p12-certificate", "/etc/replication-manager/s18.p12", "Certicate used for socket vs collector API opensvc-host refer to a cluster VIP")
monitorCmd.Flags().BoolVar(&conf.ProvOpensvcUseCollectorAPI, "opensvc-use-collector-api", false, "Use the collector API instead of cluster VIP")
monitorCmd.Flags().StringVar(&conf.KubeConfig, "kube-config", "", "path to ks8 config file")
monitorCmd.Flags().StringVar(&conf.ProvOpensvcCollectorAccount, "opensvc-collector-account", "/etc/replication-manager/account.yaml", "Openscv collector account")

dbConfig := viper.New()
dbConfig.SetConfigType("yaml")
file, err := ioutil.ReadFile(conf.ConfDir + "/account.yaml")
if err != nil {
file, err = ioutil.ReadFile(conf.ShareDir + "/opensvc/account.yaml")
if conf.ProvOpensvcUseCollectorAPI {
dbConfig.SetConfigType("yaml")
file, err := ioutil.ReadFile(conf.ProvOpensvcCollectorAccount)
if err != nil {
log.Errorf("%s", err)
log.Errorf("Provide OpenSVC account file : %s", err)

}

dbConfig.ReadConfig(bytes.NewBuffer(file))
conf.ProvUser = dbConfig.Get("email").(string) + ":" + dbConfig.Get("hashed_password").(string)
crcTable := crc64.MakeTable(crc64.ECMA)
conf.ProvCodeApp = "ns" + strconv.FormatUint(crc64.Checksum([]byte(dbConfig.Get("email").(string)), crcTable), 10)
}
dbConfig.ReadConfig(bytes.NewBuffer(file))
// log.Printf("OpenSVC user account: %s", dbConfig.Get("email").(string))
conf.ProvUser = dbConfig.Get("email").(string) + ":" + dbConfig.Get("hashed_password").(string)
crcTable := crc64.MakeTable(crc64.ECMA)
conf.ProvCodeApp = "ns" + strconv.FormatUint(crc64.Checksum([]byte(dbConfig.Get("email").(string)), crcTable), 10)
// log.Printf("OpenSVC code application: %s", conf.ProvCodeApp)
// } else {
// monitorCmd.Flags().StringVar(&conf.ProvUser, "opensvc-user", "replication-manager@localhost.localdomain:mariadb", "OpenSVC collector provisioning user")
// monitorCmd.Flags().StringVar(&conf.ProvCodeApp, "opensvc-codeapp", "MariaDB", "OpenSVC collector applicative code")
// }

}
}
Expand Down
2 changes: 1 addition & 1 deletion share/opensvc/account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ state: enabled
access:
site:
login: 'true'
hashed_password: repman
hashed_password: xxxx

0 comments on commit f6327a9

Please sign in to comment.