Remove hardcoded VersionMap from majorversionupgrade (#3043)

Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
This commit is contained in:
Jorge Solorzano 2026-03-02 11:13:10 +01:00 committed by GitHub
parent 2a31c403d0
commit d495825f4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
@ -14,15 +15,6 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
) )
// VersionMap Map of version numbers
var VersionMap = map[string]int{
"14": 140000,
"15": 150000,
"16": 160000,
"17": 170000,
"18": 180000,
}
const ( const (
majorVersionUpgradeSuccessAnnotation = "last-major-upgrade-success" majorVersionUpgradeSuccessAnnotation = "last-major-upgrade-success"
majorVersionUpgradeFailureAnnotation = "last-major-upgrade-failure" majorVersionUpgradeFailureAnnotation = "last-major-upgrade-failure"
@ -30,14 +22,15 @@ const (
// IsBiggerPostgresVersion Compare two Postgres version numbers // IsBiggerPostgresVersion Compare two Postgres version numbers
func IsBiggerPostgresVersion(old string, new string) bool { func IsBiggerPostgresVersion(old string, new string) bool {
oldN := VersionMap[old] oldN, _ := strconv.Atoi(old)
newN := VersionMap[new] newN, _ := strconv.Atoi(new)
return newN > oldN return newN > oldN
} }
// GetDesiredMajorVersionAsInt Convert string to comparable integer of PG version // GetDesiredMajorVersionAsInt Convert string to comparable integer of PG version
func (c *Cluster) GetDesiredMajorVersionAsInt() int { func (c *Cluster) GetDesiredMajorVersionAsInt() int {
return VersionMap[c.GetDesiredMajorVersion()] version, _ := strconv.Atoi(c.GetDesiredMajorVersion())
return version * 10000
} }
// GetDesiredMajorVersion returns major version to use, incl. potential auto upgrade // GetDesiredMajorVersion returns major version to use, incl. potential auto upgrade