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] config.serverNamePrefix option #732

Merged
merged 1 commit into from
Jun 13, 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
2 changes: 1 addition & 1 deletion helm/charts/nats/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- nats
- messaging
- cncf
version: 1.0.0-beta.5
version: 1.0.0-beta.6
home: http://github.com/nats-io/k8s
maintainers:
- email: info@nats.io
Expand Down
2 changes: 1 addition & 1 deletion helm/charts/nats/files/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $pidFile := ternary "/var/run/nats/nats.pid" "/var/run/nats.pid" .Values.reloader.enabled }}
{{- with .Values.config }}

server_name: << $POD_NAME >>
server_name: << $SERVER_NAME >>
lame_duck_grace_period: 10s
lame_duck_duration: 30s
pid_file: {{ $pidFile }}
Expand Down
16 changes: 0 additions & 16 deletions helm/charts/nats/files/stateful-set/beta2-mount-fix-container.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions helm/charts/nats/files/stateful-set/nats-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ env:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: SERVER_NAME
value: {{ printf "%s$(POD_NAME)" .Values.config.serverNamePrefix | quote }}
{{- with .Values.container.env }}
{{- include "nats.env" . }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions helm/charts/nats/test/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func HelmRender(t *testing.T, test *Test) *Resources {
}

_ = os.Setenv("POD_NAME", "nats-0")
_ = os.Setenv("SERVER_NAME", "nats-0")
resources.Conf.Value, err = conf.ParseFile(filepath.Join(confDir, "nats.conf"))
require.NoError(t, err)
resources.Conf.HasValue = true
Expand Down
9 changes: 6 additions & 3 deletions helm/charts/nats/test/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ config:
pvc:
size: 5Gi
storageClassName: gp3
serverNamePrefix: test_
`
expected := DefaultResources(t, test)

Expand Down Expand Up @@ -211,16 +212,18 @@ config:
},
}

vm := expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts
expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts = append(vm, corev1.VolumeMount{
ctr := &expected.StatefulSet.Value.Spec.Template.Spec.Containers[0]
ctr.Env[1].Value = "test_$(POD_NAME)"

ctr.VolumeMounts = append(ctr.VolumeMounts, corev1.VolumeMount{
MountPath: "/mnt",
Name: test.FullName + "-js",
}, corev1.VolumeMount{
MountPath: "/mnt/resolver",
Name: test.FullName + "-resolver",
})

expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{
ctr.Ports = []corev1.ContainerPort{
{
Name: "nats",
ContainerPort: 4222,
Expand Down
4 changes: 4 additions & 0 deletions helm/charts/nats/test/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ exec sh -ec "$0"
},
},
},
{
Name: "SERVER_NAME",
Value: "$(POD_NAME)",
},
},
Image: dd.NatsImage,
Lifecycle: &corev1.Lifecycle{
Expand Down
4 changes: 4 additions & 0 deletions helm/charts/nats/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ config:
merge: {}
patch: []

# adds a prefix to the server name, which defaults to the pod name
# helpful for ensuring server name is unique in a super cluster
serverNamePrefix: ""

# merge or patch the nats config
# https://docs.nats.io/running-a-nats-service/configuration
# following special rules apply
Expand Down