diff --git a/helm/charts/nats/Chart.yaml b/helm/charts/nats/Chart.yaml index 67c7f8a6..3e9b61b0 100644 --- a/helm/charts/nats/Chart.yaml +++ b/helm/charts/nats/Chart.yaml @@ -6,7 +6,7 @@ keywords: - nats - messaging - cncf -version: 1.0.0-beta.2 +version: 1.0.0-beta.3 home: http://github.com/nats-io/k8s maintainers: - email: info@nats.io diff --git a/helm/charts/nats/README.md b/helm/charts/nats/README.md index 25091ab7..7a8dfc6b 100644 --- a/helm/charts/nats/README.md +++ b/helm/charts/nats/README.md @@ -15,6 +15,9 @@ helm repo add nats https://nats-io.github.io/k8s/helm/charts/ helm upgrade --install nats nats/nats --devel ``` +## 1.x Beta Upgrade Notes +- If using `1.0.0-beta.2` or lower with JetStream enabled, upgrade to `1.0.0-beta.3` first + ## Values There are a handful of explicitly defined options which are documented with comments in the [values.yaml](values.yaml) file. @@ -113,6 +116,7 @@ podTemplate: topologySpreadConstraints: kubernetes.io/hostname: maxSkew: 1 + whenUnsatisfiable: DoNotSchedule ``` ### NATS Container Resources diff --git a/helm/charts/nats/files/config/jetstream.yaml b/helm/charts/nats/files/config/jetstream.yaml index cd8ba3d9..17262f64 100644 --- a/helm/charts/nats/files/config/jetstream.yaml +++ b/helm/charts/nats/files/config/jetstream.yaml @@ -11,8 +11,10 @@ max_memory_store: 0 {{- with .fileStore }} {{- if .enabled }} store_dir: {{ .dir }} -{{- with .maxSize }} -max_file_store: << {{ . }} >> +{{- if .maxSize }} +max_file_store: << {{ .maxSize }} >> +{{- else if .pvc.enabled }} +max_file_store: << {{ .pvc.size }} >> {{- end }} {{- else }} max_file_store: 0 diff --git a/helm/charts/nats/files/stateful-set/beta2-mount-fix-container.yaml b/helm/charts/nats/files/stateful-set/beta2-mount-fix-container.yaml new file mode 100644 index 00000000..8c2c2b7d --- /dev/null +++ b/helm/charts/nats/files/stateful-set/beta2-mount-fix-container.yaml @@ -0,0 +1,16 @@ +name: beta2-mount-fix +{{ include "nats.image" (merge (pick $.Values "global") .Values.natsBox.container.image) }} + +command: +- sh +- -ec +- | + cd {{ .Values.config.jetstream.fileStore.dir | quote }} + mkdir -p jetstream + find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; + +volumeMounts: +{{- with .Values.config.jetstream.fileStore }} +- name: {{ .pvc.name }} + mountPath: {{ .dir | quote }} +{{- end }} diff --git a/helm/charts/nats/files/stateful-set/nats-container.yaml b/helm/charts/nats/files/stateful-set/nats-container.yaml index c5916821..3bbc27ae 100644 --- a/helm/charts/nats/files/stateful-set/nats-container.yaml +++ b/helm/charts/nats/files/stateful-set/nats-container.yaml @@ -73,7 +73,7 @@ volumeMounts: {{- if and .enabled .fileStore.enabled .fileStore.pvc.enabled }} {{- with .fileStore }} - name: {{ .pvc.name }} - mountPath: {{ printf "%s/jetstream" .dir | quote }} + mountPath: {{ .dir | quote }} {{- end }} {{- end }} {{- end }} diff --git a/helm/charts/nats/files/stateful-set/pod-template.yaml b/helm/charts/nats/files/stateful-set/pod-template.yaml index d58f91fd..7c056eb6 100644 --- a/helm/charts/nats/files/stateful-set/pod-template.yaml +++ b/helm/charts/nats/files/stateful-set/pod-template.yaml @@ -7,6 +7,15 @@ metadata: checksum/config: {{ sha256sum $configMap }} {{- end }} spec: + {{- with .Values.config.jetstream }} + {{- if and .enabled .fileStore.enabled .fileStore.pvc.enabled }} + # just for 1.0.0-beta.3 + # add an init container in order to fix mount from <= 1.0.0-beta.2 + initContainers: + - {{ include "nats.loadMergePatch" (merge (dict "file" "stateful-set/beta2-mount-fix-container.yaml" "ctx" $) dict) | nindent 4 }} + {{- end }} + {{- end }} + containers: # nats {{- $nats := dict }} diff --git a/helm/charts/nats/templates/_helpers.tpl b/helm/charts/nats/templates/_helpers.tpl index 91671311..aa37461c 100644 --- a/helm/charts/nats/templates/_helpers.tpl +++ b/helm/charts/nats/templates/_helpers.tpl @@ -192,8 +192,8 @@ output: JSON encoded map with 1 key: */}} {{- define "nats.loadMergePatch" -}} {{- $doc := tpl (.ctx.Files.Get (printf "files/%s" .file)) .ctx | fromYaml | default dict -}} -{{- $doc = mergeOverwrite $doc (deepCopy .merge) -}} -{{- get (include "jsonpatch" (dict "doc" $doc "patch" .patch) | fromJson ) "doc" | toYaml -}} +{{- $doc = mergeOverwrite $doc (deepCopy (.merge | default dict)) -}} +{{- get (include "jsonpatch" (dict "doc" $doc "patch" (.patch | default list)) | fromJson ) "doc" | toYaml -}} {{- end }} diff --git a/helm/charts/nats/test/config_test.go b/helm/charts/nats/test/config_test.go index 6f36eed5..647a9efa 100644 --- a/helm/charts/nats/test/config_test.go +++ b/helm/charts/nats/test/config_test.go @@ -56,6 +56,7 @@ config: }, } expected.Conf.Value["jetstream"] = map[string]any{ + "max_file_store": int64(10737418240), "max_memory_store": int64(0), "store_dir": "/data", } @@ -65,7 +66,7 @@ config: vm := expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts = append(vm, corev1.VolumeMount{ - MountPath: "/data/jetstream", + MountPath: "/data", Name: test.FullName + "-js", }) @@ -88,6 +89,29 @@ config: }, } + nbc := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0] + expected.StatefulSet.Value.Spec.Template.Spec.InitContainers = []corev1.Container{ + { + Command: []string{ + "sh", + "-ec", + `cd "/data" +mkdir -p jetstream +find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; +`, + }, + Image: nbc.Image, + ImagePullPolicy: nbc.ImagePullPolicy, + Name: "beta2-mount-fix", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/data", + Name: test.FullName + "-js", + }, + }, + }, + } + expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{ { Name: "nats", @@ -210,9 +234,32 @@ config: }, } + nbc := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0] + expected.StatefulSet.Value.Spec.Template.Spec.InitContainers = []corev1.Container{ + { + Command: []string{ + "sh", + "-ec", + `cd "/mnt" +mkdir -p jetstream +find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; +`, + }, + Image: nbc.Image, + ImagePullPolicy: nbc.ImagePullPolicy, + Name: "beta2-mount-fix", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/mnt", + Name: test.FullName + "-js", + }, + }, + }, + } + vm := expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts = append(vm, corev1.VolumeMount{ - MountPath: "/mnt/jetstream", + MountPath: "/mnt", Name: test.FullName + "-js", }, corev1.VolumeMount{ MountPath: "/mnt/resolver", @@ -370,7 +417,7 @@ config: vm := expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts = append(vm, corev1.VolumeMount{ - MountPath: "/data/jetstream", + MountPath: "/data", Name: test.FullName + "-js", }, corev1.VolumeMount{ MountPath: "/data/resolver", @@ -417,6 +464,29 @@ config: }, } + nbc := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0] + expected.StatefulSet.Value.Spec.Template.Spec.InitContainers = []corev1.Container{ + { + Command: []string{ + "sh", + "-ec", + `cd "/data" +mkdir -p jetstream +find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; +`, + }, + Image: nbc.Image, + ImagePullPolicy: nbc.ImagePullPolicy, + Name: "beta2-mount-fix", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/data", + Name: test.FullName + "-js", + }, + }, + }, + } + expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{ { Name: "nats", @@ -737,7 +807,7 @@ config: jetstream: enabled: true merge: - 000$include: "js.conf" + zzz$include: "js.conf" merge: $include: "my-config.conf" zzz$include: "my-config-last.conf" @@ -780,7 +850,7 @@ max_outstanding_catchup: 64MB vm := expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].VolumeMounts = append(vm, corev1.VolumeMount{ - MountPath: "/data/jetstream", + MountPath: "/data", Name: test.FullName + "-js", }) @@ -803,6 +873,29 @@ max_outstanding_catchup: 64MB }, } + nbc := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0] + expected.StatefulSet.Value.Spec.Template.Spec.InitContainers = []corev1.Container{ + { + Command: []string{ + "sh", + "-ec", + `cd "/data" +mkdir -p jetstream +find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; +`, + }, + Image: nbc.Image, + ImagePullPolicy: nbc.ImagePullPolicy, + Name: "beta2-mount-fix", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/data", + Name: test.FullName + "-js", + }, + }, + }, + } + RenderAndCheck(t, test, expected) } diff --git a/helm/charts/nats/test/resources_test.go b/helm/charts/nats/test/resources_test.go index de7ee22e..3f5d36ad 100644 --- a/helm/charts/nats/test/resources_test.go +++ b/helm/charts/nats/test/resources_test.go @@ -51,7 +51,7 @@ reloader: key: token natsVolumeMountPrefixes: - /etc/ - - /data/ + - /data promExporter: enabled: true port: 7778 @@ -101,6 +101,7 @@ natsBox: expected := DefaultResources(t, test) expected.Conf.Value["jetstream"] = map[string]any{ + "max_file_store": int64(10737418240), "max_memory_store": int64(0), "store_dir": "/data", } @@ -141,7 +142,7 @@ natsBox: ctr[0].ImagePullPolicy = "IfNotPresent" ctr[0].VolumeMounts = append(ctr[0].VolumeMounts, corev1.VolumeMount{ Name: test.FullName + "-js", - MountPath: "/data/jetstream", + MountPath: "/data", }) // reloader @@ -150,7 +151,7 @@ natsBox: ctr[1].ImagePullPolicy = "Always" ctr[1].VolumeMounts = append(ctr[1].VolumeMounts, corev1.VolumeMount{ Name: test.FullName + "-js", - MountPath: "/data/jetstream", + MountPath: "/data", }) // promExporter @@ -308,6 +309,29 @@ natsBox: }, } + nbc := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0] + expected.StatefulSet.Value.Spec.Template.Spec.InitContainers = []corev1.Container{ + { + Command: []string{ + "sh", + "-ec", + `cd "/data" +mkdir -p jetstream +find . -maxdepth 1 -mindepth 1 -not -name 'lost+found' -not -name 'jetstream' -exec mv {} jetstream \; +`, + }, + Image: nbc.Image, + ImagePullPolicy: nbc.ImagePullPolicy, + Name: "beta2-mount-fix", + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: "/data", + Name: test.FullName + "-js", + }, + }, + }, + } + expected.StatefulSet.Value.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{ { Name: "nats", diff --git a/helm/charts/nats/values.yaml b/helm/charts/nats/values.yaml index 7894f303..f8fbfc89 100644 --- a/helm/charts/nats/values.yaml +++ b/helm/charts/nats/values.yaml @@ -50,7 +50,6 @@ config: fileStore: enabled: true - # disk will be mounted to