Skip to content

Commit

Permalink
Upgrade NATS Server to 2.10.7 and helm chart configs (#273)
Browse files Browse the repository at this point in the history
* upgrade NATS Server to 2.10.7 and helm chart configs

* fixed tests

* turned no_advetise on and remove cluster_advertise

* fixed tests

* fixed tests

* updated resources

* added comment
  • Loading branch information
mfaizanse authored Jan 19, 2024
1 parent dfc64bb commit 9d2e28e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
38 changes: 34 additions & 4 deletions e2e/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,49 @@ func Test_ConfigMap(t *testing.T) {

cmMap := cmToMap(cm.Data["nats.conf"])

if err := checkValueInCMMap(cmMap, "max_file", FileStorageSize); err != nil {
if err := checkValueInCMMap(cmMap, "debug", True); err != nil {
return err
}

if err := checkValueInCMMap(cmMap, "max_mem", MemStorageSize); err != nil {
if err := checkValueInCMMap(cmMap, "trace", True); err != nil {
return err
}

if err := checkValueInCMMap(cmMap, "debug", True); err != nil {
// **********************
// TODO: remove this section when NATS server 2.10.x is released.
// `max_file` is changed to `max_file_store` in NATS 2.10.x.
// `max_mem` is changed to `max_memory_store` in NATS 2.10.x.
// To check the correct key in configMap,
// fetch the NATS statefulSet and get the NATS server version.
// And then based on the version, check the expected key.
sts, stsErr := clientSet.AppsV1().StatefulSets(NamespaceName).Get(ctx, STSName, metav1.GetOptions{})
if stsErr != nil {
return stsErr
}

imageName := ""
for _, c := range sts.Spec.Template.Spec.Containers {
if c.Name == ContainerName {
imageName = c.Image
}
}
if strings.Contains(imageName, "2.9.") {
if err := checkValueInCMMap(cmMap, "max_file", FileStorageSize); err != nil {
return err
}

if err := checkValueInCMMap(cmMap, "max_mem", MemStorageSize); err != nil {
return err
}
return nil
}
// **********************

if err := checkValueInCMMap(cmMap, "max_file_store", FileStorageSize); err != nil {
return err
}

if err := checkValueInCMMap(cmMap, "trace", True); err != nil {
if err := checkValueInCMMap(cmMap, "max_memory_store", MemStorageSize); err != nil {
return err
}

Expand Down
9 changes: 5 additions & 4 deletions resources/nats/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ data:
# #
###############
http: 8222
server_name: $POD_NAME
http_port: 8222,
server_name: $SERVER_NAME
###################################
# #
Expand All @@ -41,7 +42,7 @@ data:
{{- end}}
{{- if .Values.nats.jetstream.memStorage.enabled }}
max_mem: {{ .Values.nats.jetstream.memStorage.size }}
max_memory_store: {{ .Values.nats.jetstream.memStorage.size }}
{{- end }}
{{- if .Values.nats.jetstream.domain }}
Expand All @@ -52,9 +53,9 @@ data:
store_dir: {{ .Values.nats.jetstream.fileStorage.storageDirectory }}
{{- if .Values.nats.jetstream.fileStorage.existingClaim }}
max_file: {{ .Values.nats.jetstream.fileStorage.claimStorageSize }}
max_file_store: {{ .Values.nats.jetstream.fileStorage.claimStorageSize }}
{{- else }}
max_file: {{ .Values.global.jetstream.fileStorage.size }}
max_file_store: {{ .Values.global.jetstream.fileStorage.size }}
{{- end }}
{{- end }}
Expand Down
8 changes: 8 additions & 0 deletions resources/nats/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ spec:
claimName: {{ .Values.nats.jetstream.fileStorage.existingClaim | quote }}
{{- end }}

# disable service environment variables
# service discovery uses DNS; don't need service env vars
enableServiceLinks: false
# Required to be able to HUP signal and apply config
# reload to the server without restarting the pod.
shareProcessNamespace: true
Expand All @@ -109,6 +112,8 @@ spec:
{{- if .Values.containerSecurityContext }}
securityContext: {{- toYaml .Values.containerSecurityContext | nindent 10 }}
{{- end }}
resources:
{{- toYaml .Values.reloader.resources | nindent 10 }}
command:
- "nats-server-config-reloader"
- "-pid"
Expand Down Expand Up @@ -140,6 +145,7 @@ spec:
resources:
{{- toYaml .Values.exporter.resources | nindent 10 }}
args:
- -port=7777
- -connz
- -routez
- -subz
Expand Down Expand Up @@ -209,6 +215,8 @@ spec:
fieldPath: metadata.namespace
- name: CLUSTER_ADVERTISE
value: {{ include "nats.clusterAdvertise" . }}
- name: SERVER_NAME
value: $(POD_NAME)

{{- with .Values.nats.jetstream.encryption }}
{{- with .secret }}
Expand Down
24 changes: 20 additions & 4 deletions resources/nats/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ global:
images:
nats:
name: nats
version: v20230620-2.9.18-alpine3.18
version: v20240102-2.10.7-alpine3.18
directory: prod/external
nats_config_reloader:
name: natsio/nats-server-config-reloader
version: 0.14.0
version: 0.14.1
directory: prod/external
prometheus_nats_exporter:
name: natsio/prometheus-nats-exporter
Expand Down Expand Up @@ -139,7 +139,7 @@ nats:
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 30
failureThreshold: 90

# Adds a hash of the ConfigMap as a pod annotation
# This will cause the StatefulSet to roll when the ConfigMap is updated
Expand Down Expand Up @@ -330,4 +330,20 @@ commonAnnotations: {}
exporter:
enabled: true
pullPolicy: IfNotPresent
resources: {}
resources:
limits:
cpu: 50m
memory: 32Mi
requests:
cpu: 10m
memory: 20Mi

# NATS config reloader sidecar.
reloader:
resources:
limits:
cpu: 50m
memory: 32Mi
requests:
cpu: 10m
memory: 20Mi
4 changes: 2 additions & 2 deletions testutils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats
}

// check if file storage size is correctly defined in NATS config.
if !strings.Contains(natsConfigStr, fmt.Sprintf("max_file: %s", nats.Spec.FileStorage.Size.String())) {
if !strings.Contains(natsConfigStr, fmt.Sprintf("max_file_store: %s", nats.Spec.FileStorage.Size.String())) {
return false
}

Expand Down Expand Up @@ -529,7 +529,7 @@ func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats
}

// check if mem storage size is correctly defined in NATS config.
return strings.Contains(natsConfigStr, fmt.Sprintf("max_mem: %s", nats.Spec.MemStorage.Size.String()))
return strings.Contains(natsConfigStr, fmt.Sprintf("max_memory_store: %s", nats.Spec.MemStorage.Size.String()))
}, SmallTimeOut, SmallPollingInterval, "failed to ensure NATS CR Spec.jetStream.memStorage")
}

Expand Down

0 comments on commit 9d2e28e

Please sign in to comment.