first commit
This commit is contained in:
		
							parent
							
								
									38e15183a2
								
							
						
					
					
						commit
						64292177eb
					
				| 
						 | 
				
			
			@ -625,13 +625,16 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
 | 
			
		|||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	if oldSpec.Spec.PostgresqlParam.PgVersion != newSpec.Spec.PostgresqlParam.PgVersion { // PG versions comparison
 | 
			
		||||
	if oldSpec.Spec.PostgresqlParam.PgVersion >= newSpec.Spec.PostgresqlParam.PgVersion {
 | 
			
		||||
		c.logger.Warningf("postgresql version change(%q -> %q) has no effect",
 | 
			
		||||
			oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
		c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "PostgreSQL", "postgresql version change(%q -> %q) has no effect",
 | 
			
		||||
			oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
		//we need that hack to generate statefulset with the old version
 | 
			
		||||
		newSpec.Spec.PostgresqlParam.PgVersion = oldSpec.Spec.PostgresqlParam.PgVersion
 | 
			
		||||
	} else {
 | 
			
		||||
		c.logger.Infof("postgresql version increased (%q -> %q), major version upgrade will start after StatefulSet Sync",
 | 
			
		||||
			oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Service
 | 
			
		||||
| 
						 | 
				
			
			@ -787,6 +790,18 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
 | 
			
		|||
		updateFailed = true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// major version upgrade should run only when all changes to pods have completed
 | 
			
		||||
	if oldSpec.Spec.PostgresqlParam.PgVersion < newSpec.Spec.PostgresqlParam.PgVersion {
 | 
			
		||||
		c.logger.Infof("postgresql version increased (%q -> %q), triggering major version upgrade",
 | 
			
		||||
			oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
		c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "PostgreSQL", "postgresql version increased (%q -> %q), triggering major version upgrade",
 | 
			
		||||
			oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
		if err := c.triggerMajorVersionUpgrade(&newSpec.Spec); err != nil {
 | 
			
		||||
			c.logger.Errorf("major version upgrade failed: %v", err)
 | 
			
		||||
			updateFailed = true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1500,3 +1515,14 @@ func (c *Cluster) needSyncConnectionPoolerDefaults(
 | 
			
		|||
 | 
			
		||||
	return sync, reasons
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Cluster) triggerMajorVersionUpgrade(newSpec *acidv1.PostgresSpec) (err error) {
 | 
			
		||||
	masterPod, err := c.getRolePods(Master)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("could not get master pod: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	masterNamespacedName := spec.NamespacedName{Namespace: masterPod[0].Namespace, Name: masterPod[0].Name}
 | 
			
		||||
 | 
			
		||||
	_, err = c.ExecCommand(&masterNamespacedName, "python3", "/scripts/inplace_upgrade.py ", fmt.Sprintf("%d", c.getNumberOfInstances(newSpec)))
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -909,41 +909,6 @@ func extractPgVersionFromBinPath(binPath string, template string) (string, error
 | 
			
		|||
	return fmt.Sprintf("%v", pgVersion), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Cluster) getNewPgVersion(container v1.Container, newPgVersion string) (string, error) {
 | 
			
		||||
	var (
 | 
			
		||||
		spiloConfiguration spiloConfiguration
 | 
			
		||||
		runningPgVersion   string
 | 
			
		||||
		err                error
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	for _, env := range container.Env {
 | 
			
		||||
		if env.Name != "SPILO_CONFIGURATION" {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		err = json.Unmarshal([]byte(env.Value), &spiloConfiguration)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return newPgVersion, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(spiloConfiguration.PgLocalConfiguration) > 0 {
 | 
			
		||||
		currentBinPath := fmt.Sprintf("%v", spiloConfiguration.PgLocalConfiguration[patroniPGBinariesParameterName])
 | 
			
		||||
		runningPgVersion, err = extractPgVersionFromBinPath(currentBinPath, pgBinariesLocationTemplate)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", fmt.Errorf("could not extract Postgres version from %v in SPILO_CONFIGURATION", currentBinPath)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		return "", fmt.Errorf("could not find %q setting in SPILO_CONFIGURATION", patroniPGBinariesParameterName)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if runningPgVersion != newPgVersion {
 | 
			
		||||
		c.logger.Warningf("postgresql version change(%q -> %q) has no effect", runningPgVersion, newPgVersion)
 | 
			
		||||
		newPgVersion = runningPgVersion
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return newPgVersion, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.StatefulSet, error) {
 | 
			
		||||
 | 
			
		||||
	var (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -332,18 +332,6 @@ func (c *Cluster) syncStatefulSet() error {
 | 
			
		|||
		// statefulset is already there, make sure we use its definition in order to compare with the spec.
 | 
			
		||||
		c.Statefulset = sset
 | 
			
		||||
 | 
			
		||||
		// check if there is no Postgres version mismatch
 | 
			
		||||
		for _, container := range c.Statefulset.Spec.Template.Spec.Containers {
 | 
			
		||||
			if container.Name != "postgres" {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			pgVersion, err := c.getNewPgVersion(container, c.Spec.PostgresqlParam.PgVersion)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("could not parse current Postgres version: %v", err)
 | 
			
		||||
			}
 | 
			
		||||
			c.Spec.PostgresqlParam.PgVersion = pgVersion
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		desiredSS, err := c.generateStatefulSet(&c.Spec)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("could not generate statefulset: %v", err)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue