Skip to content

Commit

Permalink
Option to support additional Service types (#202)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Signed-off-by: Ayush Tiwari <[email protected]>
  • Loading branch information
dbcelm authored May 11, 2024
1 parent c46b566 commit c86ac70
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/opencost/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
- finops
- monitoring
- opencost
version: 1.36.0
version: 1.37.0
maintainers:
- name: mattray
url: https://mattray.dev
Expand Down
2 changes: 2 additions & 0 deletions charts/opencost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
15 changes: 14 additions & 1 deletion charts/opencost/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions charts/opencost/tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions charts/opencost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit c86ac70

Please sign in to comment.