@@ -110,11 +110,6 @@ func Download(runtimeDef, name string, featuresToInstall []InstallFeature) (*Run
110
110
)
111
111
112
112
if strings .HasPrefix (runtimeDef , "http" ) {
113
- // urlString := store.RuntimeDefURL
114
- // if version != nil {
115
- // urlString = strings.Replace(urlString, "/releases/latest/download", "/releases/download/v"+version.String(), 1)
116
- // }
117
-
118
113
res , err := http .Get (runtimeDef )
119
114
if err != nil {
120
115
return nil , fmt .Errorf ("failed to download runtime definition: %w" , err )
@@ -225,7 +220,7 @@ func (r *Runtime) Install(ctx context.Context, f apkube.Factory, cloneOpts *apgi
225
220
}
226
221
227
222
func (r * Runtime ) Upgrade (fs apfs.FS , newRt * Runtime , config * CommonConfig ) ([]AppDef , error ) {
228
- newComponents , err := r .Spec .upgrade (fs , & newRt .Spec )
223
+ newComponents , err := r .Spec .upgrade (fs , & newRt .Spec , r . Name )
229
224
if err != nil {
230
225
return nil , err
231
226
}
@@ -255,7 +250,7 @@ func (r *RuntimeSpec) install(ctx context.Context, f apkube.Factory, cloneOpts *
255
250
return nil
256
251
}
257
252
258
- func (r * RuntimeSpec ) upgrade (fs apfs.FS , newRt * RuntimeSpec ) ([]AppDef , error ) {
253
+ func (r * RuntimeSpec ) upgrade (fs apfs.FS , newRt * RuntimeSpec , runtimeName string ) ([]AppDef , error ) {
259
254
log .G ().Infof ("Upgrading bootstrap specifier" )
260
255
argocdDir := fs .Join (apstore .Default .BootsrtrapDir , apstore .Default .ArgoCDName )
261
256
if err := updateKustomization (fs , argocdDir , r .FullSpecifier (), newRt .FullSpecifier ()); err != nil {
@@ -274,9 +269,16 @@ func (r *RuntimeSpec) upgrade(fs apfs.FS, newRt *RuntimeSpec) ([]AppDef, error)
274
269
for _ , newComponent := range newRt .Components {
275
270
curComponent := r .component (newComponent .Name )
276
271
if curComponent != nil {
277
- log .G ().Infof ("Upgrading \" %s\" " , newComponent .Name )
278
- baseDir := fs .Join (apstore .Default .AppsDir , curComponent .Name , apstore .Default .BaseDir )
279
- if err := updateKustomization (fs , baseDir , curComponent .URL , newComponent .URL ); err != nil {
272
+ var err error
273
+ if curComponent .Type == "kustomize" {
274
+ err = curComponent .updateKustApp (fs , & newComponent )
275
+ } else if curComponent .Type == "helm" {
276
+ err = curComponent .updateHelmApp (fs , & newComponent , runtimeName )
277
+ } else {
278
+ err = fmt .Errorf ("unknown component type \" %s\" " , curComponent .Type )
279
+ }
280
+
281
+ if err != nil {
280
282
return nil , fmt .Errorf ("failed to upgrade app \" %s\" : %w" , curComponent .Name , err )
281
283
}
282
284
} else {
@@ -355,6 +357,10 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg
355
357
}
356
358
newCloneOpts .Parse ()
357
359
360
+ if a .Type == "kustomize" || a .Type == "dir" {
361
+ return a .createAppUsingAutopilot (ctx , f , newCloneOpts , runtimeName , cfType )
362
+ }
363
+
358
364
if a .Type == "helm" {
359
365
values := ""
360
366
if len (optionalValues ) > 0 {
@@ -363,7 +369,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg
363
369
return a .createHelmAppDirectly (ctx , newCloneOpts , runtimeName , cfType , values )
364
370
}
365
371
366
- return a . createAppUsingAutopilot ( ctx , f , newCloneOpts , runtimeName , cfType )
372
+ return fmt . Errorf ( "failed to create app \" %s \" , unknown type \" %s \" " , a . Name , a . Type )
367
373
},
368
374
})
369
375
}
@@ -401,12 +407,6 @@ func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory,
401
407
}
402
408
403
409
func (a * AppDef ) createHelmAppDirectly (ctx context.Context , cloneOpts * apgit.CloneOptions , runtimeName , cfType string , values string ) error {
404
- r , fs , err := cloneOpts .GetRepo (ctx )
405
- if err != nil {
406
- return fmt .Errorf ("failed getting repository while creating helm app: %w" , err )
407
- }
408
-
409
- helmAppPath := cloneOpts .FS .Join (apstore .Default .AppsDir , a .Name , runtimeName , "config_helm.json" )
410
410
host , orgRepo , path , gitRef , _ , suffix , _ := apaputil .ParseGitUrl (a .URL )
411
411
repoUrl := host + orgRepo + suffix
412
412
config := & HelmConfig {
@@ -428,6 +428,13 @@ func (a *AppDef) createHelmAppDirectly(ctx context.Context, cloneOpts *apgit.Clo
428
428
},
429
429
Values : values ,
430
430
}
431
+
432
+ r , fs , err := cloneOpts .GetRepo (ctx )
433
+ if err != nil {
434
+ return fmt .Errorf ("failed getting repository while creating helm app: %w" , err )
435
+ }
436
+
437
+ helmAppPath := fs .Join (apstore .Default .AppsDir , a .Name , runtimeName , "config_helm.json" )
431
438
err = fs .WriteJson (helmAppPath , config )
432
439
if err != nil {
433
440
return fmt .Errorf ("failed to write helm app config file: %w" , err )
@@ -437,9 +444,39 @@ func (a *AppDef) createHelmAppDirectly(ctx context.Context, cloneOpts *apgit.Clo
437
444
if fs .Root () != "" {
438
445
commitMsg += fmt .Sprintf (" installation-path: '%s'" , fs .Root ())
439
446
}
447
+
440
448
return aputil .PushWithMessage (ctx , r , commitMsg )
441
449
}
442
450
451
+ func (a * AppDef ) updateKustApp (fs apfs.FS , newComponent * AppDef ) error {
452
+ log .G ().Infof ("Upgrading \" %s\" " , a .Name )
453
+ baseDir := fs .Join (apstore .Default .AppsDir , a .Name , apstore .Default .BaseDir )
454
+ if err := updateKustomization (fs , baseDir , a .URL , newComponent .URL ); err != nil {
455
+ return err
456
+ }
457
+
458
+ return nil
459
+ }
460
+
461
+ func (a * AppDef ) updateHelmApp (fs apfs.FS , newComponent * AppDef , runtimeName string ) error {
462
+ log .G ().Infof ("Upgrading \" %s\" " , a .Name )
463
+ helmAppPath := fs .Join (apstore .Default .AppsDir , a .Name , runtimeName , "config_helm.json" )
464
+ var config HelmConfig
465
+ err := fs .ReadJson (helmAppPath , & config )
466
+ if err != nil {
467
+ return err
468
+ }
469
+
470
+ host , orgRepo , path , gitRef , _ , suffix , _ := apaputil .ParseGitUrl (newComponent .URL )
471
+ repoUrl := host + orgRepo + suffix
472
+ config .SrcRepoURL = repoUrl
473
+ config .SrcPath = path
474
+ config .SrcTargetRevision = gitRef
475
+ config .Labels [util .EscapeAppsetFieldName (store .Get ().LabelKeyCFInternal )] = strconv .FormatBool (newComponent .IsInternal )
476
+ config .Annotations [util .EscapeAppsetFieldName (store .Get ().AnnotationKeySyncWave )] = strconv .Itoa (newComponent .SyncWave )
477
+ return fs .WriteJson (helmAppPath , config )
478
+ }
479
+
443
480
func (a * AppDef ) delete (fs apfs.FS ) error {
444
481
return billyUtils .RemoveAll (fs , fs .Join (apstore .Default .AppsDir , a .Name ))
445
482
}
@@ -462,14 +499,17 @@ func buildFullURL(urlString, ref string) string {
462
499
return urlString
463
500
}
464
501
465
- if urlString != store .Get ().RuntimeDefURL {
502
+ host , orgRepo , _ , _ , _ , suffix , _ := apaputil .ParseGitUrl (urlString )
503
+ repoUrl := host + orgRepo + suffix
504
+ if repoUrl != store .Get ().DefaultRuntimeDefRepoURL () {
505
+ // if the url is not from codefresh-io/cli-v2 - don't change it
466
506
return urlString
467
507
}
468
508
469
509
urlObj , _ := url .Parse (urlString )
470
510
v := urlObj .Query ()
471
511
if v .Get ("ref" ) == "" {
472
- v .Add ("ref" , "v" + ref )
512
+ v .Add ("ref" , "v" + ref )
473
513
urlObj .RawQuery = v .Encode ()
474
514
}
475
515
0 commit comments