Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

aws: Add check for multiple worker pools #889

Merged
merged 2 commits into from
Sep 2, 2020
Merged

Conversation

knrt10
Copy link
Member

@knrt10 knrt10 commented Sep 1, 2020

Add validation check for multiple worker pools, to avoid conflicting
port values in aws_lb_listener. User has to set unique values for
lb_http_port and lb_https_port.

Part of #839

Signed-off-by: knrt10 kautilya@kinvolk.io

@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from fc7c8e7 to 97bff06 Compare September 1, 2020 14:51
pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also @knrt10 perhaps we could implement some unit tests to validate this logic? It shouldn't be too hard, as we do similar thing for example for Packet already.

@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from 97bff06 to a204fa6 Compare September 1, 2020 15:40
@knrt10 knrt10 requested a review from invidian September 1, 2020 15:40
@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from a204fa6 to f6354bf Compare September 1, 2020 15:48
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest the following patch to resolve the issues I found. Also, those scenarios should be covered by tests as well.

diff --git a/pkg/platform/aws/aws.go b/pkg/platform/aws/aws.go
index f1dd9f87..eea2a5e6 100644
--- a/pkg/platform/aws/aws.go
+++ b/pkg/platform/aws/aws.go
@@ -294,18 +294,40 @@ func (c *config) checkValidConfig() hcl.Diagnostics {
 func (c *config) checkDifferentPortForMuliplePools() hcl.Diagnostics {
        var diagnostics hcl.Diagnostics

-       portMap := make(map[int]bool)
+       portMap := make(map[int]struct {
+               field    string
+               poolName string
+       })

        for _, wp := range c.WorkerPools {
-               if !portMap[wp.LBHTTPPort] && !portMap[wp.LBHTTPSPort] {
-                       portMap[wp.LBHTTPPort] = true
-                       portMap[wp.LBHTTPSPort] = true
-               } else {
-                       diagnostics = append(diagnostics, &hcl.Diagnostic{
-                               Severity: hcl.DiagError,
-                               Summary:  "Unique values required",
-                               Detail:   fmt.Sprintf("Values lb_http_port and lb_https_port not set for worker pool %s", wp.Name),
-                       })
+               httpPort := wp.LBHTTPPort
+               if httpPort == 0 {
+                       httpPort = 80
+               }
+
+               httpsPort := wp.LBHTTPSPort
+               if httpsPort == 0 {
+                       httpsPort = 443
+               }
+
+               ports := map[int]string{
+                       httpPort:  "lb_http_port",
+                       httpsPort: "lb_https_port",
+               }
+
+               for p, field := range ports {
+                       if v, ok := portMap[p]; ok {
+                               diagnostics = append(diagnostics, &hcl.Diagnostic{
+                                       Severity: hcl.DiagError,
+                                       Summary:  "Unique ports required",
+                                       Detail:   fmt.Sprintf("'worker_pool.%s.%s' collides with 'worker_pool.%s.%s'", wp.Name, field, v.poolName, v.field),
+                               })
+                       }
+
+                       portMap[p] = struct {
+                               field    string
+                               poolName string
+                       }{field, wp.Name}
                }
        }

pkg/platform/aws/aws_test.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws_test.go Outdated Show resolved Hide resolved
@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from f6354bf to 4743ea7 Compare September 2, 2020 08:56
@knrt10
Copy link
Member Author

knrt10 commented Sep 2, 2020

Updated

@knrt10 knrt10 requested a review from invidian September 2, 2020 08:56
@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from 4743ea7 to 019e05c Compare September 2, 2020 08:59
@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch 3 times, most recently from 69a85b4 to b7593a8 Compare September 2, 2020 09:27
@knrt10 knrt10 force-pushed the knrt10/fix-aws-pool-bug branch from b7593a8 to 5b3c315 Compare September 2, 2020 10:39
@knrt10 knrt10 requested a review from surajssd September 2, 2020 10:39
invidian
invidian previously approved these changes Sep 2, 2020
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits, but not blocking. Looks cool @knrt10!

pkg/platform/aws/aws_internal_test.go Outdated Show resolved Hide resolved
pkg/platform/aws/aws_internal_test.go Outdated Show resolved Hide resolved
invidian
invidian previously approved these changes Sep 2, 2020
@invidian invidian added this to the v0.4.0 milestone Sep 2, 2020
Copy link
Contributor

@iaguis iaguis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small clarification.

pkg/platform/aws/aws.go Outdated Show resolved Hide resolved
knrt10 and others added 2 commits September 2, 2020 17:02
Add validation check for multiple worker pools, to avoid conflicting
port values in aws_lb_listener. User has to set unique values for
lb_http_port and lb_https_port.

Signed-off-by: knrt10 <kautilya@kinvolk.io>
Co-authored-by: Mateusz Gozdek <mateusz@kinvolk.io>
Signed-off-by: knrt10 <kautilya@kinvolk.io>
Copy link
Contributor

@iaguis iaguis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@knrt10 knrt10 merged commit 29d986d into master Sep 2, 2020
@knrt10 knrt10 deleted the knrt10/fix-aws-pool-bug branch September 2, 2020 11:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants