mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-09 06:45:49 +02:00
Allow disabling access to the DB and the Teams API.
Command-line options --nodatabaseaccess and --noteamsapi disable all teams api interaction and access to the Postgres database. This is useful for debugging purposes when the operator runs out of cluster (with --outofcluster flag). The same effect can be achieved by setting enable_db_access and/or enable_teams_api to false.
This commit is contained in:
+10
-8
@@ -227,18 +227,20 @@ func (c *Cluster) Create(stopCh <-chan struct{}) error {
|
||||
}
|
||||
c.logger.Infof("Pods are ready")
|
||||
|
||||
if !c.masterLess {
|
||||
if err = c.initDbConn(); err != nil {
|
||||
if !(c.masterLess || c.DatabaseAccessDisabled()) {
|
||||
if err := c.initDbConn(); err != nil {
|
||||
return fmt.Errorf("Can't init db connection: %s", err)
|
||||
}
|
||||
|
||||
if err = c.createUsers(); err != nil {
|
||||
return fmt.Errorf("Can't create users: %s", err)
|
||||
} else {
|
||||
c.logger.Infof("Users have been successfully created")
|
||||
if err = c.createUsers(); err != nil {
|
||||
return fmt.Errorf("Can't create users: %s", err)
|
||||
} else {
|
||||
c.logger.Infof("Users have been successfully created")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.logger.Warnln("Cluster is masterless")
|
||||
if c.masterLess {
|
||||
c.logger.Warnln("Cluster is masterless")
|
||||
}
|
||||
}
|
||||
|
||||
c.ListResources()
|
||||
|
||||
+7
-4
@@ -32,10 +32,14 @@ func (c *Cluster) pgConnectionString() string {
|
||||
strings.Replace(password, "$", "\\$", -1))
|
||||
}
|
||||
|
||||
func (c *Cluster) initDbConn() error {
|
||||
//TODO: concurrent safe?
|
||||
func (c *Cluster) DatabaseAccessDisabled() bool {
|
||||
if c.OpConfig.EnableDBAccess == false {
|
||||
c.logger.Debugf("Database access is disabled")
|
||||
}
|
||||
return c.OpConfig.EnableDBAccess == false
|
||||
}
|
||||
func (c *Cluster) initDbConn() (err error) {
|
||||
if c.pgDb == nil {
|
||||
if c.pgDb == nil {
|
||||
conn, err := sql.Open("postgres", c.pgConnectionString())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -47,7 +51,6 @@ func (c *Cluster) initDbConn() error {
|
||||
}
|
||||
|
||||
c.pgDb = conn
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -36,6 +36,9 @@ func (c *Cluster) SyncCluster(stopCh <-chan struct{}) {
|
||||
if err := c.syncStatefulSet(); err != nil {
|
||||
c.logger.Errorf("Can't sync StatefulSets: %s", err)
|
||||
}
|
||||
if c.DatabaseAccessDisabled() {
|
||||
return
|
||||
}
|
||||
if err := c.initDbConn(); err != nil {
|
||||
c.logger.Errorf("Can't init db connection: %s", err)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user