Skip to content

Commit cbf0865

Browse files
runtime upgrade fix (#234)
1 parent 3912d7f commit cbf0865

File tree

6 files changed

+48
-39
lines changed

6 files changed

+48
-39
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.214
1+
VERSION=v0.0.216
22

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

cmd/commands/runtime.go

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

10911093
func 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

11731172
func 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
}

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.214/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.216/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.214/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.216/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.214
8+
version: 0.0.216
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ const (
118118
UpgradeStepRunPreCheckEnsureCliVersion CliStep = "upgrade.run.step.ensure-cli-version"
119119
UpgradeStepGetRepo CliStep = "upgrade.run.step.get-repo"
120120
UpgradeStepLoadRuntimeDefinition CliStep = "upgrade.run.step.load-runtime-definition"
121+
UpgradeStepCompareRuntimeVersions CliStep = "upgrade.run.step.compare-runtime-versions"
121122
UpgradeStepUpgradeRuntime CliStep = "upgrade.run.step.upgrade-runtime"
122123
UpgradeStepPushRuntimeDefinition CliStep = "upgrade.run.step.push-runtime-definition"
123-
UpgradeStepCreateApps CliStep = "upgrade.run.step.create-apps"
124+
UpgradeStepInstallNewComponents CliStep = "upgrade.run.step.install-new-components"
124125
UpgradePhaseFinish CliStep = "upgrade.run.phase.finish"
125126

126127
// General

pkg/runtime/runtime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ func Download(version *semver.Version, name string) (*Runtime, error) {
124124
func Load(fs fs.FS, filename string) (*Runtime, error) {
125125
cm := &v1.ConfigMap{}
126126
if err := fs.ReadYamls(filename, cm); err != nil {
127-
return nil, fmt.Errorf("failed to load runtime from '%s': %w", filename, err)
127+
return nil, fmt.Errorf("failed to load runtime from \"%s\": %w", filename, err)
128128
}
129129

130130
data := cm.Data["runtime"]
131131
runtime := &Runtime{}
132132
if err := yaml.Unmarshal([]byte(data), runtime); err != nil {
133-
return nil, fmt.Errorf("failed to unmarshal runtime from '%s': %w", filename, err)
133+
return nil, fmt.Errorf("failed to unmarshal runtime from \"%s\": %w", filename, err)
134134
}
135135

136136
for i := range runtime.Spec.Components {
@@ -196,21 +196,21 @@ func (r *RuntimeSpec) upgrade(fs fs.FS, newRt *RuntimeSpec) ([]AppDef, error) {
196196
for _, newComponent := range newRt.Components {
197197
curComponent := r.component(newComponent.Name)
198198
if curComponent != nil {
199-
log.G().Infof("Upgrading '%s'", newComponent.Name)
199+
log.G().Infof("Upgrading \"%s\"", newComponent.Name)
200200
baseDir := fs.Join(apstore.Default.AppsDir, curComponent.Name, apstore.Default.BaseDir)
201201
if err := updateKustomization(fs, baseDir, curComponent.URL, newComponent.URL); err != nil {
202-
return nil, fmt.Errorf("failed to upgrade app '%s': %w", curComponent.Name, err)
202+
return nil, fmt.Errorf("failed to upgrade app \"%s\": %w", curComponent.Name, err)
203203
}
204204
} else {
205-
log.G().Debugf("marking '%s' to be created later", newComponent.Name)
205+
log.G().Debugf("marking \"%s\" to be created later", newComponent.Name)
206206
newComponents = append(newComponents, newComponent)
207207
}
208208
}
209209

210210
for _, curComponent := range r.Components {
211211
newComponent := newRt.component(curComponent.Name)
212212
if newComponent == nil {
213-
log.G().Infof("Deleting '%s'", curComponent.Name)
213+
log.G().Infof("Deleting \"%s\"", curComponent.Name)
214214
if err := curComponent.delete(fs); err != nil {
215215
return nil, fmt.Errorf("failed to delete app '%s': %w", curComponent.Name, err)
216216
}

0 commit comments

Comments
 (0)