mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 11:21:28 +02:00
Remove operator checks that prevent PG major version upgrade (#1160)
* remove checks that prevent major version upgrade Co-authored-by: Sergey Dudoladov <sergey.dudoladov@zalando.de>
This commit is contained in:
co-authored by
Sergey Dudoladov
parent
d76419565b
commit
4f3bb6aa8c
@@ -626,13 +626,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
|
||||
// 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 can be done manually after StatefulSet Sync",
|
||||
oldSpec.Spec.PostgresqlParam.PgVersion, newSpec.Spec.PostgresqlParam.PgVersion)
|
||||
}
|
||||
|
||||
// Service
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -557,95 +557,6 @@ func TestExtractPgVersionFromBinPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPgVersion(t *testing.T) {
|
||||
testName := "TestGetPgVersion"
|
||||
tests := []struct {
|
||||
subTest string
|
||||
pgContainer v1.Container
|
||||
currentPgVersion string
|
||||
newPgVersion string
|
||||
}{
|
||||
{
|
||||
subTest: "new version with decimal point differs from current SPILO_CONFIGURATION",
|
||||
pgContainer: v1.Container{
|
||||
Name: "postgres",
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "SPILO_CONFIGURATION",
|
||||
Value: "{\"postgresql\": {\"bin_dir\": \"/usr/lib/postgresql/9.6/bin\"}}",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentPgVersion: "9.6",
|
||||
newPgVersion: "12",
|
||||
},
|
||||
{
|
||||
subTest: "new version differs from current SPILO_CONFIGURATION",
|
||||
pgContainer: v1.Container{
|
||||
Name: "postgres",
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "SPILO_CONFIGURATION",
|
||||
Value: "{\"postgresql\": {\"bin_dir\": \"/usr/lib/postgresql/11/bin\"}}",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentPgVersion: "11",
|
||||
newPgVersion: "12",
|
||||
},
|
||||
{
|
||||
subTest: "new version is lower than the one found in current SPILO_CONFIGURATION",
|
||||
pgContainer: v1.Container{
|
||||
Name: "postgres",
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "SPILO_CONFIGURATION",
|
||||
Value: "{\"postgresql\": {\"bin_dir\": \"/usr/lib/postgresql/12/bin\"}}",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentPgVersion: "12",
|
||||
newPgVersion: "11",
|
||||
},
|
||||
{
|
||||
subTest: "new version is the same like in the current SPILO_CONFIGURATION",
|
||||
pgContainer: v1.Container{
|
||||
Name: "postgres",
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "SPILO_CONFIGURATION",
|
||||
Value: "{\"postgresql\": {\"bin_dir\": \"/usr/lib/postgresql/12/bin\"}}",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentPgVersion: "12",
|
||||
newPgVersion: "12",
|
||||
},
|
||||
}
|
||||
|
||||
var cluster = New(
|
||||
Config{
|
||||
OpConfig: config.Config{
|
||||
ProtectedRoles: []string{"admin"},
|
||||
Auth: config.Auth{
|
||||
SuperUsername: superUserName,
|
||||
ReplicationUsername: replicationUserName,
|
||||
},
|
||||
},
|
||||
}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger, eventRecorder)
|
||||
|
||||
for _, tt := range tests {
|
||||
pgVersion, err := cluster.getNewPgVersion(tt.pgContainer, tt.newPgVersion)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if pgVersion != tt.currentPgVersion {
|
||||
t.Errorf("%s %s: Expected version %s, have %s instead",
|
||||
testName, tt.subTest, tt.currentPgVersion, pgVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecretVolume(t *testing.T) {
|
||||
testName := "TestSecretVolume"
|
||||
tests := []struct {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user