Skip to content

Commit

Permalink
[nats helm 1.x] fix JS mount
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
Caleb Lloyd committed May 9, 2023
1 parent d597864 commit 0ee6f94
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 12 deletions.
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.2
version: 1.0.0-beta.3
home: http://github.com/nats-io/k8s
maintainers:
- email: [email protected]
Expand Down
3 changes: 3 additions & 0 deletions helm/charts/nats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions helm/charts/nats/files/stateful-set/beta2-mount-fix-container.yaml
Original file line number Diff line number Diff line change
@@ -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 echo mv {} jetstream \;
volumeMounts:
{{- with .Values.config.jetstream.fileStore }}
- name: {{ .pvc.name }}
mountPath: {{ .dir | quote }}
{{- end }}
2 changes: 1 addition & 1 deletion helm/charts/nats/files/stateful-set/nats-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 9 additions & 0 deletions helm/charts/nats/files/stateful-set/pod-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions helm/charts/nats/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}


Expand Down
100 changes: 96 additions & 4 deletions helm/charts/nats/test/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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",
})

Expand All @@ -88,6 +88,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 echo 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",
Expand Down Expand Up @@ -210,9 +233,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 echo 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",
Expand Down Expand Up @@ -370,7 +416,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",
Expand Down Expand Up @@ -417,6 +463,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 echo 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",
Expand Down Expand Up @@ -780,7 +849,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",
})

Expand All @@ -803,6 +872,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 echo 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)
}

Expand Down
29 changes: 26 additions & 3 deletions helm/charts/nats/test/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ reloader:
key: token
natsVolumeMountPrefixes:
- /etc/
- /data/
- /data
promExporter:
enabled: true
port: 7778
Expand Down Expand Up @@ -141,7 +141,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
Expand All @@ -150,7 +150,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
Expand Down Expand Up @@ -308,6 +308,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 echo 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",
Expand Down
1 change: 0 additions & 1 deletion helm/charts/nats/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ config:

fileStore:
enabled: true
# disk will be mounted to <dir>/jetstream
dir: /data

############################################################
Expand Down

0 comments on commit 0ee6f94

Please sign in to comment.