From d27ea2474504653383d005adcbc043b34d62eccd Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Sat, 14 Sep 2024 11:39:53 +0000 Subject: [PATCH] Add service params snippet Allows to add custom parameters to services, and ingress services from values as is. Co-Authored-By: Mykyta Karpin Change-Id: I42b8d07126de2cf12ddc3a934d1fd4e3a2ee0051 --- helm-toolkit/Chart.yaml | 2 +- .../templates/snippets/_service_params.tpl | 61 +++++++++++++++++++ releasenotes/notes/helm-toolkit.yaml | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 helm-toolkit/templates/snippets/_service_params.tpl diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index b8027958c..e08489122 100644 --- a/helm-toolkit/Chart.yaml +++ b/helm-toolkit/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Helm-Toolkit name: helm-toolkit -version: 0.2.70 +version: 0.2.71 home: https://docs.openstack.org/openstack-helm icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png sources: diff --git a/helm-toolkit/templates/snippets/_service_params.tpl b/helm-toolkit/templates/snippets/_service_params.tpl new file mode 100644 index 000000000..6233a9355 --- /dev/null +++ b/helm-toolkit/templates/snippets/_service_params.tpl @@ -0,0 +1,61 @@ +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} +{{/* +abstract: | + Inserts kubernetes service parameters from values as is. +values: | + network: + serviceExample: + service: + type: loadBalancer + loadBalancerIP: 1.1.1.1 +usage: | + --- + apiVersion: v1 + kind: Service + metadata: + name: 'serviceExample' + spec: + ports: + - name: s-example + port: 1111 + {{ .Values.network.serviceExample | include "helm-toolkit.snippets.service_params" | indent 2 }} +return: | + type: loadBalancer + loadBalancerIP: 1.1.1.1 +*/}} + +{{- define "helm-toolkit.snippets.service_params" }} +{{- $serviceParams := dict }} +{{- if hasKey . "service" }} +{{- $serviceParams = .service }} +{{- end }} +{{- if hasKey . "node_port" }} +{{- if hasKey .node_port "enabled" }} +{{- if .node_port.enabled }} +{{- $_ := set $serviceParams "type" "NodePort" }} +{{- end }} +{{- end }} +{{- end }} +{{- if hasKey . "external_policy_local" }} +{{- if .external_policy_local }} +{{- $_ := set $serviceParams "externalTrafficPolicy" "Local" }} +{{- end }} +{{- end }} +{{- if $serviceParams }} +{{- $serviceParams | toYaml }} +{{- end }} +{{- end }} diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index b013261c7..a382844e4 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -77,4 +77,5 @@ helm-toolkit: - 0.2.68 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default - 0.2.69 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default - 0.2.70 Decode url-encoded password for rabbit connection + - 0.2.71 Add snippet with service parameters ...