DrainPrimary drains the node containing the primary pod. It returns the names of the pods that were running on that node
( ctx context.Context, crudClient client.Client, namespace, clusterName string, timeoutSeconds int, )
| 38 | // DrainPrimary drains the node containing the primary pod. |
| 39 | // It returns the names of the pods that were running on that node |
| 40 | func DrainPrimary( |
| 41 | ctx context.Context, |
| 42 | crudClient client.Client, |
| 43 | namespace, |
| 44 | clusterName string, |
| 45 | timeoutSeconds int, |
| 46 | ) []string { |
| 47 | var primaryNode string |
| 48 | var podNames []string |
| 49 | By("identifying primary node and draining", func() { |
| 50 | pod, err := clusterutils.GetPrimary(ctx, crudClient, namespace, clusterName) |
| 51 | Expect(err).ToNot(HaveOccurred()) |
| 52 | primaryNode = pod.Spec.NodeName |
| 53 | |
| 54 | // Gather the pods running on this node |
| 55 | podList, err := clusterutils.ListPods(ctx, crudClient, namespace, clusterName) |
| 56 | Expect(err).ToNot(HaveOccurred()) |
| 57 | for _, pod := range podList.Items { |
| 58 | if pod.Spec.NodeName == primaryNode { |
| 59 | podNames = append(podNames, pod.Name) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Draining the primary pod's node |
| 64 | var stdout, stderr string |
| 65 | Eventually(func() error { |
| 66 | cmd := fmt.Sprintf("kubectl drain %v --ignore-daemonsets --delete-emptydir-data --force --timeout=%ds", |
| 67 | primaryNode, timeoutSeconds) |
| 68 | stdout, stderr, err = run.Unchecked(cmd) |
| 69 | return err |
| 70 | }, timeoutSeconds).ShouldNot(HaveOccurred(), fmt.Sprintf("stdout: %s, stderr: %s", stdout, stderr)) |
| 71 | }) |
| 72 | By("ensuring no cluster pod is still running on the drained node", func() { |
| 73 | Eventually(func() ([]string, error) { |
| 74 | podList, err := clusterutils.ListPods(ctx, crudClient, namespace, clusterName) |
| 75 | usedNodes := make([]string, 0, len(podList.Items)) |
| 76 | for _, pod := range podList.Items { |
| 77 | usedNodes = append(usedNodes, pod.Spec.NodeName) |
| 78 | } |
| 79 | return usedNodes, err |
| 80 | }, 60).ShouldNot(ContainElement(primaryNode)) |
| 81 | }) |
| 82 | |
| 83 | return podNames |
| 84 | } |
| 85 | |
| 86 | // UncordonAll executes the 'kubectl uncordon' command on each node of the list |
| 87 | func UncordonAll( |
no test coverage detected