Fix setting resources in fluentd-gcp plugin

Signed-off-by: Mik Vyatskov <vmik@google.com>
This commit is contained in:
Mik Vyatskov 2017-11-17 18:28:32 +01:00
parent 8823a83565
commit e9322b929c
3 changed files with 41 additions and 16 deletions

View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd-gcp
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile

View File

@ -1,12 +1,3 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd-gcp
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: DaemonSet kind: DaemonSet
metadata: metadata:

View File

@ -1942,21 +1942,47 @@ function copy-manifests {
# Fluentd manifest is modified using kubectl, which may not be available at # Fluentd manifest is modified using kubectl, which may not be available at
# this point. Run this as a background process. # this point. Run this as a background process.
function wait-for-apiserver-and-update-fluentd { function wait-for-apiserver-and-update-fluentd {
local -r fluentd_gcp_yaml="${1}"
local modifying_flags=""
if [[ -n "${FLUENTD_GCP_MEMORY_LIMIT:-}" ]]; then
modifying_flags="${modifying_flags} --limits=memory=${FLUENTD_GCP_MEMORY_LIMIT}"
fi
local request_resources=""
if [[ -n "${FLUENTD_GCP_CPU_REQUEST:-}" ]]; then
request_resources="cpu=${FLUENTD_GCP_CPU_REQUEST}"
fi
if [[ -n "${FLUENTD_GCP_MEMORY_REQUEST:-}" ]]; then
if [[ -n "${request_resources}" ]]; then
request_resources="${request_resources},"
fi
request_resources="memory=${FLUENTD_GCP_MEMORY_REQUEST}"
fi
if [[ -n "${request_resources}" ]]; then
modifying_flags="${modifying_flags} --requests=${request_resources}"
fi
until kubectl get nodes until kubectl get nodes
do do
sleep 10 sleep 10
done done
kubectl set resources --dry-run --local -f ${fluentd_gcp_yaml} \
--limits=memory=${FLUENTD_GCP_MEMORY_LIMIT} \ local -r temp_fluentd_gcp_yaml="${fluentd_gcp_yaml}.tmp"
--requests=cpu=${FLUENTD_GCP_CPU_REQUEST},memory=${FLUENTD_GCP_MEMORY_REQUEST} \ if kubectl set resources --dry-run --local -f ${fluentd_gcp_yaml} ${modifying_flags} \
--containers=fluentd-gcp -o yaml > ${fluentd_gcp_yaml}.tmp --containers=fluentd-gcp -o yaml > ${temp_fluentd_gcp_yaml}; then
mv ${fluentd_gcp_yaml}.tmp ${fluentd_gcp_yaml} mv ${temp_fluentd_gcp_yaml} ${fluentd_gcp_yaml}
else
(echo "Failed to update fluentd resources. Used manifest:" && cat ${temp_fluentd_gcp_yaml}) >&2
rm ${temp_fluentd_gcp_yaml}
fi
} }
# Trigger background process that will ultimately update fluentd resource # Trigger background process that will ultimately update fluentd resource
# requirements. # requirements.
function start-fluentd-resource-update { function start-fluentd-resource-update {
wait-for-apiserver-and-update-fluentd & local -r fluentd_gcp_yaml="${1}"
wait-for-apiserver-and-update-fluentd ${fluentd_gcp_yaml} &
} }
# Updates parameters in yaml file for prometheus-to-sd configuration, or # Updates parameters in yaml file for prometheus-to-sd configuration, or
@ -2091,7 +2117,7 @@ EOF
local -r fluentd_gcp_yaml="${dst_dir}/fluentd-gcp/fluentd-gcp-ds.yaml" local -r fluentd_gcp_yaml="${dst_dir}/fluentd-gcp/fluentd-gcp-ds.yaml"
update-prometheus-to-sd-parameters ${event_exporter_yaml} update-prometheus-to-sd-parameters ${event_exporter_yaml}
update-prometheus-to-sd-parameters ${fluentd_gcp_yaml} update-prometheus-to-sd-parameters ${fluentd_gcp_yaml}
start-fluentd-resource-update start-fluentd-resource-update ${fluentd_gcp_yaml}
fi fi
if [[ "${ENABLE_CLUSTER_UI:-}" == "true" ]]; then if [[ "${ENABLE_CLUSTER_UI:-}" == "true" ]]; then
setup-addon-manifests "addons" "dashboard" setup-addon-manifests "addons" "dashboard"