Skip to content

Commit 9a68d9c

Browse files
Cr 8871 - ALB support (#354)
* initial commit * Add ingressController field * fix * bump * fixes according to code review * Clean up ingress controller related logic * bump
1 parent f48d149 commit 9a68d9c

File tree

8 files changed

+133
-107
lines changed

8 files changed

+133
-107
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.321
1+
VERSION=v0.0.322
22

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

cmd/commands/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func setIngressHost(ctx context.Context, opts *RuntimeInstallOptions) error {
451451
}
452452

453453
for _, s := range ServicesList.Items {
454-
if s.ObjectMeta.Name == opts.IngressController && s.Spec.Type == "LoadBalancer" {
454+
if s.ObjectMeta.Name == opts.IngressController.Name() && s.Spec.Type == "LoadBalancer" {
455455
if len(s.Status.LoadBalancer.Ingress) > 0 {
456456
ingress := s.Status.LoadBalancer.Ingress[0]
457457
if ingress.Hostname != "" {

cmd/commands/git-source.go

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ import (
5353

5454
type (
5555
GitSourceCreateOptions struct {
56-
InsCloneOpts *git.CloneOptions
57-
GsCloneOpts *git.CloneOptions
58-
GsName string
59-
RuntimeName string
60-
CreateDemoResources bool
61-
Exclude string
62-
Include string
63-
HostName string
64-
IngressHost string
65-
IngressClass string
66-
IngressControllerType ingressControllerType
56+
InsCloneOpts *git.CloneOptions
57+
GsCloneOpts *git.CloneOptions
58+
GsName string
59+
RuntimeName string
60+
CreateDemoResources bool
61+
Exclude string
62+
Include string
63+
HostName string
64+
IngressHost string
65+
IngressClass string
66+
IngressController ingressutil.IngressController
6767
}
6868

6969
GitSourceDeleteOptions struct {
@@ -87,13 +87,13 @@ type (
8787
}
8888

8989
gitSourceGithubExampleOptions struct {
90-
runtimeName string
91-
gsCloneOpts *git.CloneOptions
92-
gsFs fs.FS
93-
hostName string
94-
ingressHost string
95-
ingressClass string
96-
ingressControllerType ingressControllerType
90+
runtimeName string
91+
gsCloneOpts *git.CloneOptions
92+
gsFs fs.FS
93+
hostName string
94+
ingressHost string
95+
ingressClass string
96+
ingressController ingressutil.IngressController
9797
}
9898

9999
dirConfig struct {
@@ -255,13 +255,13 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
255255
}
256256

257257
err = createGithubExamplePipeline(&gitSourceGithubExampleOptions{
258-
runtimeName: opts.RuntimeName,
259-
gsCloneOpts: opts.GsCloneOpts,
260-
gsFs: gsFs,
261-
hostName: opts.HostName,
262-
ingressHost: opts.IngressHost,
263-
ingressClass: opts.IngressClass,
264-
ingressControllerType: opts.IngressControllerType,
258+
runtimeName: opts.RuntimeName,
259+
gsCloneOpts: opts.GsCloneOpts,
260+
gsFs: gsFs,
261+
hostName: opts.HostName,
262+
ingressHost: opts.IngressHost,
263+
ingressClass: opts.IngressClass,
264+
ingressController: opts.IngressController,
265265
})
266266
if err != nil {
267267
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
@@ -742,7 +742,7 @@ func createDemoWorkflowTemplate(gsFs fs.FS) error {
742742
func createGithubExamplePipeline(opts *gitSourceGithubExampleOptions) error {
743743
if !store.Get().SkipIngress {
744744
// Create an ingress that will manage external access to the github eventsource service
745-
ingress := createGithubExampleIngress(opts.ingressClass, opts.ingressHost, opts.hostName, opts.ingressControllerType, opts.runtimeName)
745+
ingress := createGithubExampleIngress(opts.ingressClass, opts.ingressHost, opts.hostName, opts.ingressController, opts.runtimeName)
746746
ingressFilePath := opts.gsFs.Join(opts.gsCloneOpts.Path(), store.Get().GithubExampleIngressFileName)
747747

748748
ingressRedundanded, err := cleanUpFieldsIngressGithub(&ingress)
@@ -795,7 +795,7 @@ func createGithubExamplePipeline(opts *gitSourceGithubExampleOptions) error {
795795
return nil
796796
}
797797

798-
func createGithubExampleIngress(ingressClass string, ingressHost string, hostName string, ingressControllerType ingressControllerType, runtimeName string) *netv1.Ingress {
798+
func createGithubExampleIngress(ingressClass string, ingressHost string, hostName string, ingressController ingressutil.IngressController, runtimeName string) *netv1.Ingress {
799799
ingressOptions := ingressutil.CreateIngressOptions{
800800
Name: store.Get().CodefreshDeliveryPipelines,
801801
IngressClassName: ingressClass,
@@ -809,13 +809,10 @@ func createGithubExampleIngress(ingressClass string, ingressHost string, hostNam
809809
},
810810
}}
811811

812-
if ingressControllerType == IngressControllerNginxEnterprise {
813-
ingressOptions.Annotations = map[string]string{
814-
"nginx.org/mergeable-ingress-type": "minion",
815-
}
816-
}
812+
ingress := ingressutil.CreateIngress(&ingressOptions)
813+
ingressController.Decorate(ingress)
817814

818-
return ingressutil.CreateIngress(&ingressOptions)
815+
return ingress
819816
}
820817

821818
func getRepoOwnerAndNameFromRepoURL(repoURL string) (owner string, name string) {

cmd/commands/runtime.go

Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ type (
8484
HostName string
8585
IngressHost string
8686
IngressClass string
87-
IngressController string
88-
IngressControllerType ingressControllerType
87+
IngressController ingressutil.IngressController
8988
Insecure bool
9089
InstallDemoResources bool
9190
SkipClusterChecks bool
@@ -141,25 +140,12 @@ type (
141140
message string
142141
level summaryLogLevels
143142
}
144-
145-
ingressControllerType string
146-
147-
ingressController struct {
148-
Name string
149-
Type ingressControllerType
150-
}
151143
)
152144

153145
const (
154146
Success summaryLogLevels = "Success"
155147
Failed summaryLogLevels = "Failed"
156148
Info summaryLogLevels = "Info"
157-
158-
IngressControllerNginxCommunity ingressControllerType = "k8s.io/ingress-nginx"
159-
IngressControllerNginxEnterprise ingressControllerType = "nginx.org/ingress-controller"
160-
IngressControllerIstio ingressControllerType = "istio.io/ingress-controller"
161-
IngressControllerTraefik ingressControllerType = "traefik.io/ingress-controller"
162-
IngressControllerAmbassador ingressControllerType = "getambassador.io/ingress-controller"
163149
)
164150

165151
var summaryArr []summaryLog
@@ -475,6 +461,7 @@ func ensureIngressHost(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
475461

476462
func ensureIngressClass(ctx context.Context, opts *RuntimeInstallOptions) error {
477463
if store.Get().BypassIngressClassCheck || store.Get().SkipIngress {
464+
opts.IngressController = ingressutil.GetController("")
478465
return nil
479466
}
480467

@@ -486,19 +473,15 @@ func ensureIngressClass(ctx context.Context, opts *RuntimeInstallOptions) error
486473
return fmt.Errorf("failed to get ingress class list from your cluster: %w", err)
487474
}
488475

489-
supportedControllers := []ingressControllerType{IngressControllerNginxCommunity, IngressControllerNginxEnterprise, IngressControllerIstio, IngressControllerTraefik, IngressControllerAmbassador}
490476
var ingressClassNames []string
491-
ingressClassNameToController := make(map[string]ingressController)
477+
ingressClassNameToController := make(map[string]ingressutil.IngressController)
492478
var isValidClass bool
493479

494480
for _, ic := range ingressClassList.Items {
495-
for _, controller := range supportedControllers {
481+
for _, controller := range ingressutil.SupportedControllers {
496482
if ic.Spec.Controller == string(controller) {
497483
ingressClassNames = append(ingressClassNames, ic.Name)
498-
ingressClassNameToController[ic.Name] = ingressController{
499-
Name: getIngressControllerName(controller, ic.Name),
500-
Type: controller,
501-
}
484+
ingressClassNameToController[ic.Name] = ingressutil.GetController(string(controller))
502485

503486
if opts.IngressClass == ic.Name { //if ingress class provided via flag
504487
isValidClass = true
@@ -528,31 +511,15 @@ func ensureIngressClass(ctx context.Context, opts *RuntimeInstallOptions) error
528511
}
529512
}
530513

531-
opts.IngressController = ingressClassNameToController[opts.IngressClass].Name
532-
opts.IngressControllerType = ingressClassNameToController[opts.IngressClass].Type
514+
opts.IngressController = ingressClassNameToController[opts.IngressClass]
533515

534-
if opts.IngressControllerType == IngressControllerNginxEnterprise {
516+
if opts.IngressController.Name() == string(ingressutil.IngressControllerNginxEnterprise) {
535517
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)
536518
}
537519

538520
return nil
539521
}
540522

541-
func getIngressControllerName(controllerType ingressControllerType, className string) string {
542-
switch controllerType {
543-
case IngressControllerNginxCommunity:
544-
return "ingress-nginx-controller"
545-
case IngressControllerNginxEnterprise:
546-
return fmt.Sprintf("%s-ingress-controller", className)
547-
case IngressControllerTraefik:
548-
return "traefik"
549-
case IngressControllerIstio:
550-
return "istio-ingressgateway"
551-
default:
552-
return ""
553-
}
554-
}
555-
556523
func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
557524
var componentNames []string
558525
for _, component := range rt.Spec.Components {
@@ -613,14 +580,17 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
613580
postInstallationHandler(ctx, opts, err, &disableRollback)
614581
}()
615582

583+
ingressControllerName := opts.IngressController.Name()
584+
616585
token, iv, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
617-
RuntimeName: opts.RuntimeName,
618-
Cluster: server,
619-
RuntimeVersion: runtimeVersion,
620-
IngressHost: &opts.IngressHost,
621-
ComponentNames: componentNames,
622-
Repo: &opts.InsCloneOpts.Repo,
623-
IngressClass: &opts.IngressClass,
586+
RuntimeName: opts.RuntimeName,
587+
Cluster: server,
588+
RuntimeVersion: runtimeVersion,
589+
IngressHost: &opts.IngressHost,
590+
IngressClass: &opts.IngressClass,
591+
IngressController: &ingressControllerName,
592+
ComponentNames: componentNames,
593+
Repo: &opts.InsCloneOpts.Repo,
624594
})
625595
handleCliStep(reporter.InstallStepCreateRuntimeOnPlatform, "Creating runtime on platform", err, false, true)
626596
if err != nil {
@@ -632,6 +602,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
632602
rt.Spec.Cluster = server
633603
rt.Spec.IngressHost = opts.IngressHost
634604
rt.Spec.IngressClass = opts.IngressClass
605+
rt.Spec.IngressController = string(opts.IngressController.Name())
635606
rt.Spec.Repo = opts.InsCloneOpts.Repo
636607

637608
log.G(ctx).WithField("version", rt.Spec.Version).Infof("Installing runtime \"%s\"", opts.RuntimeName)
@@ -772,7 +743,7 @@ func createRuntimeComponents(ctx context.Context, opts *RuntimeInstallOptions, r
772743
return err
773744
}
774745

775-
if opts.IngressControllerType == IngressControllerNginxEnterprise {
746+
if opts.IngressController.Name() == string(ingressutil.IngressControllerNginxEnterprise) {
776747
err := createMasterIngressResource(ctx, opts)
777748
if err != nil {
778749
return fmt.Errorf("failed to create master ingress resource: %w", err)
@@ -820,15 +791,15 @@ func createMasterIngressResource(ctx context.Context, opts *RuntimeInstallOption
820791
func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error {
821792
gitSrcMessage := fmt.Sprintf("Creating git source \"%s\"", store.Get().GitSourceName)
822793
err := RunGitSourceCreate(ctx, &GitSourceCreateOptions{
823-
InsCloneOpts: opts.InsCloneOpts,
824-
GsCloneOpts: opts.GsCloneOpts,
825-
GsName: store.Get().GitSourceName,
826-
RuntimeName: opts.RuntimeName,
827-
CreateDemoResources: opts.InstallDemoResources,
828-
HostName: opts.HostName,
829-
IngressHost: opts.IngressHost,
830-
IngressClass: opts.IngressClass,
831-
IngressControllerType: opts.IngressControllerType,
794+
InsCloneOpts: opts.InsCloneOpts,
795+
GsCloneOpts: opts.GsCloneOpts,
796+
GsName: store.Get().GitSourceName,
797+
RuntimeName: opts.RuntimeName,
798+
CreateDemoResources: opts.InstallDemoResources,
799+
HostName: opts.HostName,
800+
IngressHost: opts.IngressHost,
801+
IngressClass: opts.IngressClass,
802+
IngressController: opts.IngressController,
832803
})
833804
handleCliStep(reporter.InstallStepCreateGitsource, gitSrcMessage, err, false, true)
834805
if err != nil {
@@ -950,7 +921,7 @@ you can try to create it manually by running:
950921
func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
951922
var err error
952923

953-
if !store.Get().SkipIngress {
924+
if !store.Get().SkipIngress && rt.Spec.IngressController != string(ingressutil.IngressControllerALB) {
954925
if err = createWorkflowsIngress(ctx, opts, rt); err != nil {
955926
return fmt.Errorf("failed to patch Argo-Workflows ingress: %w", err)
956927
}
@@ -1802,11 +1773,8 @@ func createWorkflowsIngress(ctx context.Context, opts *RuntimeInstallOptions, rt
18021773
},
18031774
}
18041775

1805-
if opts.IngressControllerType == IngressControllerNginxEnterprise {
1806-
ingressOptions.Annotations["nginx.org/mergeable-ingress-type"] = "minion"
1807-
}
1808-
18091776
ingress := ingressutil.CreateIngress(&ingressOptions)
1777+
opts.IngressController.Decorate(ingress)
18101778

18111779
if err = fs.WriteYamls(fs.Join(overlaysDir, "ingress.yaml"), ingress); err != nil {
18121780
return err
@@ -1891,13 +1859,8 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
18911859
},
18921860
}
18931861

1894-
if opts.IngressControllerType == IngressControllerNginxEnterprise {
1895-
ingressOptions.Annotations = map[string]string{
1896-
"nginx.org/mergeable-ingress-type": "minion",
1897-
}
1898-
}
1899-
19001862
ingress := ingressutil.CreateIngress(&ingressOptions)
1863+
opts.IngressController.Decorate(ingress)
19011864

19021865
if err = fs.WriteYamls(fs.Join(overlaysDir, "ingress.yaml"), ingress); err != nil {
19031866
return err

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

pkg/runtime/runtime.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type (
5858
Cluster string `json:"cluster"`
5959
IngressHost string `json:"ingressHost"`
6060
IngressClass string `json:"ingressClassName"`
61+
IngressController string `json:"ingressController"`
6162
Repo string `json:"repo"`
6263

6364
devMode bool
@@ -208,6 +209,7 @@ func (r *RuntimeSpec) upgrade(fs fs.FS, newRt *RuntimeSpec) ([]AppDef, error) {
208209
newRt.Cluster = r.Cluster
209210
newRt.IngressHost = r.IngressHost
210211
newRt.IngressClass = r.IngressClass
212+
newRt.IngressController = r.IngressController
211213
newRt.Repo = r.Repo
212214

213215
newComponents := make([]AppDef, 0)

0 commit comments

Comments
 (0)