Skip to content

Commit adf7ed4

Browse files
committed
Allow to disable logrotation of kubernetes and pod logs
Make logrotate disabled by default
1 parent aa06322 commit adf7ed4

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

cluster/gce/config-default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,20 @@ METADATA_CLOBBERS_CONFIG="${METADATA_CLOBBERS_CONFIG:-false}"
425425

426426
ENABLE_BIG_CLUSTER_SUBNETS="${ENABLE_BIG_CLUSTER_SUBNETS:-false}"
427427

428+
# Optional: Enable log rotation for k8s services
429+
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
430+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
428431
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
429432
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
430433
fi
431434
if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
432435
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
433436
fi
434437

438+
# Optional: Enable log rotation for pod logs
439+
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
440+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
441+
435442
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
436443
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
437444
fi

cluster/gce/config-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,20 @@ ADVANCED_AUDIT_LOG_MODE=${ADVANCED_AUDIT_LOG_MODE:-batch} # batch, blocking
467467

468468
ENABLE_BIG_CLUSTER_SUBNETS=${ENABLE_BIG_CLUSTER_SUBNETS:-false}
469469

470+
# Optional: Enable log rotation for k8s services
471+
ENABLE_LOGROTATE_FILES="${ENABLE_LOGROTATE_FILES:-false}"
472+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_LOGROTATE_FILES"
470473
if [[ -n "${LOGROTATE_FILES_MAX_COUNT:-}" ]]; then
471474
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_FILES_MAX_COUNT"
472475
fi
473476
if [[ -n "${LOGROTATE_MAX_SIZE:-}" ]]; then
474477
PROVIDER_VARS="${PROVIDER_VARS:-} LOGROTATE_MAX_SIZE"
475478
fi
476479

480+
# Optional: Enable log rotation for pod logs
481+
ENABLE_POD_LOG="${ENABLE_POD_LOG:-false}"
482+
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_POD_LOG"
483+
477484
if [[ -n "${POD_LOG_MAX_FILE:-}" ]]; then
478485
PROVIDER_VARS="${PROVIDER_VARS:-} POD_LOG_MAX_FILE"
479486
fi

cluster/gce/gci/configure-helper.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,19 @@ function ensure-local-ssds() {
428428
# Installs logrotate configuration files
429429
function setup-logrotate() {
430430
mkdir -p /etc/logrotate.d/
431-
# Configure log rotation for all logs in /var/log, which is where k8s services
432-
# are configured to write their log files. Whenever logrotate is ran, this
433-
# config will:
434-
# * rotate the log file if its size is > 100Mb OR if one day has elapsed
435-
# * save rotated logs into a gzipped timestamped backup
436-
# * log file timestamp (controlled by 'dateformat') includes seconds too. This
437-
# ensures that logrotate can generate unique logfiles during each rotation
438-
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a
439-
# day).
440-
# * keep only 5 old (rotated) logs, and will discard older logs.
441-
cat > /etc/logrotate.d/allvarlogs <<EOF
431+
432+
if [[ "${ENABLE_LOGROTATE_FILES:-false}" = "true" ]]; then
433+
# Configure log rotation for all logs in /var/log, which is where k8s services
434+
# are configured to write their log files. Whenever logrotate is ran, this
435+
# config will:
436+
# * rotate the log file if its size is > 100Mb OR if one day has elapsed
437+
# * save rotated logs into a gzipped timestamped backup
438+
# * log file timestamp (controlled by 'dateformat') includes seconds too. This
439+
# ensures that logrotate can generate unique logfiles during each rotation
440+
# (otherwise it skips rotation if 'maxsize' is reached multiple times in a
441+
# day).
442+
# * keep only 5 old (rotated) logs, and will discard older logs.
443+
cat > /etc/logrotate.d/allvarlogs <<EOF
442444
/var/log/*.log {
443445
rotate ${LOGROTATE_FILES_MAX_COUNT:-5}
444446
copytruncate
@@ -452,9 +454,11 @@ function setup-logrotate() {
452454
create 0644 root root
453455
}
454456
EOF
457+
fi
455458

456-
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
457-
cat > /etc/logrotate.d/allpodlogs <<EOF
459+
if [[ "${ENABLE_POD_LOG:-false}" = "true" ]]; then
460+
# Configure log rotation for pod logs in /var/log/pods/NAMESPACE_NAME_UID.
461+
cat > /etc/logrotate.d/allpodlogs <<EOF
458462
/var/log/pods/*/*.log {
459463
rotate ${POD_LOG_MAX_FILE:-5}
460464
copytruncate
@@ -468,6 +472,7 @@ EOF
468472
create 0644 root root
469473
}
470474
EOF
475+
fi
471476
}
472477

473478
# Finds the master PD device; returns it in MASTER_PD_DEVICE
@@ -924,7 +929,7 @@ EOF
924929
limitedResources:
925930
- resource: pods
926931
matchScopes:
927-
- scopeName: PriorityClass
932+
- scopeName: PriorityClass
928933
operator: In
929934
values: ["system-node-critical", "system-cluster-critical"]
930935
EOF

0 commit comments

Comments
 (0)