Skip to content

feat(upgrade): specify upgrade starting version constraint #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
Expand Down Expand Up @@ -348,9 +350,6 @@ jobs:
fail-fast: false
matrix:
include:
- fabricmode: spine-leaf
fromversion: "beta-1"
fromflags: "--usb"
- fabricmode: spine-leaf
fromversion: "24.09"
fromflags: "-m=iso"
Expand Down
4 changes: 3 additions & 1 deletion api/fabricator/v1beta1/fabricator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ func (f *Fabricator) Validate(ctx context.Context) error {
}

func (f *Fabricator) CalculateVersions(def Versions) error {
f.Status.Versions = *f.Spec.Overrides.Versions.DeepCopy()
if f.Status.Versions.Fabricator.Controller == "" {
f.Status.Versions = *f.Spec.Overrides.Versions.DeepCopy()
}

if err := mergo.Merge(&f.Status.Versions, def); err != nil {
return fmt.Errorf("merging versions: %w", err)
Expand Down
20 changes: 20 additions & 0 deletions pkg/fab/recipe/control_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"time"

"github.com/Masterminds/semver/v3"
vpcapi "go.githedgehog.com/fabric/api/vpc/v1beta1"
wiringapi "go.githedgehog.com/fabric/api/wiring/v1beta1"
"go.githedgehog.com/fabric/pkg/util/kubeutil"
Expand Down Expand Up @@ -81,6 +82,25 @@ func (c *ControlUpgrade) Run(ctx context.Context) error {
return fmt.Errorf("retrying getting fabricator and control nodes: %w", err)
}

constraint, err := semver.NewConstraint(string(fab.UpgradeConstraint))
if err != nil {
return fmt.Errorf("parsing upgrade constraint: %w", err)
}

slog.Info("Currently running fabricator", "version", c.Fab.Status.Versions.Fabricator.Controller)

// TODO should we add some other markers on the host to make it more reliable?
version, err := semver.NewVersion(string(c.Fab.Status.Versions.Fabricator.Controller))
if err != nil {
return fmt.Errorf("parsing fabricator version: %w", err)
}

if !constraint.Check(version) {
slog.Error("Upgrading from the current version not supported, please upgrade to the older versions first")

return fmt.Errorf("fabricator version %q does not match upgrade constraint %q", version, constraint) //nolint:goerr113
}

if err := waitKube(ctx, kube, c.Control.Name, "",
&comp.Node{}, func(obj *comp.Node) (bool, error) {
for _, cond := range obj.Status.Conditions {
Expand Down
1 change: 1 addition & 0 deletions pkg/fab/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

var (
UpgradeConstraint = meta.Version(">=0.32.1-0") // 24.09 release; -0 is added to allow pre-release versions
FabricatorVersion = meta.Version(version.Version)
FabricVersion = meta.Version("v0.75.0")
GatewayVersion = meta.Version("v0.5.0")
Expand Down
25 changes: 25 additions & 0 deletions pkg/fab/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"strings"
"testing"

"github.com/Masterminds/semver/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.githedgehog.com/fabricator/pkg/version"
"golang.org/x/mod/modfile"
)

Expand Down Expand Up @@ -56,3 +58,26 @@ func checkVersion(t *testing.T, modfile *modfile.File, path, version string) {

assert.Truef(t, found, "Require path %s not found in go.mod", path)
}

func TestUpgradeConstraint(t *testing.T) {
c, err := semver.NewConstraint(string(UpgradeConstraint))
require.NoError(t, err, "Error parsing upgrade constraint")

for _, test := range []struct {
name string
version string
expected bool
}{
{"current", version.Version, true},
{"25.01", "v0.36.1", true},
{"24.09", "v0.32.1", true},
{"beta-1", "v0.30.3", false},
} {
t.Run(string(test.version), func(t *testing.T) {
v, err := semver.NewVersion(string(test.version))
require.NoError(t, err, "Error parsing version %q", test.version)

require.Equal(t, test.expected, c.Check(v), "Upgrade from version %q should be %v", test.version, test.expected)
})
}
}
Loading