mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-18 17:00:56 +02:00
add unit test and documentation for finalizers (#2509)
* add unit test and documentation for finalizers * error msg with lower case and cover sync case * try to avoid adding json-patch dependency * use Update to remove finalizer * changing status and finalizer during create * do not call Delete() twice
This commit is contained in:
@@ -17,7 +17,6 @@ var VersionMap = map[string]int{
|
||||
"13": 130000,
|
||||
"14": 140000,
|
||||
"15": 150000,
|
||||
|
||||
}
|
||||
|
||||
// IsBiggerPostgresVersion Compare two Postgres version numbers
|
||||
@@ -104,31 +103,31 @@ func (c *Cluster) majorVersionUpgrade() error {
|
||||
if c.currentMajorVersion < desiredVersion {
|
||||
podName := &spec.NamespacedName{Namespace: masterPod.Namespace, Name: masterPod.Name}
|
||||
c.logger.Infof("triggering major version upgrade on pod %s of %d pods", masterPod.Name, numberOfPods)
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "Starting major version upgrade on pod %s of %d pods", masterPod.Name, numberOfPods)
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "starting major version upgrade on pod %s of %d pods", masterPod.Name, numberOfPods)
|
||||
upgradeCommand := fmt.Sprintf("set -o pipefail && /usr/bin/python3 /scripts/inplace_upgrade.py %d 2>&1 | tee last_upgrade.log", numberOfPods)
|
||||
|
||||
c.logger.Debugf("checking if the spilo image runs with root or non-root (check for user id=0)")
|
||||
resultIdCheck, errIdCheck := c.ExecCommand(podName, "/bin/bash", "-c", "/usr/bin/id -u")
|
||||
if errIdCheck != nil {
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Major Version Upgrade", "Checking user id to run upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, errIdCheck)
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Major Version Upgrade", "checking user id to run upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, errIdCheck)
|
||||
}
|
||||
|
||||
resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n")
|
||||
var result string
|
||||
if resultIdCheck != "0" {
|
||||
c.logger.Infof("User id was identified as: %s, hence default user is non-root already", resultIdCheck)
|
||||
c.logger.Infof("user id was identified as: %s, hence default user is non-root already", resultIdCheck)
|
||||
result, err = c.ExecCommand(podName, "/bin/bash", "-c", upgradeCommand)
|
||||
} else {
|
||||
c.logger.Infof("User id was identified as: %s, using su to reach the postgres user", resultIdCheck)
|
||||
c.logger.Infof("user id was identified as: %s, using su to reach the postgres user", resultIdCheck)
|
||||
result, err = c.ExecCommand(podName, "/bin/su", "postgres", "-c", upgradeCommand)
|
||||
}
|
||||
if err != nil {
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Major Version Upgrade", "Upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, err)
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Major Version Upgrade", "upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, err)
|
||||
return err
|
||||
}
|
||||
c.logger.Infof("upgrade action triggered and command completed: %s", result[:100])
|
||||
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "Upgrade from %d to %d finished", c.currentMajorVersion, desiredVersion)
|
||||
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "upgrade from %d to %d finished", c.currentMajorVersion, desiredVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user