func configureKubelet()

in kinder/pkg/build/bits/initBits.go [206:281]


func configureKubelet(c *BuildContext) error {
	// files for the kubelet.service is created on the flight directly into the alter filesystem
	hsrc := filepath.Join(c.HostBitsPath(), "systemd")
	if err := os.MkdirAll(hsrc, 0777); err != nil {
		log.Errorf("failed to create %s folder! %v", hsrc, err)
		return err
	}
	csrc := filepath.Join(c.ContainerBitsPath(), "systemd")

	// The destination path for the kubelet.service file is /kind/systemd,
	dst := filepath.Join("/kind", "systemd")

	// create dest folder
	if err := c.RunInContainer("mkdir", "-p", dst); err != nil {
		log.Errorf("failed to create %s folder into the image! %v", dst, err)
		return err
	}

	// write the kubelet.service file
	hsrcFile := filepath.Join(hsrc, "kubelet.service")
	csrcFile := filepath.Join(csrc, "kubelet.service")
	dstFile := filepath.Join(dst, "kubelet.service")
	log.Infof("Adding %s to the image and enabling the kubelet service", dstFile)
	if err := ioutil.WriteFile(hsrcFile, kubeletService, 0644); err != nil {
		log.Errorf("failed to create %s file into the image! %v", dstFile, err)
		return err
	}

	if err := c.RunInContainer("cp", csrcFile, dstFile); err != nil {
		log.Errorf("failed to copy %s into the image! %v", csrcFile, err)
		return err
	}

	// TODO: someday we might need a different user ...
	if err := c.RunInContainer("chown", "-R", "root:root", dstFile); err != nil {
		log.Errorf("failed to set ownership on %s! %v", dstFile, err)
		return err
	}

	// enable the kubelet service
	if err := c.RunInContainer("systemctl", "enable", dstFile); err != nil {
		return errors.Wrap(err, "failed to enable kubelet service")
	}

	// The destination path for the kubeadm dropin file is /etc/systemd/system/kubelet.service.d/
	dst = filepath.Join("/etc", "systemd", "system", "kubelet.service.d")

	// create dest folder
	if err := c.RunInContainer("mkdir", "-p", dst); err != nil {
		log.Errorf("failed to create %s folder into the image! %v", dst, err)
		return err
	}

	// write the 10-kubeadm.conf file
	hsrcFile = filepath.Join(hsrc, "10-kubeadm.conf")
	csrcFile = filepath.Join(csrc, "10-kubeadm.conf")
	dstFile = filepath.Join(dst, "10-kubeadm.conf")
	log.Infof("Adding %s to the image", dstFile)
	if err := ioutil.WriteFile(hsrcFile, kubeadmDropIn, 0644); err != nil {
		log.Errorf("failed to create %s file into the image! %v", dstFile, err)
		return err
	}

	if err := c.RunInContainer("cp", csrcFile, dstFile); err != nil {
		log.Errorf("failed to copy %s into the image! %v", csrcFile, err)
		return err
	}

	// TODO: someday we might need a different user ...
	if err := c.RunInContainer("chown", "-R", "root:root", dstFile); err != nil {
		log.Errorf("failed to set ownership on %s! %v", dstFile, err)
		return err
	}

	return nil
}