From 43ed7fb7a2a1f1816f647d55b0eedc43136b8de5 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Thu, 3 Feb 2022 19:15:07 +0530 Subject: [PATCH 1/9] Update majorversionupgrade.go major version upgrade for rootless and ocp : solving #1689 --- pkg/cluster/majorversionupgrade.go | 33 +++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 36def164c..56729eb10 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -2,6 +2,7 @@ package cluster import ( "fmt" + "strings" "github.com/zalando/postgres-operator/pkg/spec" "github.com/zalando/postgres-operator/pkg/util" @@ -106,13 +107,35 @@ 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) 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) - if err != nil { - c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "Upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, err) - return err + // ######## checking if the spilo image runs with root or non-root (check for user id=0) + c.logger.Infof("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.EventTypeNormal, "Major Version Upgrade", "Pre-Upgrade step (checking user with id -u) for Upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, errIdCheck) + return errIdCheck + } + + resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n") + + 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) + if err != nil { + c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "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]) + } 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.EventTypeNormal, "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) } } From 633bb0d7a91ce12a143d725cfc28fbc71936cdac Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Tue, 15 Feb 2022 18:37:26 +0530 Subject: [PATCH 2/9] Update majorversionupgrade.go changed Infof to Debugf --- pkg/cluster/majorversionupgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 56729eb10..03fb6901b 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -108,7 +108,7 @@ func (c *Cluster) majorVersionUpgrade() error { upgradeCommand := fmt.Sprintf("/usr/bin/python3 /scripts/inplace_upgrade.py %d 2>&1 | tee last_upgrade.log", numberOfPods) // ######## checking if the spilo image runs with root or non-root (check for user id=0) - c.logger.Infof("checking if the spilo image runs with root or non-root (check for user id=0)") + 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 { From a3569fb9f3b31340f77d68df6e12999ae1b96130 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Wed, 16 Feb 2022 12:09:19 +0530 Subject: [PATCH 3/9] Update majorversionupgrade.go removed comment --- pkg/cluster/majorversionupgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 03fb6901b..31eeec742 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -107,7 +107,7 @@ 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) upgradeCommand := fmt.Sprintf("/usr/bin/python3 /scripts/inplace_upgrade.py %d 2>&1 | tee last_upgrade.log", numberOfPods) - // ######## checking if the spilo image runs with root or non-root (check for user id=0) + 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") From 17ee0758c293a5901c349f146faca228c1282eb6 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Thu, 24 Mar 2022 17:07:55 +0530 Subject: [PATCH 4/9] Update majorversionupgrade.go --- pkg/cluster/majorversionupgrade.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 31eeec742..8d4a6651f 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -117,27 +117,23 @@ func (c *Cluster) majorVersionUpgrade() error { } resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n") - + result, err := c.ExecCommand(podName, "/bin/bash") 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) - if err != nil { - c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "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]) + 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.EventTypeNormal, "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]) + result, err = c.ExecCommand(podName, "/bin/su", "postgres", "-c", upgradeCommand) + } + if err != nil { + c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "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) } + } return nil From 636f3ca70abc12cf232e3d2ef6be769ec5399c87 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Fri, 25 Mar 2022 15:59:10 +0530 Subject: [PATCH 5/9] Update majorversionupgrade.go --- pkg/cluster/majorversionupgrade.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 8d4a6651f..acbff81ab 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -112,12 +112,11 @@ func (c *Cluster) majorVersionUpgrade() error { resultIdCheck, errIdCheck := c.ExecCommand(podName, "/bin/bash", "-c", "/usr/bin/id -u") if errIdCheck != nil { - c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Major Version Upgrade", "Pre-Upgrade step (checking user with id -u) for Upgrade from %d to %d FAILED: %v", c.currentMajorVersion, desiredVersion, errIdCheck) - return 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") - result, err := c.ExecCommand(podName, "/bin/bash") + //result, err := c.ExecCommand(podName, "/bin/bash") 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) From 59f6d1af21ec084dad1508ae4beb633d443c3a48 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Wed, 30 Mar 2022 16:33:33 +0530 Subject: [PATCH 6/9] Update majorversionupgrade.go --- pkg/cluster/majorversionupgrade.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index acbff81ab..53ebdaea0 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -109,14 +109,13 @@ func (c *Cluster) majorVersionUpgrade() error { 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) } resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n") - //result, err := c.ExecCommand(podName, "/bin/bash") + var result, err string, error 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) From e4c777504d68c2a43c6501c0aec2d403661ba0f8 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Wed, 30 Mar 2022 16:48:14 +0530 Subject: [PATCH 7/9] Update majorversionupgrade.go --- pkg/cluster/majorversionupgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 53ebdaea0..3d26a49a9 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -115,7 +115,7 @@ func (c *Cluster) majorVersionUpgrade() error { } resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n") - var result, err string, error + 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) From e62d46ba148f904475347df4d64c38dc006bd268 Mon Sep 17 00:00:00 2001 From: neelasha-09 <66790082+neelasha-09@users.noreply.github.com> Date: Thu, 31 Mar 2022 13:46:29 +0530 Subject: [PATCH 8/9] Update majorversionupgrade.go removed additional spaces --- pkg/cluster/majorversionupgrade.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 3d26a49a9..801de1e41 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -106,7 +106,6 @@ func (c *Cluster) majorVersionUpgrade() error { 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) upgradeCommand := fmt.Sprintf("/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") @@ -124,14 +123,13 @@ func (c *Cluster) majorVersionUpgrade() error { result, err = c.ExecCommand(podName, "/bin/su", "postgres", "-c", upgradeCommand) } if err != nil { - c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "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) } - } return nil From 21c336eefcbe8a7feb03ad3893302beec955eac7 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Thu, 31 Mar 2022 12:36:19 +0200 Subject: [PATCH 9/9] Update pkg/cluster/majorversionupgrade.go --- pkg/cluster/majorversionupgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/majorversionupgrade.go b/pkg/cluster/majorversionupgrade.go index 801de1e41..d42f2c93d 100644 --- a/pkg/cluster/majorversionupgrade.go +++ b/pkg/cluster/majorversionupgrade.go @@ -114,7 +114,7 @@ func (c *Cluster) majorVersionUpgrade() error { } resultIdCheck = strings.TrimSuffix(resultIdCheck, "\n") - var result string + 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)