Skip to content

Commit fdf5175

Browse files
authored
fix helm update (#624)
* fix helm update * fix buildFullURL
1 parent 1e8c67e commit fdf5175

File tree

5 files changed

+77
-31
lines changed

5 files changed

+77
-31
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.566
1+
VERSION=v0.0.567
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.566/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.567/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.566/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.567/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 2.1.1
8-
version: 0.0.566
9-
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
8+
version: 0.0.567
9+
bootstrapSpecifier: github.com/codefresh-io/cli-v2.git/manifests/argo-cd
1010
components:
1111
- name: events
1212
type: kustomize
13-
url: github.com/codefresh-io/cli-v2/manifests/argo-events
13+
url: github.com/codefresh-io/cli-v2.git/manifests/argo-events
1414
wait: true
1515
- name: rollouts
1616
type: kustomize
17-
url: github.com/codefresh-io/cli-v2/manifests/argo-rollouts
17+
url: github.com/codefresh-io/cli-v2.git/manifests/argo-rollouts
1818
- name: workflows
1919
type: kustomize
20-
url: github.com/codefresh-io/cli-v2/manifests/argo-workflows
20+
url: github.com/codefresh-io/cli-v2.git/manifests/argo-workflows
2121
- name: app-proxy
2222
type: kustomize
23-
url: github.com/codefresh-io/cli-v2/manifests/app-proxy
23+
url: github.com/codefresh-io/cli-v2.git/manifests/app-proxy
2424
syncWave: 9
2525
- name: internal-router
2626
type: kustomize
27-
url: github.com/codefresh-io/cli-v2/manifests/internal-router
27+
url: github.com/codefresh-io/cli-v2.git/manifests/internal-router
2828
syncWave: 10
2929
- name: sealed-secrets
3030
type: kustomize
31-
url: github.com/codefresh-io/cli-v2/manifests/sealed-secrets
31+
url: github.com/codefresh-io/cli-v2.git/manifests/sealed-secrets
3232
- name: codefresh-tunnel-client
3333
type: helm
34-
url: github.com/codefresh-io/codefresh-tunnel-charts/codefresh-tunnel-client?ref=0.1.8
34+
url: github.com/codefresh-io/codefresh-tunnel-charts.git/codefresh-tunnel-client?ref=0.1.8
3535
feature: ingressless

pkg/runtime/runtime.go

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

227222
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)
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

403409
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")
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+
443480
func (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

pkg/store/store.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/Masterminds/semver/v3"
23+
apaputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
2324
)
2425

2526
var s Store
@@ -157,6 +158,11 @@ func Get() *Store {
157158
return &s
158159
}
159160

161+
func (s *Store) DefaultRuntimeDefRepoURL() string {
162+
host, orgRepo, _, _, _, suffix, _ := apaputil.ParseGitUrl(s.RuntimeDefURL)
163+
return host + orgRepo + suffix
164+
}
165+
160166
func init() {
161167
s.AddClusterJobName = "csdp-add-cluster-job-"
162168
s.ArgoCDServerName = "argocd-server"

0 commit comments

Comments
 (0)