@@ -110,11 +110,6 @@ func Download(runtimeDef, name string, featuresToInstall []InstallFeature) (*Run
110110 )
111111
112112 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-
118113 res , err := http .Get (runtimeDef )
119114 if err != nil {
120115 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
225220}
226221
227222func (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 )
229224 if err != nil {
230225 return nil , err
231226 }
@@ -255,7 +250,7 @@ func (r *RuntimeSpec) install(ctx context.Context, f apkube.Factory, cloneOpts *
255250 return nil
256251}
257252
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 ) {
259254 log .G ().Infof ("Upgrading bootstrap specifier" )
260255 argocdDir := fs .Join (apstore .Default .BootsrtrapDir , apstore .Default .ArgoCDName )
261256 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)
274269 for _ , newComponent := range newRt .Components {
275270 curComponent := r .component (newComponent .Name )
276271 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 {
280282 return nil , fmt .Errorf ("failed to upgrade app \" %s\" : %w" , curComponent .Name , err )
281283 }
282284 } else {
@@ -355,6 +357,10 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg
355357 }
356358 newCloneOpts .Parse ()
357359
360+ if a .Type == "kustomize" || a .Type == "dir" {
361+ return a .createAppUsingAutopilot (ctx , f , newCloneOpts , runtimeName , cfType )
362+ }
363+
358364 if a .Type == "helm" {
359365 values := ""
360366 if len (optionalValues ) > 0 {
@@ -363,7 +369,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f apkube.Factory, cloneOpts *apg
363369 return a .createHelmAppDirectly (ctx , newCloneOpts , runtimeName , cfType , values )
364370 }
365371
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 )
367373 },
368374 })
369375}
@@ -401,12 +407,6 @@ func (a *AppDef) createAppUsingAutopilot(ctx context.Context, f apkube.Factory,
401407}
402408
403409func (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" )
410410 host , orgRepo , path , gitRef , _ , suffix , _ := apaputil .ParseGitUrl (a .URL )
411411 repoUrl := host + orgRepo + suffix
412412 config := & HelmConfig {
@@ -428,6 +428,13 @@ func (a *AppDef) createHelmAppDirectly(ctx context.Context, cloneOpts *apgit.Clo
428428 },
429429 Values : values ,
430430 }
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" )
431438 err = fs .WriteJson (helmAppPath , config )
432439 if err != nil {
433440 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
437444 if fs .Root () != "" {
438445 commitMsg += fmt .Sprintf (" installation-path: '%s'" , fs .Root ())
439446 }
447+
440448 return aputil .PushWithMessage (ctx , r , commitMsg )
441449}
442450
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+
443480func (a * AppDef ) delete (fs apfs.FS ) error {
444481 return billyUtils .RemoveAll (fs , fs .Join (apstore .Default .AppsDir , a .Name ))
445482}
@@ -462,14 +499,17 @@ func buildFullURL(urlString, ref string) string {
462499 return urlString
463500 }
464501
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
466506 return urlString
467507 }
468508
469509 urlObj , _ := url .Parse (urlString )
470510 v := urlObj .Query ()
471511 if v .Get ("ref" ) == "" {
472- v .Add ("ref" , "v" + ref )
512+ v .Add ("ref" , "v" + ref )
473513 urlObj .RawQuery = v .Encode ()
474514 }
475515
0 commit comments