Skip to content

Commit 6f7fb0b

Browse files
committed
sql: fix bootstrap data for tenant
In #156535, we found a bug where is that when running upgrade tests with the `cockroach-go-testserver-25.3` config, we should have bootstrapped with the 25.3 data, not 25.2. This commit fixes this bug, in a way so that we don't have to adjust this logic for every future release. Release note: None Epic: None
1 parent 353e4b9 commit 6f7fb0b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

pkg/sql/tenant_creation.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package sql
77

88
import (
9+
"cmp"
910
"context"
1011
gojson "encoding/json"
1112
"fmt"
1213
"math"
14+
"slices"
1315
"strings"
1416
"time"
1517

@@ -170,16 +172,30 @@ func BootstrapTenant(
170172
// cluster's bootstrapping logic.
171173
tenantVersion.Version = clusterversion.Latest.Version()
172174
bootstrapVersionOverride = 0
173-
case execCfg.Settings.Version.IsActive(ctx, clusterversion.PreviousRelease):
174-
// If the previous major version is active, use that version to create the
175-
// tenant and bootstrap it just like the previous major version binary
176-
// would, using hardcoded initial values.
177-
tenantVersion.Version = clusterversion.PreviousRelease.Version()
178-
bootstrapVersionOverride = clusterversion.PreviousRelease
179175
default:
180-
// Otherwise, use the initial values from the min supported version.
181-
tenantVersion.Version = clusterversion.MinSupported.Version()
182-
bootstrapVersionOverride = clusterversion.MinSupported
176+
// Iterate through supported previous releases in reverse order to find the
177+
// appropriate bootstrap version.
178+
supportedReleases := clusterversion.SupportedPreviousReleases()
179+
180+
// Sort to ensure proper ordering (should already be sorted, but being safe).
181+
slices.SortFunc(supportedReleases, func(a, b clusterversion.Key) int {
182+
return cmp.Compare(a, b)
183+
})
184+
185+
// If no supported release is active, fall back to min supported version.
186+
// This should not happen in practice.
187+
foundVersion := clusterversion.MinSupported
188+
for i := len(supportedReleases) - 1; i >= 0; i-- {
189+
k := supportedReleases[i]
190+
if execCfg.Settings.Version.IsActive(ctx, k) {
191+
// Use the highest active supported release to create the tenant and
192+
// bootstrap it with the hardcoded initial values for that version.
193+
foundVersion = k
194+
break
195+
}
196+
}
197+
tenantVersion.Version = foundVersion.Version()
198+
bootstrapVersionOverride = foundVersion
183199
}
184200

185201
initialValuesOpts := bootstrap.InitialValuesOpts{

0 commit comments

Comments
 (0)