From 81ce16745fe911df6388b4ffc1acdf16d627e932 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Tue, 14 Nov 2023 15:14:54 -0500 Subject: [PATCH] Start adding to helm chart --- helm/solr-operator/templates/_helpers.tpl | 13 ++- helm/solr-operator/templates/_log_helpers.tpl | 79 +++++++++++++++++++ helm/solr-operator/templates/deployment.yaml | 17 +++- .../templates/log_rotation_configmap.yaml | 33 ++++++++ helm/solr-operator/values.yaml | 25 ++++++ main.go | 1 + 6 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 helm/solr-operator/templates/_log_helpers.tpl create mode 100644 helm/solr-operator/templates/log_rotation_configmap.yaml diff --git a/helm/solr-operator/templates/_helpers.tpl b/helm/solr-operator/templates/_helpers.tpl index a3e6ef1e..bc418169 100644 --- a/helm/solr-operator/templates/_helpers.tpl +++ b/helm/solr-operator/templates/_helpers.tpl @@ -93,6 +93,17 @@ Determine whether to use ClusterRoles or Roles {{- end -}} {{- end -}} +{{- define "solr-operator.volumeMounts" -}} +{{- include "solr-operator.mTLS.volumeMounts" . }} +{{- include "solr-operator.logging.volumeMounts" . }} +{{- end -}} + +{{- define "solr-operator.volumes" -}} +{{- include "solr-operator.mTLS.volumes" . }} +{{- include "solr-operator.logging.volumes" . }} +{{- end -}} + + {{/* mTLS vars */}} @@ -136,4 +147,4 @@ rootSolrCert.pem path: {{ include "solr-operator.mTLS.caCertName" . }} optional: false {{- end -}} -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/helm/solr-operator/templates/_log_helpers.tpl b/helm/solr-operator/templates/_log_helpers.tpl new file mode 100644 index 00000000..dde5359e --- /dev/null +++ b/helm/solr-operator/templates/_log_helpers.tpl @@ -0,0 +1,79 @@ +{{/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */}} + +{{/* vim: set filetype=mustache: */}} + + +{{/* +log file +*/}} + +{{- define "solr-operator.logging.fileMountDir" -}} +/var/logs/operator +{{- end -}} + +{{- define "solr-operator.logging.file" -}} +{{- if .Values.logging.file.enabled -}} +{{ include "solr-operator.logging.fileMountDir" . }}/{{ .Values.logging.file.path }} +{{- end -}} +{{- end -}} + + +{{/* +log file +*/}} +{{- define "solr-operator.logging.volumes" -}} +{{- if .Values.logging.file.enabled -}} +- {{ .Values.logging.file.volume | toYaml | nindent 2 }} +{{ include "solr-operator.logging.rotation.volume" . }} +{{- end -}} +{{- end -}} + +{{/* +log volume mounts +*/}} +{{- define "solr-operator.logging.volumeMounts" -}} +{{- if .Values.logging.file.enabled -}} +- name: {{ .Values.logging.file.volume.name }} + mountPath: {{ include "solr-operator.logging.fileMountDir" . }} + readOnly: false +{{ include "solr-operator.logging.rotation.volumeMount" . }} +{{- end -}} +{{- end -}} + +{{/* +log rotation +*/}} +{{- define "solr-operator.logging.rotation.configMapName" -}} +log-rotate-conf +{{- end -}} + +{{- define "solr-operator.logging.rotation.volumeMount" -}} +{{- if .Values.logging.file.enabled | and .Values.logging.file.rotation.enabled -}} +- name: {{ include "solr-operator.logging.rotation.configMapName" . }} + mountPath: /etc/logrotate.d/ + readOnly: true +{{- end -}} + +{{- end -}} +{{- define "solr-operator.logging.rotation.volume" -}} +{{- if .Values.logging.file.enabled | and .Values.logging.file.rotation.enabled -}} +- name: {{ include "solr-operator.logging.rotation.configMapName" . }} + configMap: + name: {{ include "solr-operator.logging.rotation.configMapName" . }} +{{- end -}} +{{- end -}} diff --git a/helm/solr-operator/templates/deployment.yaml b/helm/solr-operator/templates/deployment.yaml index 6dd905e6..a0947ffb 100644 --- a/helm/solr-operator/templates/deployment.yaml +++ b/helm/solr-operator/templates/deployment.yaml @@ -55,6 +55,11 @@ spec: {{- if .Values.watchNamespaces }} - --watch-namespaces={{- include "solr-operator.watchNamespaces" . -}} {{- end }} + {{- with ( include "solr-operator.logging.file" .) }} + {{- if . }} + - --log-file={{- . -}} + {{- end }} + {{- end }} {{- if .Values.mTLS.clientCertSecret }} - --tls-client-cert-path={{- include "solr-operator.mTLS.clientCertDirectory" . -}}/tls.crt - --tls-client-cert-key-path={{- include "solr-operator.mTLS.clientCertDirectory" . -}}/tls.key @@ -106,9 +111,11 @@ spec: resources: {{- toYaml .Values.resources | nindent 10 }} - {{- if (include "solr-operator.mTLS.volumeMounts" .) }} + {{- with include "solr-operator.volumeMounts" . }} + {{- if . }} volumeMounts: - {{- include "solr-operator.mTLS.volumeMounts" . | nindent 10 }} + {{- . | nindent 10 }} + {{- end }} {{- end }} {{- if .Values.metrics.enable }} @@ -116,9 +123,11 @@ spec: - containerPort: 8080 name: metrics {{- end }} - {{- if (include "solr-operator.mTLS.volumes" .) }} + {{- with include "solr-operator.volumes" . }} + {{- if . }} volumes: - {{- include "solr-operator.mTLS.volumes" . | nindent 8 }} + {{- . | nindent 8 }} + {{- end }} {{- end }} {{- if .Values.sidecarContainers }} diff --git a/helm/solr-operator/templates/log_rotation_configmap.yaml b/helm/solr-operator/templates/log_rotation_configmap.yaml new file mode 100644 index 00000000..7b078996 --- /dev/null +++ b/helm/solr-operator/templates/log_rotation_configmap.yaml @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{{- if .Values.logging.file.enabled | and .Values.logging.file.rotation.enabled }} +--- +# config for doing log rotation in the Solr Operator pod +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "solr-operator.logging.rotation.configMapName" . }} + namespace: {{ .Release.Namespace }} +data: +solr-operator: | + {{ include "solr-operator.logging.file" . }} { + rotate {{ .Values.logging.file.rotation.numOldFilesToKeep | default 0 }} + size {{ .Values.logging.file.rotation.maxFileSize | default "10m"}} + nocompress + missingok + notifempty + } +{{- end }} diff --git a/helm/solr-operator/values.yaml b/helm/solr-operator/values.yaml index 300c64d8..7fca2e72 100644 --- a/helm/solr-operator/values.yaml +++ b/helm/solr-operator/values.yaml @@ -90,3 +90,28 @@ mTLS: # Enable metrics for the Solr Operator metrics: enable: true + +# Logging settings for the Solr Operator +logging: + # Log to a file in addition to stdErr + file: + # Whether to enable logging to a file + enabled: true + # The path of the log file within the volume + path: "operator.log" + + # The volume that will be used to store the log file(s) + volume: + name: logs + emptyDir: + sizeLimit: 100Mi + + # The log rotation policy + rotation: + enabled: true + numOldFilesToKeep: 3 + maxFileSize: 20M + emptyDir: + sizeLimit: 100Mi + + diff --git a/main.go b/main.go index 962ccce1..715dbfde 100644 --- a/main.go +++ b/main.go @@ -149,6 +149,7 @@ func main() { if version.VersionSuffix != "" { fullVersion += "-" + version.VersionSuffix } + setupLog.Info("Writing logs to file", "path", logFile) setupLog.Info(fmt.Sprintf("solr-operator Version: %v", fullVersion)) setupLog.Info(fmt.Sprintf("solr-operator Git SHA: %s", version.GitSHA)) setupLog.Info(fmt.Sprintf("solr-operator Build Time: %s", version.BuildTime))