Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[helm nats 1.x] add appProtocol to services #762

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion helm/charts/nats/files/headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ spec:
{{- range $protocol := list "nats" "leafnodes" "websocket" "mqtt" "cluster" "gateway" "monitor" "profiling" }}
{{- $configProtocol := get $.Values.config $protocol }}
{{- if or (eq $protocol "nats") $configProtocol.enabled }}
- {{ dict "name" $protocol "port" $configProtocol.port "targetPort" $protocol | toYaml | nindent 4 }}
{{- $tlsEnabled := false }}
{{- if hasKey $configProtocol "tls" }}
{{- $tlsEnabled = $configProtocol.tls.enabled }}
{{- else if eq $protocol "monitor" }}
{{- $tlsEnabled = $.Values.config.nats.tls.enabled }}
{{- end }}
{{- $appProtocol := or (eq $protocol "websocket") (eq $protocol "monitor") | ternary ($tlsEnabled | ternary "https" "http") ($tlsEnabled | ternary "tls" "tcp") }}
- {{ dict "name" $protocol "port" $configProtocol.port "targetPort" $protocol "appProtocol" $appProtocol | toYaml | nindent 4 }}
{{- end }}
{{- end }}
9 changes: 8 additions & 1 deletion helm/charts/nats/files/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ spec:
{{- $configProtocol := get $.Values.config $protocol }}
{{- $servicePort := get $.Values.service.ports $protocol }}
{{- if and (or (eq $protocol "nats") $configProtocol.enabled) $servicePort.enabled }}
- {{ merge (dict "name" $protocol "targetPort" $protocol) (omit $servicePort "enabled") (dict "port" $configProtocol.port) | toYaml | nindent 4 }}
{{- $tlsEnabled := false }}
{{- if hasKey $configProtocol "tls" }}
{{- $tlsEnabled = $configProtocol.tls.enabled }}
{{- else if eq $protocol "monitor" }}
{{- $tlsEnabled = $.Values.config.nats.tls.enabled }}
{{- end }}
{{- $appProtocol := or (eq $protocol "websocket") (eq $protocol "monitor") | ternary ($tlsEnabled | ternary "https" "http") ($tlsEnabled | ternary "tls" "tcp") }}
- {{ merge (dict "name" $protocol "targetPort" $protocol "appProtocol" $appProtocol) (omit $servicePort "enabled") (dict "port" $configProtocol.port) | toYaml | nindent 4 }}
{{- end }}
{{- end }}
204 changes: 117 additions & 87 deletions helm/charts/nats/test/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,22 @@ config:

expected.HeadlessService.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
{
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
AppProtocol: &appProtocolTCP,
},
{
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
AppProtocol: &appProtocolHTTP,
},
}

Expand Down Expand Up @@ -249,19 +252,22 @@ config:

expected.HeadlessService.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
{
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
AppProtocol: &appProtocolTCP,
},
{
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
AppProtocol: &appProtocolHTTP,
},
}

Expand Down Expand Up @@ -463,62 +469,73 @@ config:

expected.HeadlessService.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
{
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
AppProtocol: &appProtocolTCP,
},
{
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
AppProtocol: &appProtocolHTTP,
},
{
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
AppProtocol: &appProtocolTCP,
},
{
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
AppProtocol: &appProtocolTCP,
},
{
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
AppProtocol: &appProtocolTCP,
},
{
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
AppProtocol: &appProtocolHTTP,
},
}

expected.Service.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
{
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
AppProtocol: &appProtocolTCP,
},
{
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
AppProtocol: &appProtocolHTTP,
},
{
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
AppProtocol: &appProtocolTCP,
},
}

Expand Down Expand Up @@ -679,62 +696,73 @@ config:

expected.HeadlessService.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTLS,
},
{
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
AppProtocol: &appProtocolTLS,
},
{
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
AppProtocol: &appProtocolHTTPS,
},
{
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
AppProtocol: &appProtocolTLS,
},
{
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
Name: "cluster",
Port: 6222,
TargetPort: intstr.FromString("cluster"),
AppProtocol: &appProtocolTLS,
},
{
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
AppProtocol: &appProtocolTLS,
},
{
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
AppProtocol: &appProtocolHTTPS,
},
}

expected.Service.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTLS,
},
{
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
Name: "leafnodes",
Port: 7422,
TargetPort: intstr.FromString("leafnodes"),
AppProtocol: &appProtocolTLS,
},
{
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
Name: "websocket",
Port: 8080,
TargetPort: intstr.FromString("websocket"),
AppProtocol: &appProtocolHTTPS,
},
{
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
Name: "mqtt",
Port: 1883,
TargetPort: intstr.FromString("mqtt"),
AppProtocol: &appProtocolTLS,
},
}

Expand Down Expand Up @@ -842,6 +870,7 @@ extraResources:
- name: gateway
port: 7222
targetPort: gateway
appProtocol: tcp
- $tplYaml: |
apiVersion: v1
kind: ConfigMap
Expand All @@ -863,9 +892,10 @@ extraResources:
expected.ExtraService.HasValue = true
expected.ExtraService.Value.Spec.Ports = []corev1.ServicePort{
{
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
Name: "gateway",
Port: 7222,
TargetPort: intstr.FromString("gateway"),
AppProtocol: &appProtocolTCP,
},
}

Expand Down
29 changes: 19 additions & 10 deletions helm/charts/nats/test/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ type DynamicDefaultsGetter struct {
dd DynamicDefaults
}

var ddg DynamicDefaultsGetter
var (
ddg DynamicDefaultsGetter
appProtocolTCP = "tcp"
appProtocolTLS = "tls"
appProtocolHTTP = "http"
appProtocolHTTPS = "https"
)

func (d *DynamicDefaultsGetter) Get(t *testing.T) DynamicDefaults {
t.Helper()
Expand Down Expand Up @@ -159,14 +165,16 @@ func DefaultResources(t *testing.T, test *Test) *Resources {
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
{
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
Name: "monitor",
Port: 8222,
TargetPort: intstr.FromString("monitor"),
AppProtocol: &appProtocolHTTP,
},
},
Selector: natsSelectorLabels(),
Expand Down Expand Up @@ -392,9 +400,10 @@ exec sh -ec "$0"
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
Name: "nats",
Port: 4222,
TargetPort: intstr.FromString("nats"),
AppProtocol: &appProtocolTCP,
},
},
Selector: natsSelectorLabels(),
Expand Down
Loading