apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kubelet-node-status-interval
  namespace: kube-system-patch
spec:
  selector:
    matchLabels:
      name: kubelet-node-status-interval
  template:
    metadata:
      labels:
        name: kubelet-node-status-interval
    spec:
      # Put a label on one node, then uncomment and edit the below,
      # if you want to test on one node first
      #nodeSelector:
      #  johnpatch: "yes"
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      containers:
      - name: kubelet-node-status-interval
        image: mcr.microsoft.com/oss/busybox/busybox:1.33.1 # use any tag from https://mcr.microsoft.com/v2/oss/busybox/busybox/tags/list
        command:
          - nsenter
          - --target
          - "1"
          - --mount
          - --uts
          - --ipc
          - --net
          - --pid
          - --
          - bash
          - -exc
          - |
            target="/etc/default/kubelet"
            desiredval="node-status-update-frequency=1m"
            if grep -q "\-\-$desiredval" "$target" ; then
                echo 'Already up to date'
                sleep infinity 
                exit 0
            fi
            #next two lines are identical - one for s one for m because pipe char as OR didn't work
            sed -i "s|--node-status-update-frequency=[0-9]*s|--$desiredval|g" "$target"
            sed -i "s|--node-status-update-frequency=[0-9]*m|--$desiredval|g" "$target"
            echo 'Done'
            systemctl restart kubelet.service
            sleep infinity
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 16Mi
        securityContext:
          privileged: true
      hostNetwork: true
      hostPID: true
      hostIPC: true
      terminationGracePeriodSeconds: 0