This is an automated email from the ASF dual-hosted git repository.

rom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 9b29394a30 add flexibility for redis service  (#41811)
9b29394a30 is described below

commit 9b29394a309895b63f7b60ba11789d52c62e288e
Author: Dewen Kong <[email protected]>
AuthorDate: Tue Oct 1 02:40:33 2024 -0400

    add flexibility for redis service  (#41811)
    
    * add service type options for redis
    
    * additional value
    
    * update based on testing
    
    * fix syntax
    
    * update description
    
    * Update chart/templates/redis/redis-service.yaml
    
    Co-authored-by: rom sharon <[email protected]>
    
    * Update chart/templates/redis/redis-service.yaml
    
    Co-authored-by: rom sharon <[email protected]>
    
    ---------
    
    Co-authored-by: rom sharon <[email protected]>
---
 chart/templates/redis/redis-service.yaml | 10 ++++++++
 chart/values.schema.json                 | 33 +++++++++++++++++++++++++
 chart/values.yaml                        |  8 +++++++
 helm_tests/other/test_redis.py           | 41 ++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+)

diff --git a/chart/templates/redis/redis-service.yaml 
b/chart/templates/redis/redis-service.yaml
index 17d4c8d5e4..ee010901ef 100644
--- a/chart/templates/redis/redis-service.yaml
+++ b/chart/templates/redis/redis-service.yaml
@@ -35,7 +35,14 @@ metadata:
       {{- toYaml . | nindent 4 }}
     {{- end }}
 spec:
+{{- if eq .Values.redis.service.type "ClusterIP" }}
   type: ClusterIP
+  {{- if .Values.redis.service.clusterIP }}
+  clusterIP: {{ .Values.redis.service.clusterIP }}
+  {{- end }}
+{{- else }}
+  type: {{ .Values.redis.service.type }}
+{{- end }}
   selector:
     tier: airflow
     component: redis
@@ -45,4 +52,7 @@ spec:
       protocol: TCP
       port: {{ .Values.ports.redisDB }}
       targetPort: {{ .Values.ports.redisDB }}
+      {{- if (and (eq .Values.redis.service.type "NodePort") (not (empty 
.Values.redis.service.nodePort))) }}
+      nodePort: {{ .Values.redis.service.nodePort }}
+      {{- end }}
 {{- end }}
diff --git a/chart/values.schema.json b/chart/values.schema.json
index 948f09f3b9..d8b5de41c8 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -7670,6 +7670,39 @@
                     "type": "integer",
                     "default": 600
                 },
+                "service": {
+                    "description": "service configuration.",
+                    "type": "object",
+                    "additionalProperties": false,
+                    "properties": {
+                        "type": {
+                            "description": "Service type.",
+                            "enum": [
+                                "ClusterIP",
+                                "NodePort",
+                                "LoadBalancer"
+                            ],
+                            "type": "string",
+                            "default": "ClusterIP"
+                        },
+                        "clusterIP": {
+                            "description": "If using `ClusterIP` service type, 
custom IP address can be specified.",
+                            "type": [
+                                "string",
+                                "null"
+                            ],
+                            "default": null
+                        },
+                        "nodePort": {
+                            "description": "If using `NodePort` service type, 
custom node port can be specified.",
+                            "type": [
+                                "integer",
+                                "null"
+                            ],
+                            "default": null
+                        }
+                    }
+                },
                 "persistence": {
                     "description": "Persistence configuration.",
                     "type": "object",
diff --git a/chart/values.yaml b/chart/values.yaml
index 7bfa733a90..0edb9f2bd7 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -2378,6 +2378,14 @@ redis:
     # Annotations to add to worker kubernetes service account.
     annotations: {}
 
+  service:
+    # service type, default: ClusterIP
+    type: "ClusterIP"
+    # If using ClusterIP service type, custom IP address can be specified
+    clusterIP:
+    # If using NodePort service type, custom node port can be specified
+    nodePort:
+
   persistence:
     # Enable persistent volumes
     enabled: true
diff --git a/helm_tests/other/test_redis.py b/helm_tests/other/test_redis.py
index a5a6f2099e..8c44567420 100644
--- a/helm_tests/other/test_redis.py
+++ b/helm_tests/other/test_redis.py
@@ -452,3 +452,44 @@ class TestRedisServiceAccount:
             show_only=["templates/redis/redis-serviceaccount.yaml"],
         )
         assert jmespath.search("automountServiceAccountToken", docs[0]) is 
False
+
+
+class TestRedisService:
+    """Tests redis service."""
+
+    @pytest.mark.parametrize(
+        "redis_values, expected",
+        [
+            ({"redis": {"service": {"type": "ClusterIP"}}}, "ClusterIP"),
+            ({"redis": {"service": {"type": "NodePort"}}}, "NodePort"),
+            ({"redis": {"service": {"type": "LoadBalancer"}}}, "LoadBalancer"),
+        ],
+    )
+    def test_redis_service_type(self, redis_values, expected):
+        docs = render_chart(
+            values=redis_values,
+            show_only=["templates/redis/redis-service.yaml"],
+        )
+        assert expected == jmespath.search("spec.type", docs[0])
+
+    def test_redis_service_nodeport(self):
+        docs = render_chart(
+            values={
+                "redis": {
+                    "service": {"type": "NodePort", "nodePort": 11111},
+                },
+            },
+            show_only=["templates/redis/redis-service.yaml"],
+        )
+        assert 11111 == jmespath.search("spec.ports[0].nodePort", docs[0])
+
+    def test_redis_service_clusterIP(self):
+        docs = render_chart(
+            values={
+                "redis": {
+                    "service": {"type": "ClusterIP", "clusterIP": "127.0.0.1"},
+                },
+            },
+            show_only=["templates/redis/redis-service.yaml"],
+        )
+        assert "127.0.0.1" == jmespath.search("spec.clusterIP", docs[0])

Reply via email to