Repository: k3s-io/k3s
File: tests/e2e/testutils.go (Go)

Code before:
	}
	files, err := os.ReadDir(resourceDir)
	if err != nil {
		err = fmt.Errorf("%s : Unable to read resource manifest file for %s", err, workload)
		return "", err
	}
	fmt.Println("\nDeploying", workload)
	for _, f := range files {
		filename := filepath.Join(resourceDir, f.Name())
		if strings.TrimSpace(f.Name()) == workload {
			cmd := "kubectl apply -f " + filename + " --kubeconfig=" + tc.KubeconfigFile
			return RunCommand(cmd)
		}
	}
	return "", nil
}

func KillK3sCluster(nodes []VagrantNode) error {
	for _, node := range nodes {
		if _, err := node.RunCmdOnNode("k3s-killall.sh"); err != nil {
			return err
		}
		if _, err := node.RunCmdOnNode("rm -rf /etc/rancher/k3s/config.yaml.d /var/lib/kubelet/pods /var/lib/rancher/k3s/agent/etc /var/lib/rancher/k3s/agent/containerd /var/lib/rancher/k3s/server/db /var/log/pods /run/k3s /run/flannel"); err != nil {
			return err
		}
		if _, err := node.RunCmdOnNode("systemctl restart containerd"); err != nil {
			return err
		}
		if _, err := node.RunCmdOnNode("journalctl --flush --sync --rotate --vacuum-size=1"); err != nil {
			return err
		}
	}
	return nil
}

func DestroyCluster() error {
	if out, err := RunCommand("vagrant destroy -f"); err != nil {
		return fmt.Errorf("%v - command output:\n%s", err, out)
	}
	return os.Remove("vagrant.log")
}

func FetchClusterIP(kubeconfig string, servicename string, dualStack bool) (string, error) {
	if dualStack {
		cmd := "kubectl get svc " + servicename + " -o jsonpath='{.spec.clusterIPs}' --kubeconfig=" + kubeconfig
		res, err := RunCommand(cmd)
		if err != nil {
			return res, err
		}
		res = strings.ReplaceAll(res, "\"", "")
		return strings.Trim(res, "[]"), nil

Review comment (suggestion):
you can remove the containerd restart from here as well - the host containerd is the backend for host docker, and is otherwise unused in favor of the bundled containerd.

Code after:
	}
	files, err := os.ReadDir(resourceDir)
	if err != nil {
		err = fmt.Errorf("%s : Unable to read resource manifest file for %s", err, workload)
		return "", err
	}
	fmt.Println("\nDeploying", workload)
	for _, f := range files {
		filename := filepath.Join(resourceDir, f.Name())
		if strings.TrimSpace(f.Name()) == workload {
			cmd := "kubectl apply -f " + filename + " --kubeconfig=" + tc.KubeconfigFile
			return RunCommand(cmd)
		}
	}
	return "", nil
}

func KillK3sCluster(nodes []VagrantNode) error {
	for _, node := range nodes {
		if _, err := node.RunCmdOnNode("k3s-killall.sh"); err != nil {
			return err
		}
		if _, err := node.RunCmdOnNode("rm -rf /etc/rancher/k3s/config.yaml.d /var/lib/kubelet/pods /var/lib/rancher/k3s/agent/etc /var/lib/rancher/k3s/agent/containerd /var/lib/rancher/k3s/server/db /var/log/pods /run/k3s /run/flannel"); err != nil {
			return err
		}
		if _, err := node.RunCmdOnNode("journalctl --flush --sync --rotate --vacuum-size=1"); err != nil {
			return err
		}
	}
	return nil
}

func DestroyCluster() error {
	if out, err := RunCommand("vagrant destroy -f"); err != nil {
		return fmt.Errorf("%v - command output:\n%s", err, out)
	}
	return os.Remove("vagrant.log")
}

func FetchClusterIP(kubeconfig string, servicename string, dualStack bool) (string, error) {
	if dualStack {
		cmd := "kubectl get svc " + servicename + " -o jsonpath='{.spec.clusterIPs}' --kubeconfig=" + kubeconfig
		res, err := RunCommand(cmd)
		if err != nil {
			return res, err
		}
		res = strings.ReplaceAll(res, "\"", "")
		return strings.Trim(res, "[]"), nil
	}
	cmd := "kubectl get svc " + servicename + " -o jsonpath='{.spec.clusterIP}' --kubeconfig=" + kubeconfig
	return RunCommand(cmd)