Skip to content

Commit 5e03cf8

Browse files
CR-12478 adjust uninstall to managed (#443)
* adjust to managed * moved isc removal to earlier stage * wip * removed some unnessecery lines * added type (hybrid/hosted) to runtime list * small change * make --repo and --git token required for hybrid runtimes only * wip * some logs * block ugrade for hosted runtimes * block upgarde for hosted * CommandFlow type * upgrade fix * bump go-sdk * log fix * bump version * remove unused getIscRepo * bump go-sdk * bump version * Update cmd/commands/common.go Co-authored-by: roi-codefresh <roi.kramer@codefresh.io> * Update cmd/commands/common.go Co-authored-by: roi-codefresh <roi.kramer@codefresh.io> * fix runtime list * bump app-proxy * small fix * allowManaged Co-authored-by: roi-codefresh <roi.kramer@codefresh.io>
1 parent 4fb32b0 commit 5e03cf8

File tree

11 files changed

+145
-125
lines changed

11 files changed

+145
-125
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.400
1+
VERSION=v0.0.401
22

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

cmd/commands/cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func newClusterAddCommand() *cobra.Command {
9292

9393
ctx := cmd.Context()
9494

95-
opts.runtimeName, err = ensureRuntimeName(ctx, args)
95+
opts.runtimeName, err = ensureRuntimeName(ctx, args, true)
9696
if err != nil {
9797
return err
9898
}
@@ -238,7 +238,7 @@ func newClusterRemoveCommand() *cobra.Command {
238238

239239
ctx := cmd.Context()
240240

241-
opts.runtimeName, err = ensureRuntimeName(ctx, args)
241+
opts.runtimeName, err = ensureRuntimeName(ctx, args, true)
242242
if err != nil {
243243
return err
244244
}
@@ -380,7 +380,7 @@ func newClusterCreateArgoRolloutsCommand() *cobra.Command {
380380
PreRunE: func(cmd *cobra.Command, args []string) error {
381381
var err error
382382

383-
opts.runtimeName, err = ensureRuntimeName(cmd.Context(), args)
383+
opts.runtimeName, err = ensureRuntimeName(cmd.Context(), args, true)
384384
return err
385385
},
386386
RunE: func(cmd *cobra.Command, _ []string) error {

cmd/commands/common.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *git.CloneOpti
141141
}
142142

143143
if cloneOpts.Repo == "" {
144-
return fmt.Errorf("must enter a valid installation repository URL")
144+
return fmt.Errorf("must enter a valid installation repository URL, using --repo")
145145
}
146146

147147
return nil
@@ -166,7 +166,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
166166
return cmd.Flags().Set("repo", repoInput)
167167
}
168168

169-
func ensureRuntimeName(ctx context.Context, args []string) (string, error) {
169+
func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (string, error) {
170170
var (
171171
runtimeName string
172172
err error
@@ -177,7 +177,7 @@ func ensureRuntimeName(ctx context.Context, args []string) (string, error) {
177177
}
178178

179179
if !store.Get().Silent {
180-
runtimeName, err = getRuntimeNameFromUserSelect(ctx)
180+
runtimeName, err = getRuntimeNameFromUserSelect(ctx, allowManaged)
181181
if err != nil {
182182
return "", err
183183
}
@@ -190,7 +190,7 @@ func ensureRuntimeName(ctx context.Context, args []string) (string, error) {
190190
return runtimeName, nil
191191
}
192192

193-
func getRuntimeNameFromUserSelect(ctx context.Context) (string, error) {
193+
func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (string, error) {
194194
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
195195
if err != nil {
196196
return "", err
@@ -200,10 +200,18 @@ func getRuntimeNameFromUserSelect(ctx context.Context) (string, error) {
200200
return "", fmt.Errorf("no runtimes were found")
201201
}
202202

203-
runtimeNames := make([]string, len(runtimes))
203+
var runtimeNames []string
204204

205-
for index, rt := range runtimes {
206-
runtimeNames[index] = rt.Metadata.Name
205+
for _, rt := range runtimes {
206+
rtDisplay := rt.Metadata.Name
207+
if rt.Managed {
208+
if !allowManaged {
209+
// preventing hosted runtimes to prompt
210+
continue
211+
}
212+
rtDisplay = fmt.Sprintf("%s (hosted)", rtDisplay)
213+
}
214+
runtimeNames = append(runtimeNames, rtDisplay)
207215
}
208216

209217
templates := &promptui.SelectTemplates{
@@ -219,7 +227,8 @@ func getRuntimeNameFromUserSelect(ctx context.Context) (string, error) {
219227
}
220228

221229
_, result, err := prompt.Run()
222-
return result, err
230+
resultSplit := strings.Split(result, " ")
231+
return resultSplit[0], err
223232
}
224233

225234
func getRuntimeNameFromUserInput() (string, error) {
@@ -301,6 +310,11 @@ func ensureGitToken(cmd *cobra.Command, cloneOpts *git.CloneOptions, verify bool
301310
return fmt.Errorf(errMessage)
302311
}
303312
}
313+
314+
if cloneOpts.Auth.Password == "" {
315+
return fmt.Errorf("must provide a git token using --git-token")
316+
}
317+
304318
return nil
305319
}
306320

@@ -635,11 +649,11 @@ func setIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (string,
635649
return setIscRepoResponse, nil
636650
}
637651

638-
func getIscRepo(ctx context.Context) (string, error) {
639-
user, err := cfConfig.NewClient().V2().UsersV2().GetCurrent(ctx)
652+
func isRuntimeManaged(ctx context.Context, runtimeName string) (bool, error) {
653+
rt, err := cfConfig.NewClient().V2().Runtime().Get(ctx, runtimeName)
640654
if err != nil {
641-
return "", fmt.Errorf("failed to get shared config repo. Error: %w", err)
655+
return false, fmt.Errorf("failed to get runtime from platform. error: %w", err)
642656
}
643657

644-
return *user.ActiveAccount.SharedConfigRepo, nil
658+
return rt.Managed, nil
645659
}

cmd/commands/integrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func RunGitIntegrationRemoveCommand(ctx context.Context, client sdk.AppProxyAPI,
305305
return fmt.Errorf("failed to remove git integration: %w", err)
306306
}
307307

308-
log.G(ctx).Infof("removed git integration: %s", name)
308+
log.G(ctx).Infof("Removed git integration: %s", name)
309309

310310
return nil
311311
}

0 commit comments

Comments
 (0)