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

Code before:
			e2e.DumpPods(tc.KubeconfigFile)
		})

		It("Creates test resources before migration", func() {
			createCmd := "kubectl create configmap migration-test --from-literal=test=before-migration"
			_, err := tc.Servers[0].RunCmdOnNode(createCmd)
			Expect(err).NotTo(HaveOccurred())

			getCmd := "kubectl get configmap migration-test -o jsonpath='{.data.test}'"
			result, err := tc.Servers[0].RunCmdOnNode(getCmd)
			Expect(err).NotTo(HaveOccurred())
			Expect(result).To(ContainSubstring("before-migration"))
		})

		It("Migrates from SQLite to etcd", func() {
			configCmd := "echo 'cluster-init: true' >> /etc/rancher/k3s/config.yaml"
			_, err := tc.Servers[0].RunCmdOnNode(configCmd)
			Expect(err).NotTo(HaveOccurred())

			Expect(e2e.RestartCluster(tc.Servers)).To(Succeed())
			Expect(e2e.RestartCluster(tc.Agents)).To(Succeed())

			Eventually(func() (string, error) {
				cmd := "kubectl get node server-0 --show-labels"
				return tc.Servers[0].RunCmdOnNode(cmd)
			}, "120s", "5s").Should(ContainSubstring("node-role.kubernetes.io/etcd=true"))
		})

		It("Checks node and pod status after migration", func() {
			By("Fetching node status after migration")
			Eventually(func() error {
				return tests.NodesReady(tc.KubeconfigFile, e2e.VagrantSlice(tc.AllNodes()))
			}, "600s", "5s").Should(Succeed())
			Eventually(func() error {
				return tests.AllPodsUp(tc.KubeconfigFile)
			}, "600s", "5s").Should(Succeed())
			Eventually(func() error {
				return tests.CheckDefaultDeployments(tc.KubeconfigFile)
			}, "480s", "10s").Should(Succeed())
			e2e.DumpPods(tc.KubeconfigFile)
		})

		It("Verifies data persistence after migration", func() {
			getCmd := "kubectl get configmap migration-test -o jsonpath='{.data.test}'"
			result, err := tc.Servers[0].RunCmdOnNode(getCmd)
			Expect(err).NotTo(HaveOccurred())
			Expect(result).To(ContainSubstring("before-migration"))
		})

		It("Kills the cluster", func() {
			err := e2e.KillK3sCluster(tc.AllNodes())

Review comment (suggestion):
nit: its a label, use it to filter the node list
```suggestion
				cmd := "kubectl get nodes -l node-role.kubernetes.io/etcd=true"
				return tc.Servers[0].RunCmdOnNode(cmd)
			}, "120s", "5s").Should(ContainSubstring(tc.Servers[0].String()))
```

Code after:
			e2e.DumpPods(tc.KubeconfigFile)
		})

		It("Creates test resources before migration", func() {
			createCmd := "kubectl create configmap migration-test --from-literal=test=before-migration"
			_, err := tc.Servers[0].RunCmdOnNode(createCmd)
			Expect(err).NotTo(HaveOccurred())

			getCmd := "kubectl get configmap migration-test -o jsonpath='{.data.test}'"
			result, err := tc.Servers[0].RunCmdOnNode(getCmd)
			Expect(err).NotTo(HaveOccurred())
			Expect(result).To(ContainSubstring("before-migration"))
		})

		It("Migrates from SQLite to etcd", func() {
			configCmd := "echo 'cluster-init: true' >> /etc/rancher/k3s/config.yaml"
			_, err := tc.Servers[0].RunCmdOnNode(configCmd)
			Expect(err).NotTo(HaveOccurred())

			Expect(e2e.RestartCluster(tc.Servers)).To(Succeed())
			Expect(e2e.RestartCluster(tc.Agents)).To(Succeed())

			Eventually(func() (string, error) {
				cmd := "kubectl get nodes -l node-role.kubernetes.io/etcd=true"
				return tc.Servers[0].RunCmdOnNode(cmd)
			}, "120s", "5s").Should(ContainSubstring(tc.Servers[0].String()))
		})

		It("Checks node and pod status after migration", func() {
			By("Fetching node status after migration")
			Eventually(func() error {
				return tests.NodesReady(tc.KubeconfigFile, e2e.VagrantSlice(tc.AllNodes()))
			}, "600s", "5s").Should(Succeed())
			Eventually(func() error {
				return tests.AllPodsUp(tc.KubeconfigFile)
			}, "600s", "5s").Should(Succeed())
			Eventually(func() error {
				return tests.CheckDefaultDeployments(tc.KubeconfigFile)
			}, "480s", "10s").Should(Succeed())
			e2e.DumpPods(tc.KubeconfigFile)
		})

		It("Verifies data persistence after migration", func() {
			getCmd := "kubectl get configmap migration-test -o jsonpath='{.data.test}'"
			result, err := tc.Servers[0].RunCmdOnNode(getCmd)
			Expect(err).NotTo(HaveOccurred())
			Expect(result).To(ContainSubstring("before-migration"))
		})

		It("Kills the cluster", func() {
			err := e2e.KillK3sCluster(tc.AllNodes())