From 278e27aedd641145a3bb4140195d8880f3e6f609 Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Fri, 7 Oct 2022 17:27:24 -0500
Subject: [PATCH 1/8] Add nodePort declaration to chart/values.schema.json to
 allow explicit setting of a nodePort port value when deploying via Helm chart

---
 chart/values.schema.json | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/chart/values.schema.json b/chart/values.schema.json
index faaed86f8e704..c3fe1f510151c 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -3465,6 +3465,12 @@
                                             "integer"
                                         ]
                                     },
+                                    "nodePort": {
+                                        "type": [
+                                            "string",
+                                            "integer"
+                                        ]
+                                    },
                                     "protocol": {
                                         "type": "string"
                                     }

From 773fe0079dc15791c17b293cf04861a4673956a6 Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Sun, 9 Oct 2022 14:35:59 -0500
Subject: [PATCH 2/8] Add test for NodePort service type for webserver
 component

---
 tests/charts/test_webserver.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index facaa97a30a22..41aa4b27d4bab 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -719,6 +719,30 @@ def test_should_add_component_specific_labels(self):
         assert "test_label" in jmespath.search("metadata.labels", docs[0])
         assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value"
 
+    @parameterized.expand(
+        [
+            (
+                [{"name": "webserver-nodeport", "nodePort": "31000", "port": "8080"}],
+                [{"name": "webserver-nodeport", "nodePort": 31000, "port": 8080}],
+            )
+        ]
+    )
+    def test_nodeport_service(self, ports, expected_ports):
+        docs = render_chart(
+            values={
+                "webserver": {
+                    "service": {
+                        "type": "NodePort",
+                        "ports": (ports),
+                    }
+                },
+            },
+            show_only=["templates/webserver/webserver-service.yaml"],
+        )
+
+        assert "NodePort" == jmespath.search("spec.type", docs[0])
+        assert expected_ports == jmespath.search("spec.ports", docs[0])
+
 
 class TestWebserverConfigmap:
     def test_no_webserver_config_configmap_by_default(self):

From fb27f0f247b31d9faa0bd5b9ab0cb5ba9410c75d Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Mon, 10 Oct 2022 18:32:03 -0500
Subject: [PATCH 3/8] Add NodePort test case where no NodePort is provided but
 service is still specified as NodePort

---
 tests/charts/test_webserver.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index 41aa4b27d4bab..85a60d2b87602 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -724,6 +724,10 @@ def test_should_add_component_specific_labels(self):
             (
                 [{"name": "webserver-nodeport", "nodePort": "31000", "port": "8080"}],
                 [{"name": "webserver-nodeport", "nodePort": 31000, "port": 8080}],
+            ),
+            (
+                [{"name": "webserver-nodeport", "port": "8080"}],
+                [{"name": "webserver-nodeport", "port": 8080}],
             )
         ]
     )

From b8e2dc3f0a9d5f749a7f46016537b4ecf8773a46 Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Tue, 18 Oct 2022 08:02:50 -0500
Subject: [PATCH 4/8] Add missing comma to test_nodeport_service parameters for
 style purposes

---
 tests/charts/test_webserver.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index 85a60d2b87602..4ae74a1e1a46e 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -728,7 +728,7 @@ def test_should_add_component_specific_labels(self):
             (
                 [{"name": "webserver-nodeport", "port": "8080"}],
                 [{"name": "webserver-nodeport", "port": 8080}],
-            )
+            ),
         ]
     )
     def test_nodeport_service(self, ports, expected_ports):

From 90606c7314e7ac527ce22fdd58df13fa9e2cae55 Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Fri, 21 Oct 2022 17:32:26 -0500
Subject: [PATCH 5/8] Update test_nodeport_service unit test with new pytest
 format

---
 tests/charts/test_webserver.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index 4ae74a1e1a46e..c181ac37c28c5 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -719,7 +719,8 @@ def test_should_add_component_specific_labels(self):
         assert "test_label" in jmespath.search("metadata.labels", docs[0])
         assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value"
 
-    @parameterized.expand(
+    @pytest.mark.parametrize(
+        "ports, expected_ports",
         [
             (
                 [{"name": "webserver-nodeport", "nodePort": "31000", "port": "8080"}],

From 6f1b23715589520f83340b8a819f35e90f53b79a Mon Sep 17 00:00:00 2001
From: Joseph Morris <jmorris@coalfire.com>
Date: Fri, 21 Oct 2022 17:33:52 -0500
Subject: [PATCH 6/8] Black formatting for tests/charts/test_webserver.py

---
 tests/charts/test_webserver.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index c181ac37c28c5..f60d97314d8ac 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -730,7 +730,7 @@ def test_should_add_component_specific_labels(self):
                 [{"name": "webserver-nodeport", "port": "8080"}],
                 [{"name": "webserver-nodeport", "port": 8080}],
             ),
-        ]
+        ],
     )
     def test_nodeport_service(self, ports, expected_ports):
         docs = render_chart(

From 892a43adf71678b114c5c15ff4208b014f79ea02 Mon Sep 17 00:00:00 2001
From: Joseph Max Morris
 <77305023+joseph-max-coalfire@users.noreply.github.com>
Date: Tue, 8 Nov 2022 13:13:13 -0600
Subject: [PATCH 7/8] Remove unnecessary parentheses from nodeport test

Co-authored-by: Daniel Standish <15932138+dstandish@users.noreply.github.com>
---
 tests/charts/test_webserver.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index f60d97314d8ac..07878c7d801e6 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -738,7 +738,7 @@ def test_nodeport_service(self, ports, expected_ports):
                 "webserver": {
                     "service": {
                         "type": "NodePort",
-                        "ports": (ports),
+                        "ports": ports,
                     }
                 },
             },

From 92c07ee7c57fe7f4337d66a295d76d2dfde26773 Mon Sep 17 00:00:00 2001
From: Joseph Max Morris
 <77305023+joseph-max-coalfire@users.noreply.github.com>
Date: Tue, 8 Nov 2022 13:13:35 -0600
Subject: [PATCH 8/8] Remove "name" value from nodeport test

Co-authored-by: Daniel Standish <15932138+dstandish@users.noreply.github.com>
---
 tests/charts/test_webserver.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/charts/test_webserver.py b/tests/charts/test_webserver.py
index 07878c7d801e6..d5f70d3d462a7 100644
--- a/tests/charts/test_webserver.py
+++ b/tests/charts/test_webserver.py
@@ -723,12 +723,12 @@ def test_should_add_component_specific_labels(self):
         "ports, expected_ports",
         [
             (
-                [{"name": "webserver-nodeport", "nodePort": "31000", "port": "8080"}],
-                [{"name": "webserver-nodeport", "nodePort": 31000, "port": 8080}],
+                [{"nodePort": "31000", "port": "8080"}],
+                [{"nodePort": 31000, "port": 8080}],
             ),
             (
-                [{"name": "webserver-nodeport", "port": "8080"}],
-                [{"name": "webserver-nodeport", "port": 8080}],
+                [{"port": "8080"}],
+                [{"port": 8080}],
             ),
         ],
     )
