Skip to content

Commit 9a1439c

Browse files
Cr 13685 fix ingress host check (#524)
fixing invereted --skip-cluster-checks flag and bad ingress host validation
1 parent 67ac22f commit 9a1439c

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
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.468
1+
VERSION=v0.0.469
22

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

cmd/commands/common.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var (
5959
COLOR_RESET = "\033[0m"
6060
UNDERLINE_RESET = "\033[24m"
6161
BOLD_RESET = "\033[22m"
62+
63+
errUserCanceledInsecureInstall = fmt.Errorf("cancelled installation due to invalid ingress host certificate")
6264
)
6365

6466
func postInitCommands(commands []*cobra.Command) {
@@ -473,12 +475,12 @@ func setIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
473475
log.G(ctx).Info("Retrieving ingress controller info from your cluster...\n")
474476

475477
cs := opts.KubeFactory.KubernetesClientSetOrDie()
476-
ServicesList, err := cs.CoreV1().Services("").List(ctx, metav1.ListOptions{})
478+
servicesList, err := cs.CoreV1().Services("").List(ctx, metav1.ListOptions{})
477479
if err != nil {
478480
return fmt.Errorf("failed to get ingress controller info from your cluster: %w", err)
479481
}
480482

481-
for _, s := range ServicesList.Items {
483+
for _, s := range servicesList.Items {
482484
if s.ObjectMeta.Name == opts.IngressController.Name() && s.Spec.Type == "LoadBalancer" {
483485
if len(s.Status.LoadBalancer.Ingress) > 0 {
484486
ingress := s.Status.LoadBalancer.Ingress[0]
@@ -498,25 +500,15 @@ func setIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
498500
}
499501

500502
if store.Get().Silent {
503+
if foundIngressHost == "" {
504+
return fmt.Errorf("please provide an ingress host via --ingress-host or installation wizard")
505+
}
501506
opts.IngressHost = foundIngressHost
502507
} else {
503508
opts.IngressHost, err = getIngressHostFromUserInput(foundIngressHost)
504-
if err != nil {
505-
return err
506-
}
507-
response, err := http.Get(opts.IngressHost)
508-
if err != nil {
509-
opts.IngressHost = ""
510-
return err
511-
}
512-
response.Body.Close()
513-
}
514-
515-
if opts.IngressHost == "" {
516-
return fmt.Errorf("please provide an ingress host via --ingress-host or installation wizard")
517509
}
518510

519-
return nil
511+
return err
520512
}
521513

522514
func getIngressHostFromUserInput(foundIngressHost string) (string, error) {
@@ -616,7 +608,7 @@ func askUserIfToProceedWithInsecure(ctx context.Context) error {
616608
if result == "Yes" {
617609
store.Get().InsecureIngressHost = true
618610
} else {
619-
return fmt.Errorf("cancelled installation due to invalid ingress host certificate")
611+
return errUserCanceledInsecureInstall
620612
}
621613

622614
return nil
@@ -635,7 +627,9 @@ func handleValidationFailsWithRepeat(callback Callback) {
635627
}
636628

637629
func isValidationError(err error) bool {
638-
return err != nil && err != promptui.ErrInterrupt
630+
return err != nil &&
631+
err != promptui.ErrInterrupt &&
632+
err != errUserCanceledInsecureInstall
639633
}
640634

641635
func getIscRepo(ctx context.Context) (string, error) {

cmd/commands/runtime_install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func getIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
358358
handleValidationFailsWithRepeat(func() error {
359359
err = ensureIngressHost(ctx, opts)
360360
if isValidationError(err) {
361-
fmt.Println("Could not resolve the URL for ingress host; enter a valid URL")
361+
fmt.Fprintf(os.Stderr, "Ingress host validation failed: %s; enter a valid URL\n", err.Error())
362362
return err
363363
}
364364
return nil
@@ -404,7 +404,7 @@ func ensureIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
404404

405405
log.G(ctx).Infof("Using ingress host: %s", opts.IngressHost)
406406

407-
if !opts.SkipClusterChecks {
407+
if opts.SkipClusterChecks {
408408
return nil
409409
}
410410

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.468/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.469/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.468/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.469/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.1
8-
version: 0.0.468
8+
version: 0.0.469
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)