Created
February 19, 2019 13:54
-
-
Save alvaroaleman/5f03c0d7b01a6e4196f29f787d784c82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@alvaro-openshift-controller origin]# kubectl get ds -n openshift-node sync -o yaml | |
apiVersion: extensions/v1beta1 | |
kind: DaemonSet | |
metadata: | |
annotations: | |
image.openshift.io/triggers: | | |
[ | |
{"from":{"kind":"ImageStreamTag","name":"node:v3.11"},"fieldPath":"spec.template.spec.containers[?(@.name==\"sync\")].image"} | |
] | |
kubectl.kubernetes.io/last-applied-configuration: | | |
{"apiVersion":"apps/v1","kind":"DaemonSet","metadata":{"annotations":{"image.openshift.io/triggers":"[\n {\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"node:v3.11\"},\"fieldPath\":\"spec.template.spec.containers[?(@.name==\\\"sync\\\")].image\"}\n]\n","kubernetes.io/description":"This daemon set provides dynamic configuration of nodes and relabels nodes as appropriate.\n"},"name":"sync","namespace":"openshift-node"},"spec":{"selector":{"matchLabels":{"app":"sync"}},"template":{"metadata":{"annotations":{"scheduler.alpha.kubernetes.io/critical-pod":""},"labels":{"app":"sync","component":"network","openshift.io/component":"sync","type":"infra"}},"spec":{"containers":[{"command":["/bin/bash","-c","#!/bin/bash\nset -euo pipefail\n\n# set by the node image\nunset KUBECONFIG\n\ntrap 'kill $(jobs -p); exit 0' TERM\n\n# track the current state of the config\nif [[ -f /etc/origin/node/node-config.yaml ]]; then\n md5sum /etc/origin/node/node-config.yaml \u003e /tmp/.old\nelse\n touch /tmp/.old\nfi\n\n# loop until BOOTSTRAP_CONFIG_NAME is set\nwhile true; do\n file=/etc/sysconfig/origin-node\n if [[ -f /etc/sysconfig/atomic-openshift-node ]]; then\n file=/etc/sysconfig/atomic-openshift-node\n elif [[ -f /etc/sysconfig/origin-node ]]; then\n file=/etc/sysconfig/origin-node\n else\n echo \"info: Waiting for the node sysconfig file to be created\" 2\u003e\u00261\n sleep 15 \u0026 wait\n continue\n fi\n name=\"$(sed -nE 's|^BOOTSTRAP_CONFIG_NAME=([^#].+)|\\1|p' \"${file}\" | head -1)\"\n if [[ -z \"${name}\" ]]; then\n echo \"info: Waiting for BOOTSTRAP_CONFIG_NAME to be set\" 2\u003e\u00261\n sleep 15 \u0026 wait\n continue\n fi\n # in the background check to see if the value changes and exit if so\n pid=$BASHPID\n (\n while true; do\n if ! updated=\"$(sed -nE 's|^BOOTSTRAP_CONFIG_NAME=([^#].+)|\\1|p' \"${file}\" | head -1)\"; then\n echo \"error: Unable to check for bootstrap config, exiting\" 2\u003e\u00261\n kill $pid\n exit 1\n fi\n if [[ \"${updated}\" != \"${name}\" ]]; then\n echo \"info: Bootstrap configuration profile name changed, exiting\" 2\u003e\u00261\n kill $pid\n exit 0\n fi\n sleep 15\n done\n ) \u0026\n break\ndone\nmkdir -p /etc/origin/node/tmp\n# periodically refresh both node-config.yaml and relabel the node\nwhile true; do\n if ! oc extract \"configmaps/${name}\" -n openshift-node --to=/etc/origin/node/tmp --confirm --request-timeout=10s --config /etc/origin/node/node.kubeconfig \"--token=$( cat /var/run/secrets/kubernetes.io/serviceaccount/token )\" \u003e /dev/null; then\n echo \"error: Unable to retrieve latest config for node\" 2\u003e\u00261\n sleep 15 \u0026\n wait $!\n continue\n fi\n\n KUBELET_HOSTNAME_OVERRIDE=$(cat /etc/sysconfig/KUBELET_HOSTNAME_OVERRIDE) || :\n if ! [[ -z \"$KUBELET_HOSTNAME_OVERRIDE\" ]]; then\n #Patching node-config for hostname override\n echo \"nodeName: $KUBELET_HOSTNAME_OVERRIDE\" \u003e\u003e /etc/origin/node/tmp/node-config.yaml\n fi\n\n # detect whether the node-config.yaml has changed, and if so trigger a restart of the kubelet.\n md5sum /etc/origin/node/tmp/node-config.yaml \u003e /tmp/.new\n if [[ \"$( cat /tmp/.old )\" != \"$( cat /tmp/.new )\" ]]; then\n mv /etc/origin/node/tmp/node-config.yaml /etc/origin/node/node-config.yaml\n echo \"info: Configuration changed, restarting kubelet\" 2\u003e\u00261\n # TODO: kubelet doesn't relabel nodes, best effort for now\n # https://github.com/kubernetes/kubernetes/issues/59314\n if args=\"$(openshift-node-config --config /etc/origin/node/node-config.yaml)\"; then\n labels=$(tr ' ' '\\n' \u003c\u003c\u003c$args | sed -ne '/^--node-labels=/ { s/^--node-labels=//; p; }' | tr ',\\n' ' ')\n if [[ -n \"${labels}\" ]]; then\n echo \"info: Applying node labels $labels\" 2\u003e\u00261\n if ! oc label --config=/etc/origin/node/node.kubeconfig \"node/${NODE_NAME}\" ${labels} --overwrite; then\n echo \"error: Unable to apply labels, will retry in 10\" 2\u003e\u00261\n sleep 10 \u0026\n wait $!\n continue\n fi\n fi\n else\n echo \"error: The downloaded node configuration is invalid, retrying later\" 2\u003e\u00261\n sleep 10 \u0026\n wait $!\n continue\n fi\n if ! pkill -U 0 -f '(^|/)hyperkube kubelet '; then\n echo \"error: Unable to restart Kubelet\" 2\u003e\u00261\n sleep 10 \u0026\n wait $!\n continue\n fi\n fi\n # annotate node with md5sum of the config\n oc annotate --config=/etc/origin/node/node.kubeconfig \"node/${NODE_NAME}\" \\\n node.openshift.io/md5sum=\"$( cat /tmp/.new | cut -d' ' -f1 )\" --overwrite\n cp -f /tmp/.new /tmp/.old\n sleep 180 \u0026\n wait $!\ndone\n"],"env":[{"name":"NODE_NAME","valueFrom":{"fieldRef":{"fieldPath":"spec.nodeName"}}}],"image":" ","name":"sync","securityContext":{"privileged":true,"runAsUser":0},"volumeMounts":[{"mountPath":"/etc/origin/node/","name":"host-config"},{"mountPath":"/etc/sysconfig","name":"host-sysconfig-node","readOnly":true}]}],"hostNetwork":true,"hostPID":true,"priorityClassName":"system-node-critical","serviceAccountName":"sync","terminationGracePeriodSeconds":1,"volumes":[{"hostPath":{"path":"/etc/origin/node"},"name":"host-config"},{"hostPath":{"path":"/etc/sysconfig"},"name":"host-sysconfig-node"}]}},"updateStrategy":{"rollingUpdate":{"maxUnavailable":"50%"},"type":"RollingUpdate"}}} | |
kubernetes.io/description: | | |
This daemon set provides dynamic configuration of nodes and relabels nodes as appropriate. | |
creationTimestamp: 2019-02-19T10:33:48Z | |
generation: 2 | |
labels: | |
app: sync | |
component: network | |
openshift.io/component: sync | |
type: infra | |
name: sync | |
namespace: openshift-node | |
resourceVersion: "19177" | |
selfLink: /apis/extensions/v1beta1/namespaces/openshift-node/daemonsets/sync | |
uid: d7a7123d-3431-11e9-8e42-9600001be975 | |
spec: | |
revisionHistoryLimit: 10 | |
selector: | |
matchLabels: | |
app: sync | |
template: | |
metadata: | |
annotations: | |
scheduler.alpha.kubernetes.io/critical-pod: "" | |
creationTimestamp: null | |
labels: | |
app: sync | |
component: network | |
openshift.io/component: sync | |
type: infra | |
spec: | |
containers: | |
- command: | |
- /bin/bash | |
- -c | |
- | | |
#!/bin/bash | |
set -euo pipefail | |
# set by the node image | |
unset KUBECONFIG | |
trap 'kill $(jobs -p); exit 0' TERM | |
# track the current state of the config | |
if [[ -f /etc/origin/node/node-config.yaml ]]; then | |
md5sum /etc/origin/node/node-config.yaml > /tmp/.old | |
else | |
touch /tmp/.old | |
fi | |
# loop until BOOTSTRAP_CONFIG_NAME is set | |
while true; do | |
file=/etc/sysconfig/origin-node | |
if [[ -f /etc/sysconfig/atomic-openshift-node ]]; then | |
file=/etc/sysconfig/atomic-openshift-node | |
elif [[ -f /etc/sysconfig/origin-node ]]; then | |
file=/etc/sysconfig/origin-node | |
else | |
echo "info: Waiting for the node sysconfig file to be created" 2>&1 | |
sleep 15 & wait | |
continue | |
fi | |
name="$(sed -nE 's|^BOOTSTRAP_CONFIG_NAME=([^#].+)|\1|p' "${file}" | head -1)" | |
if [[ -z "${name}" ]]; then | |
echo "info: Waiting for BOOTSTRAP_CONFIG_NAME to be set" 2>&1 | |
sleep 15 & wait | |
continue | |
fi | |
# in the background check to see if the value changes and exit if so | |
pid=$BASHPID | |
( | |
while true; do | |
if ! updated="$(sed -nE 's|^BOOTSTRAP_CONFIG_NAME=([^#].+)|\1|p' "${file}" | head -1)"; then | |
echo "error: Unable to check for bootstrap config, exiting" 2>&1 | |
kill $pid | |
exit 1 | |
fi | |
if [[ "${updated}" != "${name}" ]]; then | |
echo "info: Bootstrap configuration profile name changed, exiting" 2>&1 | |
kill $pid | |
exit 0 | |
fi | |
sleep 15 | |
done | |
) & | |
break | |
done | |
mkdir -p /etc/origin/node/tmp | |
# periodically refresh both node-config.yaml and relabel the node | |
while true; do | |
if ! oc extract "configmaps/${name}" -n openshift-node --to=/etc/origin/node/tmp --confirm --request-timeout=10s --config /etc/origin/node/node.kubeconfig "--token=$( cat /var/run/secrets/kubernetes.io/serviceaccount/token )" > /dev/null; then | |
echo "error: Unable to retrieve latest config for node" 2>&1 | |
sleep 15 & | |
wait $! | |
continue | |
fi | |
KUBELET_HOSTNAME_OVERRIDE=$(cat /etc/sysconfig/KUBELET_HOSTNAME_OVERRIDE) || : | |
if ! [[ -z "$KUBELET_HOSTNAME_OVERRIDE" ]]; then | |
#Patching node-config for hostname override | |
echo "nodeName: $KUBELET_HOSTNAME_OVERRIDE" >> /etc/origin/node/tmp/node-config.yaml | |
fi | |
# detect whether the node-config.yaml has changed, and if so trigger a restart of the kubelet. | |
md5sum /etc/origin/node/tmp/node-config.yaml > /tmp/.new | |
if [[ "$( cat /tmp/.old )" != "$( cat /tmp/.new )" ]]; then | |
mv /etc/origin/node/tmp/node-config.yaml /etc/origin/node/node-config.yaml | |
echo "info: Configuration changed, restarting kubelet" 2>&1 | |
# TODO: kubelet doesn't relabel nodes, best effort for now | |
# https://github.com/kubernetes/kubernetes/issues/59314 | |
if args="$(openshift-node-config --config /etc/origin/node/node-config.yaml)"; then | |
labels=$(tr ' ' '\n' <<<$args | sed -ne '/^--node-labels=/ { s/^--node-labels=//; p; }' | tr ',\n' ' ') | |
if [[ -n "${labels}" ]]; then | |
echo "info: Applying node labels $labels" 2>&1 | |
if ! oc label --config=/etc/origin/node/node.kubeconfig "node/${NODE_NAME}" ${labels} --overwrite; then | |
echo "error: Unable to apply labels, will retry in 10" 2>&1 | |
sleep 10 & | |
wait $! | |
continue | |
fi | |
fi | |
else | |
echo "error: The downloaded node configuration is invalid, retrying later" 2>&1 | |
sleep 10 & | |
wait $! | |
continue | |
fi | |
if ! pkill -U 0 -f '(^|/)hyperkube kubelet '; then | |
echo "error: Unable to restart Kubelet" 2>&1 | |
sleep 10 & | |
wait $! | |
continue | |
fi | |
fi | |
# annotate node with md5sum of the config | |
oc annotate --config=/etc/origin/node/node.kubeconfig "node/${NODE_NAME}" \ | |
node.openshift.io/md5sum="$( cat /tmp/.new | cut -d' ' -f1 )" --overwrite | |
cp -f /tmp/.new /tmp/.old | |
sleep 180 & | |
wait $! | |
done | |
env: | |
- name: NODE_NAME | |
valueFrom: | |
fieldRef: | |
apiVersion: v1 | |
fieldPath: spec.nodeName | |
image: docker.io/openshift/origin-node:v3.11 | |
imagePullPolicy: IfNotPresent | |
name: sync | |
resources: {} | |
securityContext: | |
privileged: true | |
runAsUser: 0 | |
terminationMessagePath: /dev/termination-log | |
terminationMessagePolicy: File | |
volumeMounts: | |
- mountPath: /etc/origin/node/ | |
name: host-config | |
- mountPath: /etc/sysconfig | |
name: host-sysconfig-node | |
readOnly: true | |
dnsPolicy: ClusterFirst | |
hostNetwork: true | |
hostPID: true | |
priorityClassName: system-node-critical | |
restartPolicy: Always | |
schedulerName: default-scheduler | |
securityContext: {} | |
serviceAccount: sync | |
serviceAccountName: sync | |
terminationGracePeriodSeconds: 1 | |
volumes: | |
- hostPath: | |
path: /etc/origin/node | |
type: "" | |
name: host-config | |
- hostPath: | |
path: /etc/sysconfig | |
type: "" | |
name: host-sysconfig-node | |
templateGeneration: 2 | |
updateStrategy: | |
rollingUpdate: | |
maxUnavailable: 50% | |
type: RollingUpdate | |
status: | |
currentNumberScheduled: 3 | |
desiredNumberScheduled: 3 | |
numberAvailable: 3 | |
numberMisscheduled: 0 | |
numberReady: 3 | |
observedGeneration: 2 | |
updatedNumberScheduled: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment