Skip to content

Commit 4b0cfc3

Browse files
authored
CR-14744 - fix skip-ingress flag (#585)
* check SkipIngress flag when needed
1 parent 4179506 commit 4b0cfc3

File tree

8 files changed

+55
-45
lines changed

8 files changed

+55
-45
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* roi.kramer@codefresh.io noam.gal@codefresh.io oren.gurfinkel@codefresh.io pavel@codefresh.io ziv@codefresh.io
1+
* roi.kramer@codefresh.io noam.gal@codefresh.io oren.gurfinkel@codefresh.io pavel@codefresh.io ziv@codefresh.io itai@codefresh.io

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.531
1+
VERSION=v0.0.532
22

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

cmd/commands/git-source.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type (
6565
Exclude string
6666
Include string
6767
HostName string
68+
SkipIngress bool
6869
IngressHost string
6970
IngressClass string
7071
IngressController routingutil.RoutingController
@@ -104,6 +105,7 @@ type (
104105
gsFs fs.FS
105106
hostName string
106107
ingressHost string
108+
skipIngress bool
107109
ingressClass string
108110
ingressController routingutil.RoutingController
109111
accessMode platmodel.AccessMode
@@ -611,6 +613,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
611613
gitProvider: opts.GitProvider,
612614
gsFs: gsFs,
613615
hostName: opts.HostName,
616+
skipIngress: opts.SkipIngress,
614617
ingressHost: opts.IngressHost,
615618
ingressClass: opts.IngressClass,
616619
ingressController: opts.IngressController,
@@ -752,7 +755,7 @@ func createDemoCalendarTrigger() sensorsv1alpha1.Trigger {
752755
}
753756

754757
func createDemoGitPipeline(opts *gitSourceGitDemoPipelineOptions) error {
755-
if opts.accessMode == platmodel.AccessModeIngress {
758+
if !opts.skipIngress && opts.accessMode == platmodel.AccessModeIngress {
756759
// Create an ingress that will manage external access to the git eventsource service
757760
routeOpts := routingutil.CreateRouteOpts{
758761
RuntimeName: opts.runtimeName,

cmd/commands/runtime_install.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type (
110110
TunnelDomain string
111111
TunnelSubdomain string
112112
SkipIngress bool
113+
BypassIngressClassCheck bool
113114

114115
versionStr string
115116
kubeContext string
@@ -243,7 +244,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
243244
cmd.Flags().DurationVar(&store.Get().WaitTimeout, "wait-timeout", store.Get().WaitTimeout, "How long to wait for the runtime components to be ready")
244245
cmd.Flags().StringVar(&gitIntegrationApiURL, "provider-api-url", "", "Git provider API url")
245246
cmd.Flags().BoolVar(&installationOpts.SkipIngress, "skip-ingress", false, "Skips the creation of ingress resources")
246-
cmd.Flags().BoolVar(&store.Get().BypassIngressClassCheck, "bypass-ingress-class-check", false, "Disables the ingress class check during pre-installation")
247+
cmd.Flags().BoolVar(&installationOpts.BypassIngressClassCheck, "bypass-ingress-class-check", false, "Disables the ingress class check during pre-installation")
247248
cmd.Flags().BoolVar(&installationOpts.DisableTelemetry, "disable-telemetry", false, "If true, will disable the analytics reporting for the installation process")
248249
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
249250
cmd.Flags().BoolVar(&installationOpts.FromRepo, "from-repo", false, "Installs a runtime from an existing repo. Used for recovery after cluster failure")
@@ -514,17 +515,16 @@ func validateIngressHostCertificate(ctx context.Context, ingressHost string) err
514515
}
515516

516517
func ensureRoutingControllerSupported(ctx context.Context, opts *RuntimeInstallOptions) error {
517-
var controller routingutil.RoutingController
518518
var err error
519519

520520
if opts.useGatewayAPI {
521-
controller, err = routingutil.ValidateGatewayController(ctx, opts.KubeFactory, opts.GatewayName, opts.GatewayNamespace)
522-
} else {
523-
controller, err = routingutil.ValidateIngressController(ctx, opts.KubeFactory, &opts.IngressClass)
521+
opts.IngressController, err = routingutil.ValidateGatewayController(ctx, opts.KubeFactory, opts.GatewayName, opts.GatewayNamespace)
522+
} else if opts.BypassIngressClassCheck {
523+
opts.IngressController = routingutil.GetIngressController("")
524+
} else if !opts.SkipIngress {
525+
opts.IngressController, opts.IngressClass, err = routingutil.ValidateIngressController(ctx, opts.KubeFactory, opts.IngressClass)
524526
}
525527

526-
opts.IngressController = controller
527-
528528
return err
529529
}
530530

@@ -570,7 +570,7 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r
570570
AccessMode: &opts.AccessMode,
571571
}
572572

573-
if opts.AccessMode == platmodel.AccessModeIngress {
573+
if opts.shouldInstallIngress() {
574574
runtimeArgs.InternalIngressHost = &opts.InternalIngressHost
575575
runtimeArgs.IngressClass = &opts.IngressClass
576576
ingressControllerName := opts.IngressController.Name()
@@ -629,7 +629,7 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
629629
rt.Spec.IngressHost = opts.IngressHost
630630
rt.Spec.InternalIngressHost = opts.InternalIngressHost
631631
rt.Spec.Repo = opts.InsCloneOpts.Repo
632-
if opts.AccessMode == platmodel.AccessModeIngress {
632+
if opts.shouldInstallIngress() {
633633
rt.Spec.IngressClass = opts.IngressClass
634634
rt.Spec.IngressController = string(opts.IngressController.Name())
635635
}
@@ -805,7 +805,7 @@ func createRuntimeComponents(ctx context.Context, opts *RuntimeInstallOptions, r
805805
return err
806806
}
807807

808-
if opts.AccessMode == platmodel.AccessModeIngress && opts.IngressController.Name() == string(routingutil.IngressControllerNginxEnterprise) && !opts.FromRepo {
808+
if opts.shouldInstallIngress() && opts.IngressController.Name() == string(routingutil.IngressControllerNginxEnterprise) && !opts.FromRepo {
809809
err := createMasterIngressResource(ctx, opts)
810810
if err != nil {
811811
return fmt.Errorf("failed to create master ingress resource: %w", err)
@@ -869,6 +869,7 @@ func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error {
869869
RuntimeName: opts.RuntimeName,
870870
CreateDemoResources: opts.InstallDemoResources,
871871
HostName: opts.HostName,
872+
SkipIngress: opts.SkipIngress,
872873
IngressHost: opts.IngressHost,
873874
IngressClass: opts.IngressClass,
874875
IngressController: opts.IngressController,
@@ -1031,8 +1032,8 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
10311032
var err error
10321033

10331034
// bitbucket cloud take more time to push a commit
1034-
// all coming retries perpuse is to avoid issues of cloning before pervious commit was pushed
1035-
if opts.AccessMode == platmodel.AccessModeIngress && rt.Spec.IngressController != string(routingutil.IngressControllerALB) {
1035+
// the perpuse of all retries is to avoid issues of cloning before pervious commit was pushed
1036+
if opts.shouldInstallIngress() && rt.Spec.IngressController != string(routingutil.IngressControllerALB) {
10361037
if err = util.Retry(ctx, &util.RetryOptions{
10371038
Func: func() error {
10381039
return createWorkflowsIngress(ctx, opts, rt)
@@ -1459,7 +1460,7 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
14591460
hostName = opts.InternalHostName
14601461
}
14611462

1462-
if opts.AccessMode == platmodel.AccessModeIngress {
1463+
if opts.shouldInstallIngress() {
14631464
routeOpts := routingutil.CreateRouteOpts{
14641465
RuntimeName: rt.Name,
14651466
Namespace: rt.Namespace,
@@ -2045,3 +2046,7 @@ func (opts *RuntimeInstallOptions) GetValues(name string) (string, error) {
20452046
return "", nil
20462047
}
20472048
}
2049+
2050+
func (opts *RuntimeInstallOptions) shouldInstallIngress() bool {
2051+
return !opts.SkipIngress && opts.AccessMode == platmodel.AccessModeIngress
2052+
}

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

pkg/store/store.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ type Store struct {
116116
ArgoCD string
117117
Silent bool
118118
InsecureIngressHost bool
119-
BypassIngressClassCheck bool
120119
SetDefaultResources bool
121120
MinimumMemorySizeRequired string
122121
MinimumCpuRequired string

pkg/util/routing/ingress.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,66 +181,69 @@ func CreateIngress(opts *CreateRouteOpts) *netv1.Ingress {
181181
return ingress
182182
}
183183

184-
func ValidateIngressController(ctx context.Context, kubeFactory kube.Factory, ingressClass *string) (RoutingController, error) {
185-
var ingressController RoutingController
186-
if store.Get().BypassIngressClassCheck {
187-
ingressController = GetIngressController("")
188-
return ingressController, nil
189-
}
184+
func ValidateIngressController(ctx context.Context, kubeFactory kube.Factory, requestedIngressClass string) (RoutingController, string, error) {
185+
var (
186+
ingressController RoutingController
187+
ingressClass string
188+
ingressClassNames []string
189+
)
190190

191191
log.G(ctx).Info("Retrieving ingress class info from your cluster...\n")
192192

193193
cs := kubeFactory.KubernetesClientSetOrDie()
194194
ingressClassList, err := cs.NetworkingV1().IngressClasses().List(ctx, metav1.ListOptions{})
195195
if err != nil {
196-
return nil, fmt.Errorf("failed to get ingress class list from your cluster: %w", err)
196+
return nil, "", fmt.Errorf("failed to get ingress class list from your cluster: %w", err)
197197
}
198198

199-
var ingressClassNames []string
200199
ingressClassNameToController := make(map[string]RoutingController)
201-
var isValidClass bool
202200

203201
for _, ic := range ingressClassList.Items {
204202
for _, controller := range SupportedIngressControllers {
205203
if ic.Spec.Controller == string(controller) {
206204
ingressClassNames = append(ingressClassNames, ic.Name)
207205
ingressClassNameToController[ic.Name] = GetIngressController(string(controller))
208206

209-
if *ingressClass == ic.Name { // if ingress class provided via flag
210-
isValidClass = true
207+
if requestedIngressClass == ic.Name {
208+
// if ingress class provided via flag
209+
ingressClass = requestedIngressClass
211210
}
212211
break
213212
}
214213
}
215214
}
216215

217-
if *ingressClass != "" { // if ingress class provided via flag
218-
if !isValidClass {
219-
return nil, fmt.Errorf("ingress class '%s' is not supported", *ingressClass)
216+
if requestedIngressClass != "" {
217+
if ingressClass == "" {
218+
// if ingress class provided via flag was not found in cluster
219+
return nil, "", fmt.Errorf("ingress class '%s' is not supported", requestedIngressClass)
220220
}
221221
} else if len(ingressClassNames) == 0 {
222-
return nil, fmt.Errorf("no ingress classes of the supported types were found")
222+
// if no ingress classes in cluster at all
223+
return nil, "", fmt.Errorf("no ingress classes of the supported types were found")
223224
} else if len(ingressClassNames) == 1 {
225+
// if there is only 1 ingress class in the cluster - just use it
224226
log.G(ctx).Info("Using ingress class: ", ingressClassNames[0])
225-
*ingressClass = ingressClassNames[0]
227+
ingressClass = ingressClassNames[0]
226228
} else if len(ingressClassNames) > 1 {
227-
if !store.Get().Silent {
228-
*ingressClass, err = getIngressClassFromUserSelect(ingressClassNames)
229-
if err != nil {
230-
return nil, err
231-
}
232-
} else {
233-
return nil, fmt.Errorf("there are multiple ingress controllers on your cluster, please add the --ingress-class flag and define its value")
229+
// if there are multiple ingress classes in the cluster
230+
if store.Get().Silent {
231+
return nil, "", fmt.Errorf("there are multiple ingress controllers on your cluster, please add the --ingress-class flag and define its value")
232+
}
233+
234+
ingressClass, err = getIngressClassFromUserSelect(ingressClassNames)
235+
if err != nil {
236+
return nil, "", err
234237
}
235238
}
236239

237-
ingressController = ingressClassNameToController[*ingressClass]
240+
ingressController = ingressClassNameToController[ingressClass]
238241

239242
if ingressController.Name() == string(IngressControllerNginxEnterprise) {
240243
log.G(ctx).Warn("You are using the NGINX enterprise edition (nginx.org/ingress-controller) as your ingress controller. To successfully install the runtime, configure all required settings, as described in : ", store.Get().RequirementsLink)
241244
}
242245

243-
return ingressController, nil
246+
return ingressController, ingressClass, nil
244247
}
245248

246249
func getIngressClassFromUserSelect(ingressClassNames []string) (string, error) {

0 commit comments

Comments
 (0)