Skip to content

Commit 8363df3

Browse files
CR-9099 editable ingress host (#240)
* editable ingress host * docs update * bump * lint + added loadBalancer condition * skip cert validation for http host * bump * fixes
1 parent 35fdcd6 commit 8363df3

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

cmd/commands/common.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,24 @@ func getKubeContextNameFromUserSelect(cmd *cobra.Command, kubeContextName *strin
420420
return nil
421421
}
422422

423-
func getIngressHostFromCluster(ctx context.Context, opts *RuntimeInstallOptions) error {
423+
func getIngressHostFromUserInput(ctx context.Context, opts *RuntimeInstallOptions, foundIngressHost string) error {
424+
ingressHostPrompt := promptui.Prompt{
425+
Label: "Ingress host",
426+
Default: foundIngressHost,
427+
Pointer: promptui.PipeCursor,
428+
}
429+
430+
ingressHostInput, err := ingressHostPrompt.Run()
431+
if err != nil {
432+
return fmt.Errorf("Prompt error: %w", err)
433+
}
434+
435+
opts.IngressHost = ingressHostInput
436+
437+
return nil
438+
}
439+
440+
func setIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
424441
log.G(ctx).Info("Retrieving ingress controller info from your cluster...\n")
425442

426443
cs := opts.KubeFactory.KubernetesClientSetOrDie()
@@ -429,27 +446,46 @@ func getIngressHostFromCluster(ctx context.Context, opts *RuntimeInstallOptions)
429446
return fmt.Errorf("failed to get ingress controller info from your cluster: %w", err)
430447
}
431448

449+
var foundIngressHost string
450+
432451
for _, s := range ServicesList.Items {
433-
if s.ObjectMeta.Name == opts.IngressController {
452+
if s.ObjectMeta.Name == opts.IngressController && s.Spec.Type == "LoadBalancer" {
434453
ingress := s.Status.LoadBalancer.Ingress[0]
435454
if ingress.Hostname != "" {
436-
opts.IngressHost = fmt.Sprintf("https://%s", ingress.Hostname)
455+
foundIngressHost = fmt.Sprintf("https://%s", ingress.Hostname)
456+
break
437457
} else {
438-
opts.IngressHost = fmt.Sprintf("https://%s", ingress.IP)
458+
foundIngressHost = fmt.Sprintf("https://%s", ingress.IP)
459+
break
439460
}
440-
break
461+
}
462+
}
463+
464+
if store.Get().Silent {
465+
log.G(ctx).Warnf("Using ingress host %s", foundIngressHost)
466+
opts.IngressHost = foundIngressHost
467+
} else {
468+
err = getIngressHostFromUserInput(ctx, opts, foundIngressHost)
469+
if err != nil {
470+
return err
441471
}
442472
}
443473

444474
if opts.IngressController == "" {
445-
return fmt.Errorf("failed to fetch ingress host from the cluster. please make sure you have a nginx ingress controller installed properly")
475+
return fmt.Errorf("please provide an ingress host via --ingress-host or installation wizard")
446476
}
447477

448478
return nil
449479
}
450480

451481
func checkIngressHostCertificate(ctx context.Context, ingress string) (bool, error) {
452-
var err error
482+
match, err := regexp.MatchString("http:", ingress)
483+
if err != nil {
484+
return false, err
485+
}
486+
if match {
487+
return true, nil
488+
}
453489

454490
res, err := http.Get(ingress)
455491

cmd/commands/runtime.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ func NewRuntimeInstallCommand() *cobra.Command {
232232
installationOpts.KubeFactory = kube.AddFlags(cmd.Flags())
233233

234234
util.Die(cmd.Flags().MarkHidden("bypass-ingress-class-check"))
235-
util.Die(cmd.Flags().MarkHidden("ingress-host"))
236235

237236
return cmd
238237
}
@@ -273,7 +272,7 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
273272
err = ensureIngressClass(cmd.Context(), opts)
274273
handleCliStep(reporter.InstallStepPreCheckEnsureIngressClass, "Getting ingress class", err, false)
275274
if err != nil {
276-
return util.DecorateErrorWithDocsLink(err, store.Get().RequirementsLink)
275+
return err
277276
}
278277

279278
err = ensureIngressHost(cmd, opts)
@@ -393,12 +392,10 @@ func runtimeUpgradeCommandPreRunHandler(cmd *cobra.Command, args []string, opts
393392
}
394393

395394
func ensureIngressHost(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
396-
if opts.IngressHost != "" { // ingress host provided by hidden flag (for our tests)
397-
return nil
398-
}
399-
400-
if err := getIngressHostFromCluster(cmd.Context(), opts); err != nil {
401-
return err
395+
if opts.IngressHost == "" { // ingress host not provided by flag
396+
if err := setIngressHost(cmd.Context(), opts); err != nil {
397+
return err
398+
}
402399
}
403400

404401
log.G(cmd.Context()).Infof("Using ingress host: %s", opts.IngressHost)

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ cli-v2 runtime install [runtime_name] [flags]
3838
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
3939
-h, --help help for install
4040
--ingress-class string The ingress class name
41+
--ingress-host string The ingress host
4142
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
4243
-n, --namespace string If present, the namespace scope for this CLI request
4344
--provider string The git provider, one of: gitea|github|gitlab

0 commit comments

Comments
 (0)