From df5cc2663eaaef317e9e9a7b9e48ef25c982efcc Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 7 Jun 2023 22:13:41 +0530 Subject: [PATCH 01/12] Added logLevel field for components --- .../create-federation-secret-job.yaml | 2 +- .../gossip-encryption-autogenerate-job.yaml | 2 +- .../ingress-gateways-deployment.yaml | 2 +- .../templates/mesh-gateway-deployment.yaml | 2 +- .../server-acl-init-cleanup-job.yaml | 2 +- .../consul/templates/server-acl-init-job.yaml | 2 +- .../telemetry-collector-deployment.yaml | 2 +- .../terminating-gateways-deployment.yaml | 2 +- charts/consul/templates/tls-init-job.yaml | 2 +- .../unit/create-federation-secret-job.bats | 38 +++++++++++++++++++ .../gossip-encryption-autogenerate-job.bats | 30 +++++++++++++++ .../unit/ingress-gateways-deployment.bats | 32 ++++++++++++++++ .../test/unit/mesh-gateway-deployment.bats | 32 ++++++++++++++++ .../unit/server-acl-init-cleanup-job.bats | 30 +++++++++++++++ .../consul/test/unit/server-acl-init-job.bats | 30 +++++++++++++++ .../unit/telemetry-collector-deployment.bats | 30 +++++++++++++++ .../unit/terminating-gateways-deployment.bats | 32 ++++++++++++++++ charts/consul/test/unit/tls-init-job.bats | 30 +++++++++++++++ charts/consul/values.yaml | 27 +++++++++++++ 19 files changed, 320 insertions(+), 9 deletions(-) diff --git a/charts/consul/templates/create-federation-secret-job.yaml b/charts/consul/templates/create-federation-secret-job.yaml index 4f83a1f82a..bc3e0a988b 100644 --- a/charts/consul/templates/create-federation-secret-job.yaml +++ b/charts/consul/templates/create-federation-secret-job.yaml @@ -119,7 +119,7 @@ spec: - "-ec" - | consul-k8s-control-plane create-federation-secret \ - -log-level={{ .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.global.federation.logLevel }} \ -log-json={{ .Values.global.logJSON }} \ {{- if (or .Values.global.gossipEncryption.autoGenerate (and .Values.global.gossipEncryption.secretName .Values.global.gossipEncryption.secretKey)) }} -gossip-key-file=/consul/gossip/gossip.key \ diff --git a/charts/consul/templates/gossip-encryption-autogenerate-job.yaml b/charts/consul/templates/gossip-encryption-autogenerate-job.yaml index 9d296478a1..87c579cd54 100644 --- a/charts/consul/templates/gossip-encryption-autogenerate-job.yaml +++ b/charts/consul/templates/gossip-encryption-autogenerate-job.yaml @@ -56,7 +56,7 @@ spec: -namespace={{ .Release.Namespace }} \ -secret-name={{ template "consul.fullname" . }}-gossip-encryption-key \ -secret-key="key" \ - -log-level={{ .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.global.gossipEncryption.logLevel }} \ -log-json={{ .Values.global.logJSON }} resources: requests: diff --git a/charts/consul/templates/ingress-gateways-deployment.yaml b/charts/consul/templates/ingress-gateways-deployment.yaml index 4f72031855..e6335d2c4e 100644 --- a/charts/consul/templates/ingress-gateways-deployment.yaml +++ b/charts/consul/templates/ingress-gateways-deployment.yaml @@ -211,7 +211,7 @@ spec: -gateway-kind="ingress-gateway" \ -proxy-id-file=/consul/service/proxy-id \ -service-name={{ template "consul.fullname" $root }}-{{ .name }} \ - -log-level={{ default $root.Values.global.logLevel }} \ + -log-level={{ default $root.Values.global.logLevel $root.Values.ingressGateways.logLevel }} \ -log-json={{ $root.Values.global.logJSON }} volumeMounts: - name: consul-service diff --git a/charts/consul/templates/mesh-gateway-deployment.yaml b/charts/consul/templates/mesh-gateway-deployment.yaml index 449d6ae492..8fd77946fd 100644 --- a/charts/consul/templates/mesh-gateway-deployment.yaml +++ b/charts/consul/templates/mesh-gateway-deployment.yaml @@ -161,7 +161,7 @@ spec: -gateway-kind="mesh-gateway" \ -proxy-id-file=/consul/service/proxy-id \ -service-name={{ .Values.meshGateway.consulServiceName }} \ - -log-level={{ default .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.meshGateway.logLevel }} \ -log-json={{ .Values.global.logJSON }} volumeMounts: - name: consul-service diff --git a/charts/consul/templates/server-acl-init-cleanup-job.yaml b/charts/consul/templates/server-acl-init-cleanup-job.yaml index 35b0877ab4..eae111bc98 100644 --- a/charts/consul/templates/server-acl-init-cleanup-job.yaml +++ b/charts/consul/templates/server-acl-init-cleanup-job.yaml @@ -57,7 +57,7 @@ spec: - consul-k8s-control-plane args: - delete-completed-job - - -log-level={{ .Values.global.logLevel }} + - -log-level={{ default .Values.global.logLevel .Values.server.logLevel }} - -log-json={{ .Values.global.logJSON }} - -k8s-namespace={{ .Release.Namespace }} - {{ template "consul.fullname" . }}-server-acl-init diff --git a/charts/consul/templates/server-acl-init-job.yaml b/charts/consul/templates/server-acl-init-job.yaml index e62db41ec2..c94982cca3 100644 --- a/charts/consul/templates/server-acl-init-job.yaml +++ b/charts/consul/templates/server-acl-init-job.yaml @@ -161,7 +161,7 @@ spec: CONSUL_FULLNAME="{{template "consul.fullname" . }}" consul-k8s-control-plane server-acl-init \ - -log-level={{ .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.server.logLevel}} \ -log-json={{ .Values.global.logJSON }} \ -resource-prefix=${CONSUL_FULLNAME} \ -k8s-namespace={{ .Release.Namespace }} \ diff --git a/charts/consul/templates/telemetry-collector-deployment.yaml b/charts/consul/templates/telemetry-collector-deployment.yaml index 62b8868f1f..44d0792835 100644 --- a/charts/consul/templates/telemetry-collector-deployment.yaml +++ b/charts/consul/templates/telemetry-collector-deployment.yaml @@ -115,7 +115,7 @@ spec: - -ec - |- consul-k8s-control-plane connect-init -pod-name=${POD_NAME} -pod-namespace=${POD_NAMESPACE} \ - -log-level={{ default .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.telemetryCollector.logLevel }} \ -log-json={{ .Values.global.logJSON }} \ -service-account-name="consul-telemetry-collector" \ -service-name="" \ diff --git a/charts/consul/templates/terminating-gateways-deployment.yaml b/charts/consul/templates/terminating-gateways-deployment.yaml index 2f2cb9a921..290b285949 100644 --- a/charts/consul/templates/terminating-gateways-deployment.yaml +++ b/charts/consul/templates/terminating-gateways-deployment.yaml @@ -196,7 +196,7 @@ spec: -gateway-kind="terminating-gateway" \ -proxy-id-file=/consul/service/proxy-id \ -service-name={{ .name }} \ - -log-level={{ default $root.Values.global.logLevel }} \ + -log-level={{ default $root.Values.global.logLevel $root.Values.terminatingGateways.logLevel }} \ -log-json={{ $root.Values.global.logJSON }} volumeMounts: - name: consul-service diff --git a/charts/consul/templates/tls-init-job.yaml b/charts/consul/templates/tls-init-job.yaml index d002ae7a75..b4c94436b1 100644 --- a/charts/consul/templates/tls-init-job.yaml +++ b/charts/consul/templates/tls-init-job.yaml @@ -70,7 +70,7 @@ spec: # and use * at the start of the dns name when setting -additional-dnsname. set -o noglob consul-k8s-control-plane tls-init \ - -log-level={{ .Values.global.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.server.logLevel }} \ -log-json={{ .Values.global.logJSON }} \ -domain={{ .Values.global.domain }} \ -days=730 \ diff --git a/charts/consul/test/unit/create-federation-secret-job.bats b/charts/consul/test/unit/create-federation-secret-job.bats index e528f28f0e..872cf2e36c 100644 --- a/charts/consul/test/unit/create-federation-secret-job.bats +++ b/charts/consul/test/unit/create-federation-secret-job.bats @@ -418,3 +418,41 @@ load _helpers [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "createFederationSecret/Job: logLevel is not set by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/create-federation-secret-job.yaml \ + --set 'global.federation.enabled=true' \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'global.tls.enabled=true' \ + --set 'global.federation.createFederationSecret=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "createFederationSecret/Job: override the global.logLevel flag with global.federation.logLevel" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/create-federation-secret-job.yaml \ + --set 'global.federation.enabled=true' \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'global.tls.enabled=true' \ + --set 'global.federation.createFederationSecret=true' \ + --set 'global.federation.logLevel=debug' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/test/unit/gossip-encryption-autogenerate-job.bats b/charts/consul/test/unit/gossip-encryption-autogenerate-job.bats index 662b523bc0..7520696182 100644 --- a/charts/consul/test/unit/gossip-encryption-autogenerate-job.bats +++ b/charts/consul/test/unit/gossip-encryption-autogenerate-job.bats @@ -105,3 +105,33 @@ load _helpers [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "gossipEncryptionAutogenerate/Job: uses the global.logLevel flag by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/gossip-encryption-autogenerate-job.yaml \ + --set 'global.gossipEncryption.autoGenerate=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "gossipEncryptionAutogenerate/Job: overrides the global.logLevel flag when global.gossipEncryption.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/gossip-encryption-autogenerate-job.yaml \ + --set 'global.gossipEncryption.autoGenerate=true' \ + --set 'global.gossipEncryption.logLevel=debug' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/test/unit/ingress-gateways-deployment.bats b/charts/consul/test/unit/ingress-gateways-deployment.bats index 8ed76be13a..dcc4b6116a 100644 --- a/charts/consul/test/unit/ingress-gateways-deployment.bats +++ b/charts/consul/test/unit/ingress-gateways-deployment.bats @@ -1504,3 +1504,35 @@ key2: value2' \ [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "ingressGateways/Deployment: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "ingressGateways/Deployment: override global.logLevel when ingressGateways.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'ingressGateways.logLevel=warn' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index 588b026d40..709bc5b400 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -1644,3 +1644,35 @@ key2: value2' \ [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "meshGateway/Deployment: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "meshGateway/Deployment: override global.logLevel when meshGateway.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'meshGateway.logLevel=warn' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} \ No newline at end of file diff --git a/charts/consul/test/unit/server-acl-init-cleanup-job.bats b/charts/consul/test/unit/server-acl-init-cleanup-job.bats index 947cfa9b42..f759f05a66 100644 --- a/charts/consul/test/unit/server-acl-init-cleanup-job.bats +++ b/charts/consul/test/unit/server-acl-init-cleanup-job.bats @@ -159,3 +159,33 @@ load _helpers [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "serverACLInitCleanup/Job: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/server-acl-init-cleanup-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "serverACLInitCleanup/Job: override global.logLevel when server.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/server-acl-init-cleanup-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + --set 'server.logLevel=debug' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} \ No newline at end of file diff --git a/charts/consul/test/unit/server-acl-init-job.bats b/charts/consul/test/unit/server-acl-init-job.bats index 81064c95eb..0c6bb28814 100644 --- a/charts/consul/test/unit/server-acl-init-job.bats +++ b/charts/consul/test/unit/server-acl-init-job.bats @@ -2202,3 +2202,33 @@ load _helpers [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "serverACLInit/Job: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "serverACLInit/Job: override global.logLevel when server.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + --set 'server.logLevel=debug' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/test/unit/telemetry-collector-deployment.bats b/charts/consul/test/unit/telemetry-collector-deployment.bats index 705447621e..c388ac7ad6 100755 --- a/charts/consul/test/unit/telemetry-collector-deployment.bats +++ b/charts/consul/test/unit/telemetry-collector-deployment.bats @@ -1074,3 +1074,33 @@ MIICFjCCAZsCCQCdwLtdjbzlYzAKBggqhkjOPQQDAjB0MQswCQYDVQQGEwJDQTEL' \ yq -r 'map(select(.name == "foo")) | .[0].value' | tee /dev/stderr) [ "${actual}" = "bar" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "telemetryCollector/Deployment: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/telemetry-collector-deployment.yaml \ + --set 'telemetryCollector.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "telemetryCollector/Deployment: override global.logLevel when telemetryCollector.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/telemetry-collector-deployment.yaml \ + --set 'telemetryCollector.enabled=true' \ + --set 'telemetryCollector.logLevel=warn' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} \ No newline at end of file diff --git a/charts/consul/test/unit/terminating-gateways-deployment.bats b/charts/consul/test/unit/terminating-gateways-deployment.bats index 523138a351..92e17d473e 100644 --- a/charts/consul/test/unit/terminating-gateways-deployment.bats +++ b/charts/consul/test/unit/terminating-gateways-deployment.bats @@ -1504,3 +1504,35 @@ key2: value2' \ [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "terminatingGateways/Deployment: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/terminating-gateways-deployment.yaml \ + --set 'terminatingGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "terminatingGateways/Deployment: override global.logLevel when terminatingGateways.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/terminating-gateways-deployment.yaml \ + --set 'terminatingGateways.enabled=true' \ + --set 'terminatingGateways.logLevel=debug' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/test/unit/tls-init-job.bats b/charts/consul/test/unit/tls-init-job.bats index f9294915a5..31dcee6cd8 100644 --- a/charts/consul/test/unit/tls-init-job.bats +++ b/charts/consul/test/unit/tls-init-job.bats @@ -207,3 +207,33 @@ load _helpers [ "${actualTemplateFoo}" = "bar" ] [ "${actualTemplateBaz}" = "qux" ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "tlsInit/Job: use global.logLevel by default" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/tls-init-job.yaml \ + --set 'global.tls.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "tlsInit/Job: override global.logLevel when server.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/tls-init-job.yaml \ + --set 'global.tls.enabled=true' \ + --set 'server.logLevel=error' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=error"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index 0e325ca66c..3b76ce77ab 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -289,6 +289,9 @@ global: # The key within the Kubernetes secret or Vault secret key that holds the gossip # encryption key. secretKey: "" + # Override global log verbosity level for gossip-encryption-autogenerate-job pods. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" # A list of addresses of upstream DNS servers that are used to recursively resolve DNS queries. # These values are given as `-recursor` flags to Consul servers and clients. @@ -523,6 +526,10 @@ global: # @type: string k8sAuthMethodHost: null + # Override global log verbosity level for the create-federation-secret-job pods. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # Configures metrics for Consul service mesh metrics: # Configures the Helm chart’s components @@ -676,6 +683,10 @@ server: # @type: boolean enabled: "-" + # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # The name of the Docker image (including any tag) for the containers running # Consul server agents. # @type: string @@ -2503,6 +2514,10 @@ meshGateway: # Requirements: consul 1.6.0+ if using `global.acls.manageSystemACLs``. enabled: false + # Override global log verbosity level for mesh-gateway-deployment pods. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # Number of replicas for the Deployment. replicas: 1 @@ -2715,6 +2730,10 @@ ingressGateways: # Enable ingress gateway deployment. Requires `connectInject.enabled=true`. enabled: false + # Override global log verbosity level for ingress-gateways-deployment pods. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # Defaults sets default values for all gateway fields. With the exception # of annotations, defining any of these values in the `gateways` list # will override the default values provided here. Annotations will @@ -2881,6 +2900,10 @@ terminatingGateways: # Enable terminating gateway deployment. Requires `connectInject.enabled=true`. enabled: false + # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # Defaults sets default values for all gateway fields. With the exception # of annotations, defining any of these values in the `gateways` list # will override the default values provided here. Annotations will @@ -3219,6 +3242,10 @@ telemetryCollector: # @type: boolean enabled: false + # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # The name of the Docker image (including any tag) for the containers running # the consul-telemetry-collector # @type: string From d39306174152487599659f7da4475ec396f5f4f5 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 7 Jun 2023 22:24:16 +0530 Subject: [PATCH 02/12] Add changelog --- .changelog/2298.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changelog/2298.txt diff --git a/.changelog/2298.txt b/.changelog/2298.txt new file mode 100644 index 0000000000..925a8469bd --- /dev/null +++ b/.changelog/2298.txt @@ -0,0 +1,10 @@ +```release-note:improvement +Add support to provide the logLevel flag via helm for multiple low level components. Introduces the following fields +1. server.logLevel +2. global.federation.logLevel +3. global.gossipEncryption.logLevel +4. meshGateway.logLevel +5. ingressGateways.logLevel +6. terminatingGateways.logLevel +7. telemetryCollector.logLevel +``` \ No newline at end of file From 2e1b6290ffc716df66abff154812a09440b3b1e0 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 7 Jun 2023 23:13:47 +0530 Subject: [PATCH 03/12] Fix tests --- charts/consul/test/unit/terminating-gateways-deployment.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/consul/test/unit/terminating-gateways-deployment.bats b/charts/consul/test/unit/terminating-gateways-deployment.bats index 92e17d473e..fd9f652567 100644 --- a/charts/consul/test/unit/terminating-gateways-deployment.bats +++ b/charts/consul/test/unit/terminating-gateways-deployment.bats @@ -1533,6 +1533,6 @@ key2: value2' \ yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) local actual=$(echo "$cmd" | - yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) [ "${actual}" = "true" ] } From db58c3c05034a4a1c8588cde51488e25a10bba02 Mon Sep 17 00:00:00 2001 From: Ganesh S Date: Wed, 7 Jun 2023 10:51:21 -0700 Subject: [PATCH 04/12] Rename 2298.txt to 2302.txt --- .changelog/{2298.txt => 2302.txt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .changelog/{2298.txt => 2302.txt} (98%) diff --git a/.changelog/2298.txt b/.changelog/2302.txt similarity index 98% rename from .changelog/2298.txt rename to .changelog/2302.txt index 925a8469bd..8d13d05efd 100644 --- a/.changelog/2298.txt +++ b/.changelog/2302.txt @@ -7,4 +7,4 @@ Add support to provide the logLevel flag via helm for multiple low level compone 5. ingressGateways.logLevel 6. terminatingGateways.logLevel 7. telemetryCollector.logLevel -``` \ No newline at end of file +``` From f30f7b2fbe391aeb4a7467f600708ededa404a04 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Mon, 10 Jul 2023 23:13:47 +0530 Subject: [PATCH 05/12] Address comments --- .changelog/2302.txt | 14 ++++----- .../ingress-gateways-deployment.yaml | 2 +- .../templates/mesh-gateway-deployment.yaml | 2 +- .../telemetry-collector-deployment.yaml | 2 +- .../terminating-gateways-deployment.yaml | 2 +- .../unit/ingress-gateways-deployment.bats | 29 +++++++++++++++++++ .../test/unit/mesh-gateway-deployment.bats | 29 +++++++++++++++++++ .../unit/telemetry-collector-deployment.bats | 27 +++++++++++++++++ .../unit/terminating-gateways-deployment.bats | 29 +++++++++++++++++++ charts/consul/values.yaml | 14 ++++----- 10 files changed, 132 insertions(+), 18 deletions(-) diff --git a/.changelog/2302.txt b/.changelog/2302.txt index 8d13d05efd..592fa90480 100644 --- a/.changelog/2302.txt +++ b/.changelog/2302.txt @@ -1,10 +1,10 @@ ```release-note:improvement Add support to provide the logLevel flag via helm for multiple low level components. Introduces the following fields -1. server.logLevel -2. global.federation.logLevel -3. global.gossipEncryption.logLevel -4. meshGateway.logLevel -5. ingressGateways.logLevel -6. terminatingGateways.logLevel -7. telemetryCollector.logLevel +1. `server.logLevel` +2. `global.federation.logLevel` +3. `global.gossipEncryption.logLevel` +4. `meshGateway.logLevel` +5. `ingressGateways.logLevel` +6. `terminatingGateways.logLevel` +7. `telemetryCollector.logLevel` ``` diff --git a/charts/consul/templates/ingress-gateways-deployment.yaml b/charts/consul/templates/ingress-gateways-deployment.yaml index e6335d2c4e..328c06ee3e 100644 --- a/charts/consul/templates/ingress-gateways-deployment.yaml +++ b/charts/consul/templates/ingress-gateways-deployment.yaml @@ -319,7 +319,7 @@ spec: {{- if $root.Values.global.adminPartitions.enabled }} - -service-partition={{ $root.Values.global.adminPartitions.name }} {{- end }} - - -log-level={{ default $root.Values.global.logLevel }} + - -log-level={{ default $root.Values.global.logLevel $root.Values.ingressGateways.logLevel }} - -log-json={{ $root.Values.global.logJSON }} {{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }} - -telemetry-prom-scrape-path=/metrics diff --git a/charts/consul/templates/mesh-gateway-deployment.yaml b/charts/consul/templates/mesh-gateway-deployment.yaml index 8fd77946fd..1936138db3 100644 --- a/charts/consul/templates/mesh-gateway-deployment.yaml +++ b/charts/consul/templates/mesh-gateway-deployment.yaml @@ -267,7 +267,7 @@ spec: {{- if .Values.global.adminPartitions.enabled }} - -service-partition={{ .Values.global.adminPartitions.name }} {{- end }} - - -log-level={{ default .Values.global.logLevel }} + - -log-level={{ default .Values.global.logLevel .Values.meshGateway.logLevel }} - -log-json={{ .Values.global.logJSON }} {{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableGatewayMetrics) }} - -telemetry-prom-scrape-path=/metrics diff --git a/charts/consul/templates/telemetry-collector-deployment.yaml b/charts/consul/templates/telemetry-collector-deployment.yaml index 44d0792835..bf00fd9a03 100644 --- a/charts/consul/templates/telemetry-collector-deployment.yaml +++ b/charts/consul/templates/telemetry-collector-deployment.yaml @@ -303,7 +303,7 @@ spec: {{- if .Values.global.metrics.enabled }} - -telemetry-prom-scrape-path=/metrics {{- end }} - - -log-level={{ default .Values.global.logLevel }} + - -log-level={{ default .Values.global.logLevel .Values.telemetryCollector.logLevel }} - -log-json={{ .Values.global.logJSON }} - -envoy-concurrency=2 {{- if and .Values.externalServers.enabled .Values.externalServers.skipServerWatch }} diff --git a/charts/consul/templates/terminating-gateways-deployment.yaml b/charts/consul/templates/terminating-gateways-deployment.yaml index 290b285949..fdf2c17d05 100644 --- a/charts/consul/templates/terminating-gateways-deployment.yaml +++ b/charts/consul/templates/terminating-gateways-deployment.yaml @@ -300,7 +300,7 @@ spec: {{- if $root.Values.global.adminPartitions.enabled }} - -service-partition={{ $root.Values.global.adminPartitions.name }} {{- end }} - - -log-level={{ default $root.Values.global.logLevel }} + - -log-level={{ default $root.Values.global.logLevel $root.Values.terminatingGateways.logLevel }} - -log-json={{ $root.Values.global.logJSON }} {{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }} - -telemetry-prom-scrape-path=/metrics diff --git a/charts/consul/test/unit/ingress-gateways-deployment.bats b/charts/consul/test/unit/ingress-gateways-deployment.bats index dcc4b6116a..e8390278a8 100644 --- a/charts/consul/test/unit/ingress-gateways-deployment.bats +++ b/charts/consul/test/unit/ingress-gateways-deployment.bats @@ -1536,3 +1536,32 @@ key2: value2' \ yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) [ "${actual}" = "true" ] } + +@test "ingressGateways/Deployment: use global.logLevel by default for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "ingressGateways/Deployment: override global.logLevel when ingressGateways.logLevel is set for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'ingressGateways.logLevel=trace' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=trace"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} \ No newline at end of file diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index 709bc5b400..d58def05da 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -1672,6 +1672,35 @@ key2: value2' \ . | tee /dev/stderr | yq -r '.spec.template.spec.initContainers[0].command' | tee /dev/stderr) + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "meshGateway/Deployment: use global.logLevel by default for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "meshGateway/Deployment: override global.logLevel when meshGateway.logLevel is set for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'meshGateway.logLevel=warn' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + local actual=$(echo "$cmd" | yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) [ "${actual}" = "true" ] diff --git a/charts/consul/test/unit/telemetry-collector-deployment.bats b/charts/consul/test/unit/telemetry-collector-deployment.bats index c388ac7ad6..323c8bcb95 100755 --- a/charts/consul/test/unit/telemetry-collector-deployment.bats +++ b/charts/consul/test/unit/telemetry-collector-deployment.bats @@ -1103,4 +1103,31 @@ MIICFjCCAZsCCQCdwLtdjbzlYzAKBggqhkjOPQQDAjB0MQswCQYDVQQGEwJDQTEL' \ local actual=$(echo "$cmd" | yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) [ "${actual}" = "true" ] +} + +@test "telemetryCollector/Deployment: use global.logLevel by default for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/telemetry-collector-deployment.yaml \ + --set 'telemetryCollector.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "telemetryCollector/Deployment: override global.logLevel when telemetryCollector.logLevel is set for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/telemetry-collector-deployment.yaml \ + --set 'telemetryCollector.enabled=true' \ + --set 'telemetryCollector.logLevel=debug' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] } \ No newline at end of file diff --git a/charts/consul/test/unit/terminating-gateways-deployment.bats b/charts/consul/test/unit/terminating-gateways-deployment.bats index fd9f652567..6f040134e4 100644 --- a/charts/consul/test/unit/terminating-gateways-deployment.bats +++ b/charts/consul/test/unit/terminating-gateways-deployment.bats @@ -1536,3 +1536,32 @@ key2: value2' \ yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) [ "${actual}" = "true" ] } + +@test "terminatingGateways/Deployment: use global.logLevel by default for dataplane container" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/terminating-gateways-deployment.yaml \ + --set 'terminatingGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=info"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "terminatingGateways/Deployment: override global.logLevel when terminatingGateways.logLevel is set" { + cd `chart_dir` + local cmd=$(helm template \ + -s templates/terminating-gateways-deployment.yaml \ + --set 'terminatingGateways.enabled=true' \ + --set 'terminatingGateways.logLevel=debug' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + + local actual=$(echo "$cmd" | + yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) + [ "${actual}" = "true" ] +} diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index fde83c506b..f2b79eab4b 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -289,7 +289,7 @@ global: # The key within the Kubernetes secret or Vault secret key that holds the gossip # encryption key. secretKey: "" - # Override global log verbosity level for gossip-encryption-autogenerate-job pods. One of "debug", "info", "warn", or "error". + # Override global log verbosity level for gossip-encryption-autogenerate-job pods. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -553,7 +553,7 @@ global: # @type: string k8sAuthMethodHost: null - # Override global log verbosity level for the create-federation-secret-job pods. One of "debug", "info", "warn", or "error". + # Override global log verbosity level for the create-federation-secret-job pods. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -710,7 +710,7 @@ server: # @type: boolean enabled: "-" - # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -2615,7 +2615,7 @@ meshGateway: # Requirements: consul 1.6.0+ if using `global.acls.manageSystemACLs``. enabled: false - # Override global log verbosity level for mesh-gateway-deployment pods. One of "debug", "info", "warn", or "error". + # Override global log verbosity level for mesh-gateway-deployment pods. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -2831,7 +2831,7 @@ ingressGateways: # Enable ingress gateway deployment. Requires `connectInject.enabled=true`. enabled: false - # Override global log verbosity level for ingress-gateways-deployment pods. One of "debug", "info", "warn", or "error". + # Override global log verbosity level for ingress-gateways-deployment pods. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -3001,7 +3001,7 @@ terminatingGateways: # Enable terminating gateway deployment. Requires `connectInject.enabled=true`. enabled: false - # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" @@ -3343,7 +3343,7 @@ telemetryCollector: # @type: boolean enabled: false - # Override global log verbosity level. One of "debug", "info", "warn", or "error". + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". # @type: string logLevel: "" From 77d456fabda16b0eef88313d2431abdf13efae1f Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Mon, 10 Jul 2023 23:18:16 +0530 Subject: [PATCH 06/12] Fix tests --- charts/consul/test/unit/terminating-gateways-deployment.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/consul/test/unit/terminating-gateways-deployment.bats b/charts/consul/test/unit/terminating-gateways-deployment.bats index 6f040134e4..1dc3befbdf 100644 --- a/charts/consul/test/unit/terminating-gateways-deployment.bats +++ b/charts/consul/test/unit/terminating-gateways-deployment.bats @@ -1551,7 +1551,7 @@ key2: value2' \ [ "${actual}" = "true" ] } -@test "terminatingGateways/Deployment: override global.logLevel when terminatingGateways.logLevel is set" { +@test "terminatingGateways/Deployment: override global.logLevel when terminatingGateways.logLevel is set for dataplane container" { cd `chart_dir` local cmd=$(helm template \ -s templates/terminating-gateways-deployment.yaml \ From eff93121ad3534df81bc1364cde40cbca207c4cd Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Tue, 11 Jul 2023 09:30:29 +0530 Subject: [PATCH 07/12] Fix helm tests --- charts/consul/test/unit/server-acl-init-job.bats | 3 +++ charts/consul/test/unit/telemetry-collector-deployment.bats | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/charts/consul/test/unit/server-acl-init-job.bats b/charts/consul/test/unit/server-acl-init-job.bats index bf61b49e60..9760ba564d 100644 --- a/charts/consul/test/unit/server-acl-init-job.bats +++ b/charts/consul/test/unit/server-acl-init-job.bats @@ -2247,6 +2247,9 @@ load _helpers local actual=$(echo "$cmd" | yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) [ "${actual}" = "true" ] +} + +#-------------------------------------------------------------------- # resources @test "serverACLInit/Job: resources defined by default" { diff --git a/charts/consul/test/unit/telemetry-collector-deployment.bats b/charts/consul/test/unit/telemetry-collector-deployment.bats index 323c8bcb95..7809039e11 100755 --- a/charts/consul/test/unit/telemetry-collector-deployment.bats +++ b/charts/consul/test/unit/telemetry-collector-deployment.bats @@ -1111,7 +1111,7 @@ MIICFjCCAZsCCQCdwLtdjbzlYzAKBggqhkjOPQQDAjB0MQswCQYDVQQGEwJDQTEL' \ -s templates/telemetry-collector-deployment.yaml \ --set 'telemetryCollector.enabled=true' \ . | tee /dev/stderr | - yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + yq -r '.spec.template.spec.containers[1].args' | tee /dev/stderr) local actual=$(echo "$cmd" | yq 'any(contains("-log-level=info"))' | tee /dev/stderr) @@ -1125,7 +1125,7 @@ MIICFjCCAZsCCQCdwLtdjbzlYzAKBggqhkjOPQQDAjB0MQswCQYDVQQGEwJDQTEL' \ --set 'telemetryCollector.enabled=true' \ --set 'telemetryCollector.logLevel=debug' \ . | tee /dev/stderr | - yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) + yq -r '.spec.template.spec.containers[1].args' | tee /dev/stderr) local actual=$(echo "$cmd" | yq 'any(contains("-log-level=debug"))' | tee /dev/stderr) From 0815f67f621972cc6d69eb5af74fb80a3f98b15e Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 12 Jul 2023 10:54:51 +0530 Subject: [PATCH 08/12] Address comments --- .changelog/2302.txt | 15 ++++++++------- .../templates/server-acl-init-cleanup-job.yaml | 2 +- charts/consul/templates/server-acl-init-job.yaml | 2 +- charts/consul/templates/tls-init-job.yaml | 2 +- .../test/unit/server-acl-init-cleanup-job.bats | 4 ++-- charts/consul/test/unit/server-acl-init-job.bats | 4 ++-- charts/consul/test/unit/tls-init-job.bats | 4 ++-- charts/consul/values.yaml | 12 ++++++++---- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.changelog/2302.txt b/.changelog/2302.txt index 592fa90480..29bd8b34cf 100644 --- a/.changelog/2302.txt +++ b/.changelog/2302.txt @@ -1,10 +1,11 @@ ```release-note:improvement Add support to provide the logLevel flag via helm for multiple low level components. Introduces the following fields -1. `server.logLevel` -2. `global.federation.logLevel` -3. `global.gossipEncryption.logLevel` -4. `meshGateway.logLevel` -5. `ingressGateways.logLevel` -6. `terminatingGateways.logLevel` -7. `telemetryCollector.logLevel` +1. `global.acls.logLevel` +2. `global.tls.logLevel` +3. `global.federation.logLevel` +4. `global.gossipEncryption.logLevel` +5. `meshGateway.logLevel` +6. `ingressGateways.logLevel` +7. `terminatingGateways.logLevel` +8. `telemetryCollector.logLevel` ``` diff --git a/charts/consul/templates/server-acl-init-cleanup-job.yaml b/charts/consul/templates/server-acl-init-cleanup-job.yaml index 204bd1a5af..2a5409c7d5 100644 --- a/charts/consul/templates/server-acl-init-cleanup-job.yaml +++ b/charts/consul/templates/server-acl-init-cleanup-job.yaml @@ -64,7 +64,7 @@ spec: - consul-k8s-control-plane args: - delete-completed-job - - -log-level={{ default .Values.global.logLevel .Values.server.logLevel }} + - -log-level={{ default .Values.global.logLevel .Values.global.acls.logLevel }} - -log-json={{ .Values.global.logJSON }} - -k8s-namespace={{ .Release.Namespace }} - {{ template "consul.fullname" . }}-server-acl-init diff --git a/charts/consul/templates/server-acl-init-job.yaml b/charts/consul/templates/server-acl-init-job.yaml index 5257865e3b..391da9f108 100644 --- a/charts/consul/templates/server-acl-init-job.yaml +++ b/charts/consul/templates/server-acl-init-job.yaml @@ -168,7 +168,7 @@ spec: CONSUL_FULLNAME="{{template "consul.fullname" . }}" consul-k8s-control-plane server-acl-init \ - -log-level={{ default .Values.global.logLevel .Values.server.logLevel}} \ + -log-level={{ default .Values.global.logLevel .Values.global.acls.logLevel}} \ -log-json={{ .Values.global.logJSON }} \ -resource-prefix=${CONSUL_FULLNAME} \ -k8s-namespace={{ .Release.Namespace }} \ diff --git a/charts/consul/templates/tls-init-job.yaml b/charts/consul/templates/tls-init-job.yaml index ca8bd96d1c..ba3daa3271 100644 --- a/charts/consul/templates/tls-init-job.yaml +++ b/charts/consul/templates/tls-init-job.yaml @@ -77,7 +77,7 @@ spec: # and use * at the start of the dns name when setting -additional-dnsname. set -o noglob consul-k8s-control-plane tls-init \ - -log-level={{ default .Values.global.logLevel .Values.server.logLevel }} \ + -log-level={{ default .Values.global.logLevel .Values.global.tls.logLevel }} \ -log-json={{ .Values.global.logJSON }} \ -domain={{ .Values.global.domain }} \ -days=730 \ diff --git a/charts/consul/test/unit/server-acl-init-cleanup-job.bats b/charts/consul/test/unit/server-acl-init-cleanup-job.bats index dce23a466f..8743ea4a8d 100644 --- a/charts/consul/test/unit/server-acl-init-cleanup-job.bats +++ b/charts/consul/test/unit/server-acl-init-cleanup-job.bats @@ -176,12 +176,12 @@ load _helpers [ "${actual}" = "true" ] } -@test "serverACLInitCleanup/Job: override global.logLevel when server.logLevel is set" { +@test "serverACLInitCleanup/Job: override global.logLevel when global.acls.logLevel is set" { cd `chart_dir` local cmd=$(helm template \ -s templates/server-acl-init-cleanup-job.yaml \ --set 'global.acls.manageSystemACLs=true' \ - --set 'server.logLevel=debug' \ + --set 'global.acls.logLevel=debug' \ . | tee /dev/stderr | yq -r '.spec.template.spec.containers[0].args' | tee /dev/stderr) diff --git a/charts/consul/test/unit/server-acl-init-job.bats b/charts/consul/test/unit/server-acl-init-job.bats index 9760ba564d..1dc55a9551 100644 --- a/charts/consul/test/unit/server-acl-init-job.bats +++ b/charts/consul/test/unit/server-acl-init-job.bats @@ -2235,12 +2235,12 @@ load _helpers [ "${actual}" = "true" ] } -@test "serverACLInit/Job: override global.logLevel when server.logLevel is set" { +@test "serverACLInit/Job: override global.logLevel when global.acls.logLevel is set" { cd `chart_dir` local cmd=$(helm template \ -s templates/server-acl-init-job.yaml \ --set 'global.acls.manageSystemACLs=true' \ - --set 'server.logLevel=debug' \ + --set 'global.acls.logLevel=debug' \ . | tee /dev/stderr | yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) diff --git a/charts/consul/test/unit/tls-init-job.bats b/charts/consul/test/unit/tls-init-job.bats index 1a743f26a3..f71edc43d5 100644 --- a/charts/consul/test/unit/tls-init-job.bats +++ b/charts/consul/test/unit/tls-init-job.bats @@ -224,12 +224,12 @@ load _helpers [ "${actual}" = "true" ] } -@test "tlsInit/Job: override global.logLevel when server.logLevel is set" { +@test "tlsInit/Job: override global.logLevel when global.tls.logLevel is set" { cd `chart_dir` local cmd=$(helm template \ -s templates/tls-init-job.yaml \ --set 'global.tls.enabled=true' \ - --set 'server.logLevel=error' \ + --set 'global.tls.logLevel=error' \ . | tee /dev/stderr | yq -r '.spec.template.spec.containers[0].command' | tee /dev/stderr) diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index e6f9f03f4a..5f9370b524 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -310,6 +310,10 @@ global: # This setting is required for [Cluster Peering](https://developer.hashicorp.com/consul/docs/connect/cluster-peering/k8s). enabled: false + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # If true, turns on the auto-encrypt feature on clients and servers. # It also switches consul-k8s-control-plane components to retrieve the CA from the servers # via the API. Requires Consul 1.7.1+. @@ -409,6 +413,10 @@ global: # This requires Consul >= 1.4. manageSystemACLs: false + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # A Kubernetes or Vault secret containing the bootstrap token to use for creating policies and # tokens for all Consul and consul-k8s-control-plane components. If `secretName` and `secretKey` # are unset, a default secret name and secret key are used. If the secret is populated, then @@ -734,10 +742,6 @@ server: # @type: boolean enabled: "-" - # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". - # @type: string - logLevel: "" - # The name of the Docker image (including any tag) for the containers running # Consul server agents. # @type: string From 59001d25a9d9824080f8a28f99c99c0e3a25af25 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 26 Jul 2023 11:44:19 +0530 Subject: [PATCH 09/12] Add client and server loglevels --- .../templates/client-config-configmap.yaml | 6 +++++ .../templates/server-config-configmap.yaml | 3 +++ .../test/unit/client-config-configmap.bats | 24 +++++++++++++++++++ .../test/unit/server-config-configmap.bats | 21 ++++++++++++++++ charts/consul/values.yaml | 8 +++++++ 5 files changed, 62 insertions(+) diff --git a/charts/consul/templates/client-config-configmap.yaml b/charts/consul/templates/client-config-configmap.yaml index f9650a100b..d91a4d21bf 100644 --- a/charts/consul/templates/client-config-configmap.yaml +++ b/charts/consul/templates/client-config-configmap.yaml @@ -19,6 +19,12 @@ data: "auto_reload_config": true {{- end }} } + log-level.json: |- + { + {{- if .Values.client.logLevel }} + "log_level": "{{ .Values.client.logLevel | upper }}" + {{- end }} + } extra-from-values.json: |- {{ tpl .Values.client.extraConfig . | trimAll "\"" | indent 4 }} central-config.json: |- diff --git a/charts/consul/templates/server-config-configmap.yaml b/charts/consul/templates/server-config-configmap.yaml index 7e3d251001..6c102f0ae3 100644 --- a/charts/consul/templates/server-config-configmap.yaml +++ b/charts/consul/templates/server-config-configmap.yaml @@ -27,6 +27,9 @@ data: }, "datacenter": "{{ .Values.global.datacenter }}", "data_dir": "/consul/data", + {{- if .Values.server.logLevel }} + "log_level": "{{ .Values.server.logLevel | upper }}", + {{- end }} "domain": "{{ .Values.global.domain }}", "limits": { "request_limits": { diff --git a/charts/consul/test/unit/client-config-configmap.bats b/charts/consul/test/unit/client-config-configmap.bats index 5fc4a186d9..94da580eb2 100755 --- a/charts/consul/test/unit/client-config-configmap.bats +++ b/charts/consul/test/unit/client-config-configmap.bats @@ -95,3 +95,27 @@ load _helpers [ "${actual}" = null ] } + +#-------------------------------------------------------------------- +# logLevel + +@test "client/ConfigMap: client.logLevel is empty" { + cd `chart_dir` + local configmap=$(helm template \ + -s templates/client-config-configmap.yaml \ + . | tee /dev/stderr | + yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) + + [ "${actual}" = "null" ] +} + +@test "client/ConfigMap: client.logLevel is non empty" { + cd `chart_dir` + local configmap=$(helm template \ + -s templates/client-config-configmap.yaml \ + --set 'server.logLevel=debug' \ + . | tee /dev/stderr | + yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) + + [ "${actual}" = "DEBUG" ] +} \ No newline at end of file diff --git a/charts/consul/test/unit/server-config-configmap.bats b/charts/consul/test/unit/server-config-configmap.bats index d55c10dd3a..8366341112 100755 --- a/charts/consul/test/unit/server-config-configmap.bats +++ b/charts/consul/test/unit/server-config-configmap.bats @@ -1196,4 +1196,25 @@ load _helpers local actual=$(echo $object | jq -r .audit.sink.MySink3.type | tee /dev/stderr) [ "${actual}" = "file" ] +} + +@test "server/ConfigMap: server.logLevel is empty" { + cd `chart_dir` + local configmap=$(helm template \ + -s templates/server-config-configmap.yaml \ + . | tee /dev/stderr | + yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) + + [ "${actual}" = "null" ] +} + +@test "server/ConfigMap: server.logLevel is non empty" { + cd `chart_dir` + local configmap=$(helm template \ + -s templates/server-config-configmap.yaml \ + --set 'server.logLevel=debug' \ + . | tee /dev/stderr | + yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) + + [ "${actual}" = "DEBUG" ] } \ No newline at end of file diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index 5f9370b524..2df792f534 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -742,6 +742,10 @@ server: # @type: boolean enabled: "-" + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # The name of the Docker image (including any tag) for the containers running # Consul server agents. # @type: string @@ -1376,6 +1380,10 @@ client: # @type: boolean enabled: false + # Override global log verbosity level. One of "trace", "debug", "info", "warn", or "error". + # @type: string + logLevel: "" + # The name of the Docker image (including any tag) for the containers # running Consul client agents. # @type: string From 33be78ffa1abc3d49ead5976f37145558f5f80d3 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 26 Jul 2023 14:19:00 +0530 Subject: [PATCH 10/12] Fix bats --- charts/consul/test/unit/client-config-configmap.bats | 4 ++-- charts/consul/test/unit/client-daemonset.bats | 6 +++--- charts/consul/test/unit/server-config-configmap.bats | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/charts/consul/test/unit/client-config-configmap.bats b/charts/consul/test/unit/client-config-configmap.bats index 94da580eb2..296b867538 100755 --- a/charts/consul/test/unit/client-config-configmap.bats +++ b/charts/consul/test/unit/client-config-configmap.bats @@ -106,7 +106,7 @@ load _helpers . | tee /dev/stderr | yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = "null" ] + [ "${actual}" = null ] } @test "client/ConfigMap: client.logLevel is non empty" { @@ -117,5 +117,5 @@ load _helpers . | tee /dev/stderr | yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = "DEBUG" ] + [ "${actual}" = DEBUG ] } \ No newline at end of file diff --git a/charts/consul/test/unit/client-daemonset.bats b/charts/consul/test/unit/client-daemonset.bats index 6e7a030cb1..d512ad8ab2 100755 --- a/charts/consul/test/unit/client-daemonset.bats +++ b/charts/consul/test/unit/client-daemonset.bats @@ -621,7 +621,7 @@ load _helpers --set 'client.enabled=true' \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = f9be2829fed80a127e3752e10be32f29c2f9ca0ea548abcf3d4fc2c985cb7201 ] + [ "${actual}" = 4fa9ddc3abc4c79eafccb19e5beef80006b7c9736b867d8873554ca03f42a6b3 ] } @test "client/DaemonSet: config-checksum annotation changes when extraConfig is provided" { @@ -632,7 +632,7 @@ load _helpers --set 'client.extraConfig="{\"hello\": \"world\"}"' \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = e9fb5f0b4ff4e36a89e8ca2dc1aed2072306e0dd6d4cc60b3edf155cf8dbe2e9 ] + [ "${actual}" = 42b99932385e7a0580b134fe36a9bda405aab2e375593326677b9838708f0796 ] } @test "client/DaemonSet: config-checksum annotation changes when connectInject.enabled=true" { @@ -643,7 +643,7 @@ load _helpers --set 'connectInject.enabled=true' \ . | tee /dev/stderr | yq -r '.spec.template.metadata.annotations."consul.hashicorp.com/config-checksum"' | tee /dev/stderr) - [ "${actual}" = f9be2829fed80a127e3752e10be32f29c2f9ca0ea548abcf3d4fc2c985cb7201 ] + [ "${actual}" = 4fa9ddc3abc4c79eafccb19e5beef80006b7c9736b867d8873554ca03f42a6b3 ] } #-------------------------------------------------------------------- diff --git a/charts/consul/test/unit/server-config-configmap.bats b/charts/consul/test/unit/server-config-configmap.bats index 8366341112..e8c188583a 100755 --- a/charts/consul/test/unit/server-config-configmap.bats +++ b/charts/consul/test/unit/server-config-configmap.bats @@ -1205,7 +1205,7 @@ load _helpers . | tee /dev/stderr | yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = "null" ] + [ "${actual}" = null ] } @test "server/ConfigMap: server.logLevel is non empty" { @@ -1216,5 +1216,5 @@ load _helpers . | tee /dev/stderr | yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = "DEBUG" ] + [ "${actual}" = DEBUG ] } \ No newline at end of file From bdc001924085bd50a005a54fc9588013a31bc082 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 26 Jul 2023 23:12:25 +0530 Subject: [PATCH 11/12] Update changelog --- .changelog/2302.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.changelog/2302.txt b/.changelog/2302.txt index 29bd8b34cf..7bf7e6b0f6 100644 --- a/.changelog/2302.txt +++ b/.changelog/2302.txt @@ -4,8 +4,10 @@ Add support to provide the logLevel flag via helm for multiple low level compone 2. `global.tls.logLevel` 3. `global.federation.logLevel` 4. `global.gossipEncryption.logLevel` -5. `meshGateway.logLevel` -6. `ingressGateways.logLevel` -7. `terminatingGateways.logLevel` -8. `telemetryCollector.logLevel` +5. `server.logLevel` +6. `client.logLevel` +7. `meshGateway.logLevel` +8. `ingressGateways.logLevel` +9. `terminatingGateways.logLevel` +10. `telemetryCollector.logLevel` ``` From c422913ed61681a5b3161425cfea53ab9fd91eff Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 26 Jul 2023 23:57:06 +0530 Subject: [PATCH 12/12] Fix bats tests --- .../test/unit/client-config-configmap.bats | 18 ++++++++++-------- .../test/unit/server-config-configmap.bats | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/charts/consul/test/unit/client-config-configmap.bats b/charts/consul/test/unit/client-config-configmap.bats index 296b867538..1f1443a156 100755 --- a/charts/consul/test/unit/client-config-configmap.bats +++ b/charts/consul/test/unit/client-config-configmap.bats @@ -101,21 +101,23 @@ load _helpers @test "client/ConfigMap: client.logLevel is empty" { cd `chart_dir` - local configmap=$(helm template \ - -s templates/client-config-configmap.yaml \ + local actual=$(helm template \ + -s templates/client-config-configmap.yaml \ + --set 'client.enabled=true' \ . | tee /dev/stderr | yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = null ] + [ "${actual}" = "null" ] } @test "client/ConfigMap: client.logLevel is non empty" { cd `chart_dir` - local configmap=$(helm template \ - -s templates/client-config-configmap.yaml \ - --set 'server.logLevel=debug' \ + local actual=$(helm template \ + -s templates/client-config-configmap.yaml \ + --set 'client.enabled=true' \ + --set 'client.logLevel=DEBUG' \ . | tee /dev/stderr | yq -r '.data["log-level.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = DEBUG ] -} \ No newline at end of file + [ "${actual}" = "DEBUG" ] +} diff --git a/charts/consul/test/unit/server-config-configmap.bats b/charts/consul/test/unit/server-config-configmap.bats index e8c188583a..643caeb0a1 100755 --- a/charts/consul/test/unit/server-config-configmap.bats +++ b/charts/consul/test/unit/server-config-configmap.bats @@ -1205,7 +1205,7 @@ load _helpers . | tee /dev/stderr | yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = null ] + [ "${configmap}" = "null" ] } @test "server/ConfigMap: server.logLevel is non empty" { @@ -1216,5 +1216,5 @@ load _helpers . | tee /dev/stderr | yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr) - [ "${actual}" = DEBUG ] + [ "${configmap}" = "DEBUG" ] } \ No newline at end of file