@@ -357,20 +357,22 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
357
357
return nil
358
358
}
359
359
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 {
361
361
handleCliStep (reporter .UpgradePhasePreCheckStart , "Starting pre checks" , nil , false )
362
362
363
- err := ensureRuntimeName (cmd .Context (), args , & runtimeName )
363
+ err := ensureRuntimeName (cmd .Context (), args , & opts . RuntimeName )
364
364
handleCliStep (reporter .UpgradeStepPreCheckEnsureRuntimeName , "Ensuring runtime name" , err , false )
365
365
if err != nil {
366
366
return fmt .Errorf ("%w" , err )
367
367
}
368
- err = ensureRepo (cmd , runtimeName , cloneOpts , true )
368
+
369
+ err = ensureRepo (cmd , opts .RuntimeName , opts .CloneOpts , true )
369
370
handleCliStep (reporter .UpgradeStepPreCheckEnsureRuntimeRepo , "Getting runtime repo" , err , false )
370
371
if err != nil {
371
372
return fmt .Errorf ("%w" , err )
372
373
}
373
- err = ensureGitToken (cmd , cloneOpts )
374
+
375
+ err = ensureGitToken (cmd , opts .CloneOpts )
374
376
handleCliStep (reporter .UpgradeStepPreCheckEnsureGitToken , "Getting git token" , err , false )
375
377
if err != nil {
376
378
return fmt .Errorf ("%w" , err )
@@ -1090,10 +1092,9 @@ func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOption
1090
1092
1091
1093
func NewRuntimeUpgradeCommand () * cobra.Command {
1092
1094
var (
1093
- runtimeName string
1094
1095
versionStr string
1095
- cloneOpts * git.CloneOptions
1096
1096
finalParameters map [string ]string
1097
+ opts RuntimeUpgradeOptions
1097
1098
)
1098
1099
1099
1100
cmd := & cobra.Command {
@@ -1118,61 +1119,60 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
1118
1119
1119
1120
createAnalyticsReporter (ctx , reporter .UpgradeFlow )
1120
1121
1121
- err := runtimeUpgradeCommandPreRunHandler (cmd , args , cloneOpts , runtimeName )
1122
+ err := runtimeUpgradeCommandPreRunHandler (cmd , args , & opts )
1122
1123
handleCliStep (reporter .UpgradePhasePreCheckFinish , "Finished pre installation checks" , err , false )
1123
1124
if err != nil {
1124
1125
return fmt .Errorf ("Pre installation error: %w" , err )
1125
1126
}
1126
1127
1127
1128
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
1130
1135
}
1131
1136
1132
1137
err = getApprovalFromUser (ctx , finalParameters , "runtime upgrade" )
1133
1138
if err != nil {
1134
1139
return fmt .Errorf ("%w" , err )
1135
1140
}
1136
1141
1137
- cloneOpts .Parse ()
1142
+ opts . CloneOpts .Parse ()
1138
1143
return nil
1139
1144
},
1140
1145
RunE : func (cmd * cobra.Command , args []string ) error {
1141
- var (
1142
- version * semver.Version
1143
- err error
1144
- )
1146
+ var err error
1145
1147
ctx := cmd .Context ()
1146
1148
1147
1149
if versionStr != "" {
1148
- version , err = semver .NewVersion (versionStr )
1150
+ opts . Version , err = semver .NewVersion (versionStr )
1149
1151
if err != nil {
1150
1152
return err
1151
1153
}
1152
1154
}
1153
1155
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 )
1162
1161
handleCliStep (reporter .UpgradePhaseFinish , "Runtime upgrade phase finished" , err , false )
1163
1162
return err
1164
1163
},
1165
1164
}
1166
1165
1167
1166
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 {})
1169
1168
1170
1169
return cmd
1171
1170
}
1172
1171
1173
1172
func RunRuntimeUpgrade (ctx context.Context , opts * RuntimeUpgradeOptions ) error {
1174
1173
handleCliStep (reporter .UpgradePhaseStart , "Runtime upgrade phase started" , nil , true )
1175
1174
1175
+ log .G (ctx ).Info ("Downloading runtime definition" )
1176
1176
newRt , err := runtime .Download (opts .Version , opts .RuntimeName )
1177
1177
handleCliStep (reporter .UpgradeStepDownloadRuntimeDefinition , "Downloading runtime definition" , err , false )
1178
1178
if err != nil {
@@ -1187,22 +1187,29 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
1187
1187
return err
1188
1188
}
1189
1189
1190
+ log .G (ctx ).Info ("Cloning installation repository" )
1190
1191
r , fs , err := opts .CloneOpts .GetRepo (ctx )
1191
1192
handleCliStep (reporter .UpgradeStepGetRepo , "Getting repository" , err , false )
1192
1193
if err != nil {
1193
1194
return err
1194
1195
}
1195
1196
1197
+ log .G (ctx ).Info ("Loading current runtime definition" )
1196
1198
curRt , err := runtime .Load (fs , fs .Join (apstore .Default .BootsrtrapDir , opts .RuntimeName + ".yaml" ))
1197
1199
handleCliStep (reporter .UpgradeStepLoadRuntimeDefinition , "Loading runtime definition" , err , false )
1198
1200
if err != nil {
1199
1201
return fmt .Errorf ("failed to load current runtime definition: %w" , err )
1200
1202
}
1201
1203
1202
1204
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
1204
1210
}
1205
1211
1212
+ log .G (ctx ).Infof ("Upgrading runtime \" %s\" to version: v%s" , opts .RuntimeName , newRt .Spec .Version )
1206
1213
newComponents , err := curRt .Upgrade (fs , newRt , opts .CommonConfig )
1207
1214
handleCliStep (reporter .UpgradeStepUpgradeRuntime , "Upgrading runtime" , err , false )
1208
1215
if err != nil {
@@ -1217,16 +1224,17 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
1217
1224
}
1218
1225
1219
1226
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 )
1222
1228
err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType , "" , "" )
1223
1229
if err != nil {
1224
1230
err = fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
1225
1231
break
1226
1232
}
1227
1233
}
1228
1234
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 )
1230
1238
1231
1239
return nil
1232
1240
}
0 commit comments