Skip to content

Commit 369f0b3

Browse files
Greendor1234arttor
authored andcommitted
added parser for loadBalancerSourceRanges field
1 parent ad4eef7 commit 369f0b3

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "app.fullname" . }}-myapp-lb-service
5+
labels:
6+
app: myapp
7+
{{- include "app.labels" . | nindent 4 }}
8+
spec:
9+
type: {{ .Values.myappLbService.type }}
10+
selector:
11+
app: myapp
12+
{{- include "app.selectorLabels" . | nindent 4 }}
13+
ports:
14+
{{- .Values.myappLbService.ports | toYaml | nindent 2 }}
15+
loadBalancerSourceRanges:
16+
{{ - .Values.myappLbService.loadBalancerSourceRanges | toYaml | nindent 2 }}

examples/app/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ myapp:
8989
tag: v0.8.0
9090
replicas: 3
9191
revisionHistoryLimit: 5
92+
myappLbService:
93+
loadBalancerSourceRanges:
94+
- 10.0.0.0/8
95+
ports:
96+
- name: https
97+
port: 8443
98+
targetPort: https
99+
type: LoadBalancer
92100
myappPdb:
93101
minAvailable: 2
94102
myappService:

pkg/processor/service/service.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ spec:
3030
{{- .Values.%[1]s.ports | toYaml | nindent 2 }}`
3131
)
3232

33+
const (
34+
lbSourceRangesTempSpec = `
35+
loadBalancerSourceRanges:
36+
{{ - .Values.%[1]s.loadBalancerSourceRanges | toYaml | nindent 2 }}`
37+
)
38+
3339
var svcGVC = schema.GroupVersionKind{
3440
Group: "",
3541
Version: "v1",
@@ -97,6 +103,9 @@ func (r svc) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
97103

98104
_ = unstructured.SetNestedSlice(values, ports, shortNameCamel, "ports")
99105
res := meta + fmt.Sprintf(svcTempSpec, shortNameCamel, selector, appMeta.ChartName())
106+
107+
res += parseLoadBalancerSourceRanges(values, service, shortNameCamel)
108+
100109
if shortNameCamel == "webhookService" && appMeta.Config().AddWebhookOption {
101110
res = fmt.Sprintf("{{- if .Values.webhook.enabled }}\n%s\n{{- end }}", res)
102111
}
@@ -107,6 +116,18 @@ func (r svc) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
107116
}, nil
108117
}
109118

119+
func parseLoadBalancerSourceRanges(values helmify.Values, service corev1.Service, shortNameCamel string) string {
120+
if len(service.Spec.LoadBalancerSourceRanges) < 1 {
121+
return ""
122+
}
123+
lbSourceRanges := make([]interface{}, len(service.Spec.LoadBalancerSourceRanges))
124+
for i, ip := range service.Spec.LoadBalancerSourceRanges {
125+
lbSourceRanges[i] = ip
126+
}
127+
_ = unstructured.SetNestedSlice(values, lbSourceRanges, shortNameCamel, "loadBalancerSourceRanges")
128+
return fmt.Sprintf(lbSourceRangesTempSpec, shortNameCamel)
129+
}
130+
110131
type result struct {
111132
name string
112133
data string

test_data/sample-app.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ spec:
138138
selector:
139139
app: myapp
140140
---
141+
apiVersion: v1
142+
kind: Service
143+
metadata:
144+
labels:
145+
app: myapp
146+
name: myapp-lb-service
147+
namespace: my-ns
148+
spec:
149+
ports:
150+
- name: https
151+
port: 8443
152+
targetPort: https
153+
selector:
154+
app: myapp
155+
type: LoadBalancer
156+
loadBalancerSourceRanges:
157+
- 10.0.0.0/8
158+
---
141159
apiVersion: networking.k8s.io/v1
142160
kind: Ingress
143161
metadata:

0 commit comments

Comments
 (0)