mirror of https://github.com/k3s-io/k3s
Improve error handling of CheckDeployments test helper
Expose actual error, so that we can tell if the deployment is not found or not ready/available Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/11498/head
parent
68f26fe9ac
commit
93e548326a
|
@ -130,33 +130,24 @@ func K3sServerArgs() []string {
|
||||||
|
|
||||||
// K3sDefaultDeployments checks if the default deployments for K3s are ready, otherwise returns an error
|
// K3sDefaultDeployments checks if the default deployments for K3s are ready, otherwise returns an error
|
||||||
func K3sDefaultDeployments() error {
|
func K3sDefaultDeployments() error {
|
||||||
return CheckDeployments([]string{"coredns", "local-path-provisioner", "metrics-server", "traefik"})
|
return CheckDeployments(metav1.NamespaceSystem, []string{"coredns", "local-path-provisioner", "metrics-server", "traefik"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckDeployments checks if the provided list of deployments are ready, otherwise returns an error
|
// CheckDeployments checks if the provided list of deployments are ready, otherwise returns an error
|
||||||
func CheckDeployments(deployments []string) error {
|
func CheckDeployments(namespace string, deployments []string) error {
|
||||||
|
|
||||||
deploymentSet := make(map[string]bool)
|
|
||||||
for _, d := range deployments {
|
|
||||||
deploymentSet[d] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := k8sClient()
|
client, err := k8sClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
deploymentList, err := client.AppsV1().Deployments("").List(context.Background(), metav1.ListOptions{})
|
|
||||||
if err != nil {
|
for _, deploymentName := range deployments {
|
||||||
return err
|
deployment, err := client.AppsV1().Deployments(namespace).Get(context.Background(), deploymentName, metav1.GetOptions{})
|
||||||
}
|
if err != nil {
|
||||||
for _, deployment := range deploymentList.Items {
|
return err
|
||||||
if _, ok := deploymentSet[deployment.Name]; ok && deployment.Status.ReadyReplicas == deployment.Status.Replicas {
|
|
||||||
deploymentSet[deployment.Name] = true
|
|
||||||
}
|
}
|
||||||
}
|
if deployment.Status.ReadyReplicas != deployment.Status.Replicas || deployment.Status.AvailableReplicas != deployment.Status.Replicas {
|
||||||
for d, found := range deploymentSet {
|
return fmt.Errorf("deployment %s not ready: replicas=%d readyReplicas=%d availableReplicas=%d",
|
||||||
if !found {
|
deploymentName, deployment.Status.Replicas, deployment.Status.ReadyReplicas, deployment.Status.AvailableReplicas)
|
||||||
return fmt.Errorf("failed to deploy %s", d)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ var _ = Describe("startup tests", Ordered, func() {
|
||||||
})
|
})
|
||||||
It("has the default pods without traefik deployed", func() {
|
It("has the default pods without traefik deployed", func() {
|
||||||
Eventually(func() error {
|
Eventually(func() error {
|
||||||
return testutil.CheckDeployments([]string{"coredns", "local-path-provisioner", "metrics-server"})
|
return testutil.CheckDeployments("kube-system", []string{"coredns", "local-path-provisioner", "metrics-server"})
|
||||||
}, "90s", "10s").Should(Succeed())
|
}, "90s", "10s").Should(Succeed())
|
||||||
nodes, err := testutil.ParseNodes()
|
nodes, err := testutil.ParseNodes()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue