Skip to content

Commit 6b13fe5

Browse files
handle upgrade (#573)
* handle upgrade * fixed component filtering * updated version to 0.0.518 * Update pkg/runtime/runtime.go Co-authored-by: roi-codefresh <roi.kramer@codefresh.io> * fixed pr comments * added comment to code Co-authored-by: roi-codefresh <roi.kramer@codefresh.io>
1 parent 8e8c55e commit 6b13fe5

File tree

13 files changed

+129
-90
lines changed

13 files changed

+129
-90
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.517
1+
VERSION=v0.0.518
22

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

cmd/commands/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func newClusterAddCommand() *cobra.Command {
149149
}
150150

151151
func runClusterAdd(ctx context.Context, opts *ClusterAddOptions) error {
152-
runtime, err := cfConfig.NewClient().V2().Runtime().Get(ctx, opts.runtimeName)
152+
runtime, err := getRuntime(ctx, opts.runtimeName)
153153
if err != nil {
154154
return err
155155
}

cmd/commands/common.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/codefresh-io/cli-v2/pkg/store"
3434
"github.com/codefresh-io/cli-v2/pkg/util"
3535

36+
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
3637
apgit "github.com/argoproj-labs/argocd-autopilot/pkg/git"
3738
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
3839
"github.com/manifoldco/promptui"
@@ -124,13 +125,13 @@ func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *apgit.CloneOp
124125
}
125126

126127
if fromAPI {
127-
runtimeData, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
128+
runtime, err := getRuntime(ctx, runtimeName)
128129
if err != nil {
129130
return fmt.Errorf("failed getting runtime repo information: %w", err)
130131
}
131132

132-
if runtimeData.Repo != nil {
133-
die(cmd.Flags().Set("repo", *runtimeData.Repo))
133+
if runtime.Repo != nil {
134+
die(cmd.Flags().Set("repo", *runtime.Repo))
134135
return nil
135136
}
136137
}
@@ -646,18 +647,18 @@ func suggestIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (stri
646647
}
647648

648649
func isRuntimeManaged(ctx context.Context, runtimeName string) (bool, error) {
649-
rt, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
650+
rt, err := getRuntime(ctx, runtimeName)
650651
if err != nil {
651-
return false, fmt.Errorf("failed to get runtime from platform. error: %w", err)
652+
return false, err
652653
}
653654

654655
return rt.Managed, nil
655656
}
656657

657658
func ensureRuntimeOnKubeContext(ctx context.Context, kubeconfig string, runtimeName string, kubeContextName string) error {
658-
rt, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
659+
rt, err := getRuntime(ctx, runtimeName)
659660
if err != nil {
660-
return fmt.Errorf("failed to get runtime from platform. error: %w", err)
661+
return err
661662
}
662663

663664
runtimeClusterServer := rt.Cluster
@@ -679,3 +680,12 @@ func ensureRuntimeOnKubeContext(ctx context.Context, kubeconfig string, runtimeN
679680

680681
return nil
681682
}
683+
684+
func getRuntime(ctx context.Context, runtimeName string) (*platmodel.Runtime, error) {
685+
rt, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
686+
if err != nil {
687+
return nil, fmt.Errorf("failed to get runtime from platform. error: %w", err)
688+
}
689+
690+
return rt, nil
691+
}

cmd/commands/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func NewConfigSetRuntimeCommand() *cobra.Command {
167167
}
168168

169169
func RunConfigSetRuntime(ctx context.Context, runtime string) error {
170-
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtime)
170+
_, err := getRuntime(ctx, runtime)
171171
if err != nil {
172172
return err
173173
}

cmd/commands/git-source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ func deleteCommonRedundantFields(crd map[string]interface{}) {
15081508
}
15091509

15101510
func getRuntimeVersion(ctx context.Context, runtimeName string) (*semver.Version, error) {
1511-
rt, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
1511+
rt, err := getRuntime(ctx, runtimeName)
15121512
if err != nil {
15131513
return nil, err
15141514
}

cmd/commands/integrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func RunGitAuthCommand(ctx context.Context, cmd *cobra.Command) error {
456456
}
457457

458458
runtimeName := cmd.Flag("runtime").Value.String()
459-
runtime, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
459+
runtime, err := getRuntime(ctx, runtimeName)
460460
if err != nil {
461461
return err
462462
}

cmd/commands/runtime.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
appset "github.com/argoproj/applicationset/api/v1alpha1"
4444
argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
4545
argocdv1alpha1cs "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
46-
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
46+
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
4747
"github.com/juju/ansiterm"
4848
"github.com/manifoldco/promptui"
4949
"github.com/rkrmr33/checklist"
@@ -74,6 +74,8 @@ type (
7474
CommonConfig *runtime.CommonConfig
7575
SuggestedSharedConfigRepo string
7676
DisableTelemetry bool
77+
78+
featuresToInstall []runtime.InstallFeature
7779
}
7880

7981
gvr struct {
@@ -150,6 +152,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
150152
if !opts.Managed {
151153
opts.kubeContext, err = getKubeContextName(cmd.Flag("context"), cmd.Flag("kubeconfig"))
152154
}
155+
153156
handleCliStep(reporter.UninstallStepPreCheckGetKubeContext, "Getting kube context name", err, true, false)
154157
if err != nil {
155158
return err
@@ -165,6 +168,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
165168
opts.skipAutopilotUninstall = true // will not touch the cluster and repo
166169
}
167170
}
171+
168172
handleCliStep(reporter.UninstallStepPreCheckEnsureRuntimeOnKubeContext, "Ensuring runtime is on the kube context", err, true, false)
169173
if err != nil {
170174
return err
@@ -181,6 +185,7 @@ func runtimeUninstallCommandPreRunHandler(cmd *cobra.Command, args []string, opt
181185
if !opts.Managed {
182186
err = ensureGitRuntimeToken(cmd, nil, opts.CloneOpts)
183187
}
188+
184189
handleCliStep(reporter.UninstallStepPreCheckEnsureGitToken, "Getting git token", err, true, false)
185190
if err != nil {
186191
return err
@@ -201,16 +206,20 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts
201206
return err
202207
}
203208

204-
isManaged, err := isRuntimeManaged(ctx, opts.RuntimeName)
209+
rt, err := getRuntime(ctx, opts.RuntimeName)
205210
handleCliStep(reporter.UpgradeStepPreCheckIsManagedRuntime, "Checking if runtime is hosted", err, true, false)
206211
if err != nil {
207212
return err
208213
}
209214

210-
if isManaged {
215+
if rt.Managed {
211216
return fmt.Errorf("manual upgrades are not allowed for hosted runtimes and are managed by Codefresh operational team")
212217
}
213218

219+
if rt.AccessMode == platmodel.AccessModeTunnel {
220+
opts.featuresToInstall = append(opts.featuresToInstall, runtime.InstallFeatureIngressless)
221+
}
222+
214223
err = ensureRepo(cmd, opts.RuntimeName, opts.CloneOpts, true)
215224
handleCliStep(reporter.UpgradeStepPreCheckEnsureRuntimeRepo, "Getting runtime repo", err, true, false)
216225
if err != nil {
@@ -258,7 +267,7 @@ func removeGitIntegrations(ctx context.Context, opts *RuntimeUninstallOptions) e
258267
return nil
259268
}
260269

261-
func getComponentChecklistState(c model.Component) (checklist.ListItemState, checklist.ListItemInfo) {
270+
func getComponentChecklistState(c platmodel.Component) (checklist.ListItemState, checklist.ListItemInfo) {
262271
state := checklist.Waiting
263272
name := strings.TrimPrefix(c.Metadata.Name, fmt.Sprintf("%s-", c.Metadata.Runtime))
264273
version := "N/A"
@@ -280,16 +289,16 @@ func getComponentChecklistState(c model.Component) (checklist.ListItemState, che
280289
if len(c.Self.Errors) > 0 {
281290
// use the first sync error due to lack of space
282291
for _, err := range c.Self.Errors {
283-
se, ok := err.(model.SyncError)
284-
if ok && se.Level == model.ErrorLevelsError {
292+
se, ok := err.(platmodel.SyncError)
293+
if ok && se.Level == platmodel.ErrorLevelsError {
285294
errs = se.Message
286295
state = checklist.Error
287296
}
288297
}
289298
}
290299
}
291300

292-
if healthStatus == string(model.HealthStatusHealthy) && syncStatus == string(model.SyncStatusSynced) {
301+
if healthStatus == string(platmodel.HealthStatusHealthy) && syncStatus == string(platmodel.SyncStatusSynced) {
293302
state = checklist.Ready
294303
}
295304

@@ -488,7 +497,7 @@ func runRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
488497
// check whether the runtime exists
489498
var err error
490499
if !opts.SkipChecks {
491-
_, err = cfConfig.NewClient().V2().Runtime().Get(ctx, opts.RuntimeName)
500+
_, err = getRuntime(ctx, opts.RuntimeName)
492501
}
493502
handleCliStep(reporter.UninstallStepCheckRuntimeExists, "Checking if runtime exists", err, false, true)
494503
if err != nil {
@@ -730,7 +739,9 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
730739
var (
731740
versionStr string
732741
finalParameters map[string]string
733-
opts RuntimeUpgradeOptions
742+
opts = &RuntimeUpgradeOptions{
743+
featuresToInstall: make([]runtime.InstallFeature, 0),
744+
}
734745
)
735746

736747
cmd := &cobra.Command{
@@ -756,7 +767,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
756767

757768
createAnalyticsReporter(ctx, reporter.UpgradeFlow, opts.DisableTelemetry)
758769

759-
err := runtimeUpgradeCommandPreRunHandler(cmd, args, &opts)
770+
err := runtimeUpgradeCommandPreRunHandler(cmd, args, opts)
760771
handleCliStep(reporter.UpgradePhasePreCheckFinish, "Finished pre run checks", err, true, false)
761772
if err != nil {
762773
if errors.Is(err, promptui.ErrInterrupt) {
@@ -798,7 +809,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
798809
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
799810
}
800811

801-
err = runRuntimeUpgrade(ctx, &opts)
812+
err = runRuntimeUpgrade(ctx, opts)
802813
handleCliStep(reporter.UpgradePhaseFinish, "Runtime upgrade phase finished", err, false, false)
803814
return err
804815
},
@@ -817,7 +828,8 @@ func runRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
817828
handleCliStep(reporter.UpgradePhaseStart, "Runtime upgrade phase started", nil, false, true)
818829

819830
log.G(ctx).Info("Downloading runtime definition")
820-
newRt, err := runtime.Download(opts.Version, opts.RuntimeName)
831+
832+
newRt, err := runtime.Download(opts.Version, opts.RuntimeName, opts.featuresToInstall)
821833
handleCliStep(reporter.UpgradeStepDownloadRuntimeDefinition, "Downloading runtime definition", err, true, false)
822834
if err != nil {
823835
return fmt.Errorf("failed to download runtime definition: %w", err)

0 commit comments

Comments
 (0)