remove role from installLookupFunction and run it on database sync, too
This commit is contained in:
		
							parent
							
								
									79ab7d3216
								
							
						
					
					
						commit
						54481d76af
					
				|  | @ -684,7 +684,7 @@ func logPoolerEssentials(log *logrus.Entry, oldSpec, newSpec *acidv1.Postgresql) | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("syncing connection pooler from (%v, %v) to (%v, %v)", v[0], v[1], v[2], v[3]) | ||||
| 	log.Debugf("syncing connection pooler (master, replica) from (%v, %v) to (%v, %v)", v[0], v[1], v[2], v[3]) | ||||
| } | ||||
| 
 | ||||
| func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, LookupFunction InstallFunction) (SyncReason, error) { | ||||
|  | @ -760,27 +760,9 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, Look | |||
| 			// in between
 | ||||
| 
 | ||||
| 			// in this case also do not forget to install lookup function
 | ||||
| 			// new databases could have been created that need the pooler schema
 | ||||
| 			if !c.ConnectionPooler[role].LookupFunction { | ||||
| 				newConnectionPooler := newSpec.Spec.ConnectionPooler | ||||
| 
 | ||||
| 				specSchema := "" | ||||
| 				specUser := "" | ||||
| 
 | ||||
| 				if newConnectionPooler != nil { | ||||
| 					specSchema = newConnectionPooler.Schema | ||||
| 					specUser = newConnectionPooler.User | ||||
| 				} | ||||
| 
 | ||||
| 				schema := util.Coalesce( | ||||
| 					specSchema, | ||||
| 					c.OpConfig.ConnectionPooler.Schema) | ||||
| 
 | ||||
| 				user := util.Coalesce( | ||||
| 					specUser, | ||||
| 					c.OpConfig.ConnectionPooler.User) | ||||
| 
 | ||||
| 				if err = LookupFunction(schema, user, role); err != nil { | ||||
| 			if c.ConnectionPooler[role].LookupFunction { | ||||
| 				if err = c.syncConnectionPoolerSchema(LookupFunction); err != nil { | ||||
| 					c.ConnectionPooler[role].LookupFunction = true | ||||
| 					return NoSync, err | ||||
| 				} | ||||
| 			} | ||||
|  | @ -935,3 +917,29 @@ func (c *Cluster) syncConnectionPoolerWorker(oldSpec, newSpec *acidv1.Postgresql | |||
| 
 | ||||
| 	return NoSync, nil | ||||
| } | ||||
| 
 | ||||
| func (c *Cluster) syncConnectionPoolerSchema(LookupFunction InstallFunction) error { | ||||
| 
 | ||||
| 	connectionPooler := c.Spec.ConnectionPooler | ||||
| 	specSchema := "" | ||||
| 	specUser := "" | ||||
| 
 | ||||
| 	if connectionPooler != nil { | ||||
| 		specSchema = connectionPooler.Schema | ||||
| 		specUser = connectionPooler.User | ||||
| 	} | ||||
| 
 | ||||
| 	schema := util.Coalesce( | ||||
| 		specSchema, | ||||
| 		c.OpConfig.ConnectionPooler.Schema) | ||||
| 
 | ||||
| 	user := util.Coalesce( | ||||
| 		specUser, | ||||
| 		c.OpConfig.ConnectionPooler.User) | ||||
| 
 | ||||
| 	if err := LookupFunction(schema, user); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ import ( | |||
| 	"k8s.io/client-go/kubernetes/fake" | ||||
| ) | ||||
| 
 | ||||
| func mockInstallLookupFunction(schema string, user string, role PostgresRole) error { | ||||
| func mockInstallLookupFunction(schema string, user string) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -508,7 +508,7 @@ func (c *Cluster) execCreateOrAlterExtension(extName, schemaName, statement, doi | |||
| 
 | ||||
| // Creates a connection pool credentials lookup function in every database to
 | ||||
| // perform remote authentication.
 | ||||
| func (c *Cluster) installLookupFunction(poolerSchema, poolerUser string, role PostgresRole) error { | ||||
| func (c *Cluster) installLookupFunction(poolerSchema, poolerUser string) error { | ||||
| 	var stmtBytes bytes.Buffer | ||||
| 
 | ||||
| 	c.logger.Info("Installing lookup function") | ||||
|  | @ -604,8 +604,8 @@ func (c *Cluster) installLookupFunction(poolerSchema, poolerUser string, role Po | |||
| 		c.logger.Infof("pooler lookup function installed into %s", dbname) | ||||
| 	} | ||||
| 
 | ||||
| 	if len(failedDatabases) == 0 { | ||||
| 		c.ConnectionPooler[role].LookupFunction = true | ||||
| 	if len(failedDatabases) > 0 { | ||||
| 		return fmt.Errorf("could not install pooler lookup function in every specified databases") | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
|  |  | |||
|  | @ -758,6 +758,13 @@ func (c *Cluster) syncDatabases() error { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if len(createDatabases) > 0 { | ||||
| 		// create the pooler objects in new database if needed
 | ||||
| 		if needConnectionPooler(&c.Spec) { | ||||
| 			c.syncConnectionPoolerSchema(c.installLookupFunction) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// set default privileges for prepared database
 | ||||
| 	for _, preparedDatabase := range preparedDatabases { | ||||
| 		if err := c.initDbConnWithName(preparedDatabase); err != nil { | ||||
|  |  | |||
|  | @ -72,7 +72,7 @@ type ClusterStatus struct { | |||
| 
 | ||||
| type TemplateParams map[string]interface{} | ||||
| 
 | ||||
| type InstallFunction func(schema string, user string, role PostgresRole) error | ||||
| type InstallFunction func(schema string, user string) error | ||||
| 
 | ||||
| type SyncReason []string | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue