@@ -357,20 +357,22 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
357357 return nil
358358}
359359
360- func runtimeUpgradeCommandPreRunHandler (cmd * cobra.Command , args []string , cloneOpts * git. CloneOptions , runtimeName string ) error {
360+ func runtimeUpgradeCommandPreRunHandler (cmd * cobra.Command , args []string , opts * RuntimeUpgradeOptions ) error {
361361 handleCliStep (reporter .UpgradePhasePreCheckStart , "Starting pre checks" , nil , false )
362362
363- err := ensureRuntimeName (cmd .Context (), args , & runtimeName )
363+ err := ensureRuntimeName (cmd .Context (), args , & opts . RuntimeName )
364364 handleCliStep (reporter .UpgradeStepPreCheckEnsureRuntimeName , "Ensuring runtime name" , err , false )
365365 if err != nil {
366366 return fmt .Errorf ("%w" , err )
367367 }
368- err = ensureRepo (cmd , runtimeName , cloneOpts , true )
368+
369+ err = ensureRepo (cmd , opts .RuntimeName , opts .CloneOpts , true )
369370 handleCliStep (reporter .UpgradeStepPreCheckEnsureRuntimeRepo , "Getting runtime repo" , err , false )
370371 if err != nil {
371372 return fmt .Errorf ("%w" , err )
372373 }
373- err = ensureGitToken (cmd , cloneOpts )
374+
375+ err = ensureGitToken (cmd , opts .CloneOpts )
374376 handleCliStep (reporter .UpgradeStepPreCheckEnsureGitToken , "Getting git token" , err , false )
375377 if err != nil {
376378 return fmt .Errorf ("%w" , err )
@@ -1090,10 +1092,9 @@ func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOption
10901092
10911093func NewRuntimeUpgradeCommand () * cobra.Command {
10921094 var (
1093- runtimeName string
10941095 versionStr string
1095- cloneOpts * git.CloneOptions
10961096 finalParameters map [string ]string
1097+ opts RuntimeUpgradeOptions
10971098 )
10981099
10991100 cmd := & cobra.Command {
@@ -1118,61 +1119,60 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
11181119
11191120 createAnalyticsReporter (ctx , reporter .UpgradeFlow )
11201121
1121- err := runtimeUpgradeCommandPreRunHandler (cmd , args , cloneOpts , runtimeName )
1122+ err := runtimeUpgradeCommandPreRunHandler (cmd , args , & opts )
11221123 handleCliStep (reporter .UpgradePhasePreCheckFinish , "Finished pre installation checks" , err , false )
11231124 if err != nil {
11241125 return fmt .Errorf ("Pre installation error: %w" , err )
11251126 }
11261127
11271128 finalParameters = map [string ]string {
1128- "Runtime name" : runtimeName ,
1129- "Repository URL" : cloneOpts .Repo ,
1129+ "Runtime name" : opts .RuntimeName ,
1130+ "Repository URL" : opts .CloneOpts .Repo ,
1131+ }
1132+
1133+ if versionStr != "" {
1134+ finalParameters ["Version" ] = versionStr
11301135 }
11311136
11321137 err = getApprovalFromUser (ctx , finalParameters , "runtime upgrade" )
11331138 if err != nil {
11341139 return fmt .Errorf ("%w" , err )
11351140 }
11361141
1137- cloneOpts .Parse ()
1142+ opts . CloneOpts .Parse ()
11381143 return nil
11391144 },
11401145 RunE : func (cmd * cobra.Command , args []string ) error {
1141- var (
1142- version * semver.Version
1143- err error
1144- )
1146+ var err error
11451147 ctx := cmd .Context ()
11461148
11471149 if versionStr != "" {
1148- version , err = semver .NewVersion (versionStr )
1150+ opts . Version , err = semver .NewVersion (versionStr )
11491151 if err != nil {
11501152 return err
11511153 }
11521154 }
11531155
1154- err = RunRuntimeUpgrade (ctx , & RuntimeUpgradeOptions {
1155- RuntimeName : runtimeName ,
1156- Version : version ,
1157- CloneOpts : cloneOpts ,
1158- CommonConfig : & runtime.CommonConfig {
1159- CodefreshBaseURL : cfConfig .GetCurrentContext ().URL ,
1160- },
1161- })
1156+ opts .CommonConfig = & runtime.CommonConfig {
1157+ CodefreshBaseURL : cfConfig .GetCurrentContext ().URL ,
1158+ }
1159+
1160+ err = RunRuntimeUpgrade (ctx , & opts )
11621161 handleCliStep (reporter .UpgradePhaseFinish , "Runtime upgrade phase finished" , err , false )
11631162 return err
11641163 },
11651164 }
11661165
11671166 cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to upgrade to, defaults to latest" )
1168- cloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
1167+ opts . CloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
11691168
11701169 return cmd
11711170}
11721171
11731172func RunRuntimeUpgrade (ctx context.Context , opts * RuntimeUpgradeOptions ) error {
11741173 handleCliStep (reporter .UpgradePhaseStart , "Runtime upgrade phase started" , nil , true )
11751174
1175+ log .G (ctx ).Info ("Downloading runtime definition" )
11761176 newRt , err := runtime .Download (opts .Version , opts .RuntimeName )
11771177 handleCliStep (reporter .UpgradeStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , false )
11781178 if err != nil {
@@ -1187,22 +1187,29 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
11871187 return err
11881188 }
11891189
1190+ log .G (ctx ).Info ("Cloning installation repository" )
11901191 r , fs , err := opts .CloneOpts .GetRepo (ctx )
11911192 handleCliStep (reporter .UpgradeStepGetRepo , "Getting repository" , err , false )
11921193 if err != nil {
11931194 return err
11941195 }
11951196
1197+ log .G (ctx ).Info ("Loading current runtime definition" )
11961198 curRt , err := runtime .Load (fs , fs .Join (apstore .Default .BootsrtrapDir , opts .RuntimeName + ".yaml" ))
11971199 handleCliStep (reporter .UpgradeStepLoadRuntimeDefinition , "Loading runtime definition" , err , false )
11981200 if err != nil {
11991201 return fmt .Errorf ("failed to load current runtime definition: %w" , err )
12001202 }
12011203
12021204 if ! newRt .Spec .Version .GreaterThan (curRt .Spec .Version ) {
1203- return fmt .Errorf ("must upgrade to version > %s" , curRt .Spec .Version )
1205+ err = fmt .Errorf ("current runtime version (%s) is greater than or equal to the specified version (%s)" , curRt .Spec .Version , newRt .Spec .Version )
1206+ }
1207+ handleCliStep (reporter .UpgradeStepLoadRuntimeDefinition , "Comparing runtime versions" , err , false )
1208+ if err != nil {
1209+ return err
12041210 }
12051211
1212+ log .G (ctx ).Infof ("Upgrading runtime \" %s\" to version: v%s" , opts .RuntimeName , newRt .Spec .Version )
12061213 newComponents , err := curRt .Upgrade (fs , newRt , opts .CommonConfig )
12071214 handleCliStep (reporter .UpgradeStepUpgradeRuntime , "Upgrading runtime" , err , false )
12081215 if err != nil {
@@ -1217,16 +1224,17 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
12171224 }
12181225
12191226 for _ , component := range newComponents {
1220- infoStr := fmt .Sprintf ("Creating app '%s'" , component .Name )
1221- log .G (ctx ).Infof (infoStr )
1227+ log .G (ctx ).Infof ("Installing new component \" %s\" " , component .Name )
12221228 err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType , "" , "" )
12231229 if err != nil {
12241230 err = fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
12251231 break
12261232 }
12271233 }
12281234
1229- handleCliStep (reporter .UpgradeStepCreateApps , "Creating apps" , err , false )
1235+ handleCliStep (reporter .UpgradeStepInstallNewComponents , "Install new components" , err , false )
1236+
1237+ log .G (ctx ).Infof ("Runtime upgraded to version: v%s" , newRt .Spec .Version )
12301238
12311239 return nil
12321240}
0 commit comments