diff --git a/examples/app/templates/myapp-lb-service.yaml b/examples/app/templates/myapp-lb-service.yaml new file mode 100644 index 0000000..c440b1f --- /dev/null +++ b/examples/app/templates/myapp-lb-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "app.fullname" . }}-myapp-lb-service + labels: + app: myapp + {{- include "app.labels" . | nindent 4 }} +spec: + type: {{ .Values.myappLbService.type }} + selector: + app: myapp + {{- include "app.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.myappLbService.ports | toYaml | nindent 2 }} + loadBalancerSourceRanges: + {{ - .Values.myappLbService.loadBalancerSourceRanges | toYaml | nindent 2 }} \ No newline at end of file diff --git a/examples/app/values.yaml b/examples/app/values.yaml index 8a19b2c..2d23d62 100644 --- a/examples/app/values.yaml +++ b/examples/app/values.yaml @@ -89,6 +89,14 @@ myapp: tag: v0.8.0 replicas: 3 revisionHistoryLimit: 5 +myappLbService: + loadBalancerSourceRanges: + - 10.0.0.0/8 + ports: + - name: https + port: 8443 + targetPort: https + type: LoadBalancer myappPdb: minAvailable: 2 myappService: diff --git a/pkg/processor/service/service.go b/pkg/processor/service/service.go index 7a22348..2379d16 100644 --- a/pkg/processor/service/service.go +++ b/pkg/processor/service/service.go @@ -30,6 +30,12 @@ spec: {{- .Values.%[1]s.ports | toYaml | nindent 2 }}` ) +const ( + lbSourceRangesTempSpec = ` + loadBalancerSourceRanges: + {{ - .Values.%[1]s.loadBalancerSourceRanges | toYaml | nindent 2 }}` +) + var svcGVC = schema.GroupVersionKind{ Group: "", Version: "v1", @@ -97,6 +103,9 @@ func (r svc) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured _ = unstructured.SetNestedSlice(values, ports, shortNameCamel, "ports") res := meta + fmt.Sprintf(svcTempSpec, shortNameCamel, selector, appMeta.ChartName()) + + res += parseLoadBalancerSourceRanges(values, service, shortNameCamel) + if shortNameCamel == "webhookService" && appMeta.Config().AddWebhookOption { res = fmt.Sprintf("{{- if .Values.webhook.enabled }}\n%s\n{{- end }}", res) } @@ -107,6 +116,18 @@ func (r svc) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured }, nil } +func parseLoadBalancerSourceRanges(values helmify.Values, service corev1.Service, shortNameCamel string) string { + if len(service.Spec.LoadBalancerSourceRanges) < 1 { + return "" + } + lbSourceRanges := make([]interface{}, len(service.Spec.LoadBalancerSourceRanges)) + for i, ip := range service.Spec.LoadBalancerSourceRanges { + lbSourceRanges[i] = ip + } + _ = unstructured.SetNestedSlice(values, lbSourceRanges, shortNameCamel, "loadBalancerSourceRanges") + return fmt.Sprintf(lbSourceRangesTempSpec, shortNameCamel) +} + type result struct { name string data string diff --git a/test_data/sample-app.yaml b/test_data/sample-app.yaml index d99c55d..d2399c8 100644 --- a/test_data/sample-app.yaml +++ b/test_data/sample-app.yaml @@ -138,6 +138,24 @@ spec: selector: app: myapp --- +apiVersion: v1 +kind: Service +metadata: + labels: + app: myapp + name: myapp-lb-service + namespace: my-ns +spec: + ports: + - name: https + port: 8443 + targetPort: https + selector: + app: myapp + type: LoadBalancer + loadBalancerSourceRanges: + - 10.0.0.0/8 +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: