@@ -3,6 +3,7 @@ package seaweedfs
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "time"
78
89 "github.com/Masterminds/semver/v3"
@@ -52,6 +53,23 @@ func (s *SeaweedFS) Upgrade(
5253 }
5354 }
5455
56+ // When upgrading from a previous version, we need to disable hashicorp raft as a rolling
57+ // update will fail if toggling raft implementation.
58+ shouldDisableHashicorpRaft , err := s .shouldDisableRaftHashicorp (ctx , kcli )
59+ if err != nil {
60+ return fmt .Errorf ("checking if raft hashicorp should be disabled: %w" , err )
61+ }
62+ if shouldDisableHashicorpRaft {
63+ logrus .Debug ("Setting master.raftHashicorp=false and master.raftBootstrap=false" )
64+ if err := helm .SetValue (values , "master.raftHashicorp" , false ); err != nil {
65+ return fmt .Errorf ("setting master.raftHashicorp: %w" , err )
66+ }
67+ if err := helm .SetValue (values , "master.raftBootstrap" , false ); err != nil {
68+ return fmt .Errorf ("setting master.raftBootstrap: %w" , err )
69+ }
70+ logrus .Debug ("master.raftHashicorp=false and master.raftBootstrap=false set" )
71+ }
72+
5573 _ , err = hcli .Upgrade (ctx , helm.UpgradeOptions {
5674 ReleaseName : s .ReleaseName (),
5775 ChartPath : s .ChartLocation (domains ),
@@ -73,39 +91,20 @@ func (s *SeaweedFS) Upgrade(
7391func (s * SeaweedFS ) needsScalingRestart (ctx context.Context , kcli client.Client ) (bool , error ) {
7492 logrus .Debug ("Checking if scaling fix is needed for upgrade from pre-2.7.3" )
7593
76- // Get the latest installation to use for getting the previous one
77- latest , err := kubeutils .GetLatestInstallation (ctx , kcli )
78- if err != nil {
79- return false , fmt .Errorf ("getting latest installation: %w" , err )
80- }
81-
82- // Get the previous installation to check version
83- previous , err := kubeutils .GetPreviousInstallation (ctx , kcli , latest )
94+ prevVersion , err := getPreviousECVersion (ctx , kcli )
8495 if err != nil {
85- var errNotFound kubeutils.ErrInstallationNotFound
86- if errors .As (err , & errNotFound ) {
87- logrus .Debug ("No previous installation found, no scaling fix needed" )
88- return false , nil // No previous installation means no upgrade, no scaling fix needed
89- }
90- return false , fmt .Errorf ("getting previous installation: %w" , err )
91- }
92-
93- if previous == nil || previous .Spec .Config == nil || previous .Spec .Config .Version == "" {
94- return false , errors .New ("previous installation has no version config" )
95- }
96-
97- // Parse previous version
98- prevVersion , err := semver .NewVersion (previous .Spec .Config .Version )
99- if err != nil {
100- return false , fmt .Errorf ("parsing previous version %s: %w" , previous .Spec .Config .Version , err )
96+ return false , fmt .Errorf ("get previous installation: %w" , err )
97+ } else if prevVersion == nil {
98+ logrus .Debug ("No previous version found, no scaling fix needed" )
99+ return false , nil
101100 }
102101
103102 // Only restart if upgrading from < 2.7.3
104103 if ! lessThanECVersion273 (prevVersion ) {
105- logrus .Debugf ("Previous version %s >= 2.7.3, no scaling fix needed" , prevVersion . String () )
104+ logrus .Debugf ("Previous version %s >= 2.7.3, no scaling fix needed" , prevVersion )
106105 return false , nil
107106 }
108- logrus .Debugf ("Previous version %s < 2.7.3, checking StatefulSet configuration" , prevVersion . String () )
107+ logrus .Debugf ("Previous version %s < 2.7.3, checking StatefulSet configuration" , prevVersion )
109108
110109 // Check if SeaweedFS StatefulSet exists and check current replica configuration
111110 var sts appsv1.StatefulSet
@@ -141,12 +140,65 @@ func (s *SeaweedFS) needsScalingRestart(ctx context.Context, kcli client.Client)
141140 return false , nil
142141}
143142
143+ func getPreviousECVersion (ctx context.Context , kcli client.Client ) (* semver.Version , error ) {
144+ latest , err := kubeutils .GetLatestInstallation (ctx , kcli )
145+ if err != nil {
146+ return nil , fmt .Errorf ("get latest installation: %w" , err )
147+ }
148+ previous , err := kubeutils .GetPreviousInstallation (ctx , kcli , latest )
149+ if err != nil {
150+ var errNotFound kubeutils.ErrInstallationNotFound
151+ if errors .As (err , & errNotFound ) {
152+ return nil , nil
153+ }
154+ return nil , fmt .Errorf ("get previous installation: %w" , err )
155+ }
156+ if previous .Spec .Config == nil || previous .Spec .Config .Version == "" {
157+ return nil , errors .New ("previous installation has no version config" )
158+ }
159+ sv , err := semver .NewVersion (previous .Spec .Config .Version )
160+ if err != nil {
161+ return nil , fmt .Errorf ("parse previous version %s: %w" , previous .Spec .Config .Version , err )
162+ }
163+ return sv , nil
164+ }
165+
166+ var version273 = semver .MustParse ("2.7.3" )
167+
144168// lessThanECVersion273 checks if a version is less than 2.7.3
145169func lessThanECVersion273 (ver * semver.Version ) bool {
146- version273 := semver .MustParse ("2.7.3" )
147170 return ver .LessThan (version273 )
148171}
149172
173+ // shouldDisableRaftHashicorp checks to see if there is a previous statefulset without
174+ // -raftHashicorp argument
175+ func (s * SeaweedFS ) shouldDisableRaftHashicorp (ctx context.Context , kcli client.Client ) (bool , error ) {
176+ logrus .Debug ("Checking if hashicorp raft should be disabled" )
177+
178+ var sts appsv1.StatefulSet
179+ nsn := client.ObjectKey {Namespace : s .Namespace (), Name : "seaweedfs-master" }
180+ if err := kcli .Get (ctx , nsn , & sts ); client .IgnoreNotFound (err ) != nil {
181+ return false , fmt .Errorf ("get seaweedfs master statefulset: %w" , err )
182+ } else if err != nil {
183+ // not found, so no previous statefulset
184+ logrus .Debug ("No previous statefulset found, do not disable raft hashicorp" )
185+ return false , nil
186+ }
187+ // check if the seaweedfs container has the -raftHashicorp argument
188+ for _ , container := range sts .Spec .Template .Spec .Containers {
189+ if container .Name == "seaweedfs" {
190+ for _ , arg := range append (container .Command , container .Args ... ) {
191+ if strings .Contains (arg , "-raftHashicorp" ) {
192+ logrus .Debug ("Raft hashicorp is enabled, do not disable it" )
193+ return false , nil
194+ }
195+ }
196+ }
197+ }
198+ logrus .Debug ("Raft hashicorp is disabled, disable it" )
199+ return true , nil
200+ }
201+
150202// scaleStatefulSet directly scales the StatefulSet to the target replica count
151203func (s * SeaweedFS ) scaleStatefulSet (ctx context.Context , kcli client.Client , replicas int32 ) error {
152204 // Get the current StatefulSet
0 commit comments