From c86ac7031c2965c839a757591a73d3f32f2a9e93 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari <47293577+dbcelm@users.noreply.github.com> Date: Sun, 12 May 2024 04:50:59 +0530 Subject: [PATCH] Option to support additional Service types (#202) * added option to choose multiple service types * fixes based on review * fixed indentation and default service type * fixes based on review * bumped chart version to 1.36.0 * bumped version to 1.37.0 Signed-off-by: Ayush Tiwari <47293577+dbcelm@users.noreply.github.com> --------- Signed-off-by: Ayush Tiwari <47293577+dbcelm@users.noreply.github.com> --- charts/opencost/Chart.yaml | 2 +- charts/opencost/README.md | 2 ++ charts/opencost/templates/service.yaml | 15 ++++++++++++- charts/opencost/tests/service_test.yaml | 29 +++++++++++++++++++++++++ charts/opencost/values.yaml | 4 ++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 charts/opencost/tests/service_test.yaml diff --git a/charts/opencost/Chart.yaml b/charts/opencost/Chart.yaml index 0bd5147..e9a8bbd 100755 --- a/charts/opencost/Chart.yaml +++ b/charts/opencost/Chart.yaml @@ -9,7 +9,7 @@ keywords: - finops - monitoring - opencost -version: 1.36.0 +version: 1.37.0 maintainers: - name: mattray url: https://mattray.dev diff --git a/charts/opencost/README.md b/charts/opencost/README.md index 18d281e..39db624 100644 --- a/charts/opencost/README.md +++ b/charts/opencost/README.md @@ -198,6 +198,8 @@ $ helm install opencost opencost/opencost | service.enabled | bool | `true` | | | service.extraPorts | list | `[]` | extra ports. Useful for sidecar pods such as oauth-proxy | | service.labels | object | `{}` | Labels to add to the service account | +| service.loadBalancerSourceRanges | list | `[]` | LoadBalancer Source IP CIDR if service type is LoadBalancer and cloud provider supports this | +| service.nodePort | object | `{}` | NodePort if service type is NodePort | | service.type | string | `"ClusterIP"` | Kubernetes Service type | | serviceAccount.annotations | object | `{}` | Annotations to add to the service account | | serviceAccount.automountServiceAccountToken | bool | `true` | Whether pods running as this service account should have an API token automatically mounted | diff --git a/charts/opencost/templates/service.yaml b/charts/opencost/templates/service.yaml index 1a65a7f..4c8c8e5 100644 --- a/charts/opencost/templates/service.yaml +++ b/charts/opencost/templates/service.yaml @@ -14,7 +14,15 @@ metadata: {{- end }} spec: selector: {{- include "opencost.selectorLabels" . | nindent 4 }} - type: {{ .Values.service.type }} + {{- if and .Values.service .Values.service.type }} + type: "{{ .Values.service.type }}" + {{- end }} + {{- if (eq .Values.service.type "LoadBalancer") }} + {{- if .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }} + {{- end -}} + {{- end }} ports: - name: http port: {{ .Values.opencost.exporter.apiPort }} @@ -23,6 +31,11 @@ spec: - name: http-ui port: {{ .Values.opencost.ui.uiPort }} targetPort: {{ .Values.opencost.ui.uiPort }} + {{- if (eq .Values.service.type "NodePort") }} + {{- if .Values.service.nodePort }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + {{- end }} {{- end }} {{- if .Values.opencost.exporter.debugPort }} - name: debug-port diff --git a/charts/opencost/tests/service_test.yaml b/charts/opencost/tests/service_test.yaml new file mode 100644 index 0000000..b1fec3a --- /dev/null +++ b/charts/opencost/tests/service_test.yaml @@ -0,0 +1,29 @@ +suite: test service +templates: + - templates/service.yaml +tests: + - it: should work + set: + service: + type: ClusterIP + asserts: + - equal: + path: spec.type + value: ClusterIP + - it: should render right if values given + set: + service: + type: NodePort + NodePort: 30200 + asserts: + - equal: + path: spec.type + value: NodePort + - it: should render right if values given + set: + service: + type: LoadBalancer + asserts: + - equal: + path: spec.type + value: LoadBalancer diff --git a/charts/opencost/values.yaml b/charts/opencost/values.yaml index 315c406..25b0f19 100644 --- a/charts/opencost/values.yaml +++ b/charts/opencost/values.yaml @@ -95,6 +95,8 @@ service: labels: {} # -- Kubernetes Service type type: ClusterIP + # -- NodePort if service type is NodePort + nodePort: {} # -- extra ports. Useful for sidecar pods such as oauth-proxy extraPorts: [] # - name: oauth-proxy @@ -103,6 +105,8 @@ service: # - name: oauth-metrics # port: 8082 # targetPort: 8082 + # -- LoadBalancer Source IP CIDR if service type is LoadBalancer and cloud provider supports this + loadBalancerSourceRanges: [] # Create cluster role policies rbac: