Skip to content

Commit

Permalink
Merge pull request #2785 from wfernandes/etcd-e2e-tests
Browse files Browse the repository at this point in the history
🏃Add Etcd e2e tests
  • Loading branch information
k8s-ci-robot authored Mar 27, 2020
2 parents 1717c75 + d205b68 commit 2cc8570
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 218 deletions.
2 changes: 0 additions & 2 deletions test/framework/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ type WaitForControlPlaneToBeReadyInput struct {
}

// WaitForControlPlaneToBeReady will wait for a control plane to be ready.
// TODO(chuckha): Once we implement control plane Ready, then we should update this to wait actually wait for ready.
// TODO(chuckha): In the meantime this uses initialized as a placeholder for Ready.
func WaitForControlPlaneToBeReady(ctx context.Context, input WaitForControlPlaneToBeReadyInput, intervals ...interface{}) {
By("waiting for the control plane to be ready")
Eventually(func() (bool, error) {
Expand Down
100 changes: 100 additions & 0 deletions test/framework/workload_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package framework

import (
"context"
"fmt"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// podListCondition is a type that operates a condition on a Pod
type podListCondition func(p *corev1.PodList) error

// WaitForPodListConditionInput is the input args for WaitForPodListCondition
type WaitForPodListConditionInput struct {
Lister Lister
ListOptions *client.ListOptions
Condition podListCondition
}

// WaitForPodListCondition waits for the specified condition to be true for all
// pods returned from the list filter.
func WaitForPodListCondition(ctx context.Context, input WaitForPodListConditionInput, intervals ...interface{}) {
Eventually(func() (bool, error) {
podList := &corev1.PodList{}
if err := input.Lister.List(ctx, podList, input.ListOptions); err != nil {
return false, err
}
Expect(len(podList.Items)).ToNot(BeZero())

// all pods in the list should satisfy the condition
err := input.Condition(podList)
if err != nil {
// DEBUG:
fmt.Println(err.Error())
return false, err
}
return true, nil
}, intervals...).Should(BeTrue())
By("pod condition satisfied")
}

// EtcdImageTagCondition returns a podListCondition that ensures the pod image
// contains the specified image tag
func EtcdImageTagCondition(expectedTag string, expectedCount int) podListCondition {
return func(pl *corev1.PodList) error {
countWithCorrectTag := 0
for _, pod := range pl.Items {
if strings.Contains(pod.Spec.Containers[0].Image, expectedTag) {
countWithCorrectTag++
}
}
if countWithCorrectTag != expectedCount {
return errors.Errorf("etcdImageTagCondition: expected %d pods to have image tag %q, got %d", expectedCount, expectedTag, countWithCorrectTag)
}

// This check is to ensure that if there are three controlplane nodes,
// then there are only three etcd pods running. Currently, we create a
// new etcd pod before deleting the previous one. So we can have a
// case where there are three etcd pods with the correct tag and one
// left over that has yet to be deleted.
if len(pl.Items) != expectedCount {
return errors.Errorf("etcdImageTagCondition: expected %d pods, got %d", expectedCount, len(pl.Items))
}
return nil
}
}

// PhasePodCondition is a podListCondition ensuring that pods are in the expected
// pod phase
func PhasePodCondition(expectedPhase corev1.PodPhase) podListCondition {
return func(pl *corev1.PodList) error {
for _, pod := range pl.Items {
if pod.Status.Phase != expectedPhase {
return errors.Errorf("pod %q is not %s", pod.Name, expectedPhase)
}
}
return nil
}
}
2 changes: 1 addition & 1 deletion test/infrastructure/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test-e2e: ## Run the end-to-end tests
E2E_CONF_FILE ?= e2e/local-e2e.conf
SKIP_RESOURCE_CLEANUP ?= false
run-e2e:
go test ./e2e -v -ginkgo.v -ginkgo.trace -count=1 -timeout=20m -tags=e2e -e2e.config="$(abspath $(E2E_CONF_FILE))" -skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP)
go test ./e2e -v -ginkgo.v -ginkgo.trace -count=1 -timeout=35m -tags=e2e -e2e.config="$(abspath $(E2E_CONF_FILE))" -skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP)

## --------------------------------------
## Binaries
Expand Down
23 changes: 0 additions & 23 deletions test/infrastructure/docker/e2e/docker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,6 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
deleteClusterInput := framework.DeleteClusterInput{
Deleter: mgmtClient,
Cluster: cluster,
}
framework.DeleteCluster(ctx, deleteClusterInput)

waitForClusterDeletedInput := framework.WaitForClusterDeletedInput{
Getter: mgmtClient,
Cluster: cluster,
}
framework.WaitForClusterDeleted(ctx, waitForClusterDeletedInput)

assertAllClusterAPIResourcesAreGoneInput := framework.AssertAllClusterAPIResourcesAreGoneInput{
Lister: mgmtClient,
Cluster: cluster,
}
framework.AssertAllClusterAPIResourcesAreGone(ctx, assertAllClusterAPIResourcesAreGoneInput)

ensureDockerDeletedInput := ensureDockerArtifactsDeletedInput{
Lister: mgmtClient,
Cluster: cluster,
}
ensureDockerArtifactsDeleted(ensureDockerDeletedInput)

// Dump the logs of the providers before deleting them.
Expect(writeLogs(mgmt, "capi-system", "capi-controller-manager", logPath)).To(Succeed())
Expand Down
Loading

0 comments on commit 2cc8570

Please sign in to comment.