* major version upgrade for rootless and ocp : solving #1689 Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
This commit is contained in:
		
							parent
							
								
									2333d531d3
								
							
						
					
					
						commit
						f5cca1a093
					
				|  | @ -2,6 +2,7 @@ package cluster | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/zalando/postgres-operator/pkg/spec" | 	"github.com/zalando/postgres-operator/pkg/spec" | ||||||
| 	"github.com/zalando/postgres-operator/pkg/util" | 	"github.com/zalando/postgres-operator/pkg/util" | ||||||
|  | @ -106,13 +107,27 @@ func (c *Cluster) majorVersionUpgrade() error { | ||||||
| 			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("/usr/bin/python3 /scripts/inplace_upgrade.py %d 2>&1 | tee last_upgrade.log", numberOfPods) | 			upgradeCommand := fmt.Sprintf("/usr/bin/python3 /scripts/inplace_upgrade.py %d 2>&1 | tee last_upgrade.log", numberOfPods) | ||||||
| 			 | 			 | ||||||
| 			result, err := c.ExecCommand(podName, "/bin/su", "postgres", "-c", upgradeCommand) | 			c.logger.Debugf("checking if the spilo image runs with root or non-root (check for user id=0)") | ||||||
| 			if err != nil { | 			resultIdCheck, errIdCheck := c.ExecCommand(podName, "/bin/bash", "-c", "/usr/bin/id -u") | ||||||
| 				c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "Upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, err) | 			if errIdCheck != nil { | ||||||
| 				return err | 				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) | ||||||
|  | 				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) | ||||||
|  | 				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) | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
| 			c.logger.Infof("upgrade action triggered and command completed: %s", result[:100]) | 			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) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue