diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index bb15612d..9b51b266 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -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 } diff --git a/resources/nats/templates/configmap.yaml b/resources/nats/templates/configmap.yaml index 52502014..e1b28185 100644 --- a/resources/nats/templates/configmap.yaml +++ b/resources/nats/templates/configmap.yaml @@ -24,7 +24,8 @@ data: # # ############### http: 8222 - server_name: $POD_NAME + http_port: 8222, + server_name: $SERVER_NAME ################################### # # @@ -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 }} @@ -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 }} diff --git a/resources/nats/templates/statefulset.yaml b/resources/nats/templates/statefulset.yaml index 11c38c43..9d5e4bd2 100644 --- a/resources/nats/templates/statefulset.yaml +++ b/resources/nats/templates/statefulset.yaml @@ -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 @@ -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" @@ -140,6 +145,7 @@ spec: resources: {{- toYaml .Values.exporter.resources | nindent 10 }} args: + - -port=7777 - -connz - -routez - -subz @@ -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 }} diff --git a/resources/nats/values.yaml b/resources/nats/values.yaml index 54a1adf3..c3d94ca4 100644 --- a/resources/nats/values.yaml +++ b/resources/nats/values.yaml @@ -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 @@ -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 @@ -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 diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index 02cfe25f..ddb761f1 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -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 } @@ -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") }