Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add Kubernetes conformance E2E test #3811

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ variables:
CNI: "./data/cni/kindnet/kindnet.yaml"
EXP_CLUSTER_RESOURCE_SET: "true"
EXP_MACHINE_POOL: "true"
KUBETEST_CONFIGURATION: "./data/kubetest/conformance.yaml"

intervals:
default/wait-controllers: ["3m", "10s"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ spec:
controllerManager:
extraArgs: {enable-hostpath-provisioner: 'true'}
apiServer:
certSANs: [localhost, 127.0.0.1, 0.0.0.0]
# host.docker.internal is required by kubetest when running on MacOS because of the way ports are proxied.
certSANs: [localhost, 127.0.0.1, 0.0.0.0, host.docker.internal]
initConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/data/kubetest/conformance-fast.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ginkgo.focus: \[Conformance\]
ginkgo.skip: \[sig-scheduling\].*\[Serial\]
disable-log-dump: true
ginkgo.progress: true
ginkgo.slowSpecThreshold: 120.0
ginkgo.flakeAttempts: 3
ginkgo.trace: true
ginkgo.v: true
7 changes: 7 additions & 0 deletions test/e2e/data/kubetest/conformance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ginkgo.focus: \[Conformance\]
disable-log-dump: true
ginkgo.progress: true
ginkgo.slowSpecThreshold: 120.0
ginkgo.flakeAttempts: 3
ginkgo.trace: true
ginkgo.v: true
7 changes: 2 additions & 5 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ package e2e
import (
"context"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -84,8 +81,8 @@ func TestE2E(t *testing.T) {
}

RegisterFailHandler(Fail)
junitPath := filepath.Join(artifactFolder, fmt.Sprintf("junit.e2e_suite.%d.xml", config.GinkgoConfig.ParallelNode))
junitReporter := reporters.NewJUnitReporter(junitPath)

junitReporter := framework.CreateJUnitReporterForProw(artifactFolder)
RunSpecsWithDefaultAndCustomReporters(t, "capi-e2e", []Reporter{junitReporter})
}

Expand Down
125 changes: 125 additions & 0 deletions test/e2e/k8s_conformance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
Copyright 2020 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 e2e

import (
"context"
"fmt"
"os"
"path/filepath"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved

fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/test/framework/kubetest"
"sigs.k8s.io/cluster-api/util"
)

// K8SConformanceSpecInput is the input for K8SConformanceSpec.
type K8SConformanceSpecInput struct {
E2EConfig *clusterctl.E2EConfig
ClusterctlConfigPath string
BootstrapClusterProxy framework.ClusterProxy
ArtifactFolder string
SkipCleanup bool
}

// K8SConformanceSpec implements a spec that creates a cluster and runs Kubernetes conformance suite.
func K8SConformanceSpec(ctx context.Context, inputGetter func() K8SConformanceSpecInput) {
const (
kubetestConfigurationVariable = "KUBETEST_CONFIGURATION"
)
var (
specName = "k8s-conformance"
input K8SConformanceSpecInput
namespace *corev1.Namespace
cancelWatches context.CancelFunc
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
kubetestConfigFilePath string
)

BeforeEach(func() {
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName)
input = inputGetter()
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName)
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName)
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName)
Expect(os.MkdirAll(input.ArtifactFolder, 0755)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName)

Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion))
Expect(input.E2EConfig.Variables).To(HaveKey(kubetestConfigurationVariable), "% spec requires a %s variable to be defined in the config file", specName, kubetestConfigurationVariable)
kubetestConfigFilePath = input.E2EConfig.GetVariable(kubetestConfigurationVariable)
Expect(kubetestConfigFilePath).To(BeAnExistingFile(), "%s should be a valid kubetest config file")

// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder)
})

It("Should create a workload cluster and run kubetest", func() {

By("Creating a workload cluster")

// NOTE: The number of CP nodes does not have relevance for conformance; instead, the number of workers allows
// better parallelism of tests and thus a lower execution time.
var workerMachineCount int64 = 5

clusterResources = clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
ClusterProxy: input.BootstrapClusterProxy,
ConfigCluster: clusterctl.ConfigClusterInput{
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()),
ClusterctlConfigPath: input.ClusterctlConfigPath,
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
Flavor: clusterctl.DefaultFlavor,
Namespace: namespace.Name,
ClusterName: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersion),
ControlPlaneMachineCount: pointer.Int64Ptr(1),
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
WorkerMachineCount: pointer.Int64Ptr(workerMachineCount),
},
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"),
WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
})

workloadProxy := input.BootstrapClusterProxy.GetWorkloadCluster(ctx, namespace.Name, clusterResources.Cluster.Name)

// Start running conformance test suites.
err := kubetest.Run(
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
ctx,
kubetest.RunInput{
ClusterProxy: workloadProxy,
NumberOfNodes: int(workerMachineCount),
ArtifactsDirectory: input.ArtifactFolder,
ConfigFilePath: kubetestConfigFilePath,
GinkgoNodes: int(workerMachineCount),
},
)
Expect(err).ToNot(HaveOccurred(), "Failed to run Kubernetes conformance")

By("PASSED!")
})

AfterEach(func() {
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
})
}
39 changes: 39 additions & 0 deletions test/e2e/k8s_conformance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// +build e2e

/*
Copyright 2020 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 e2e

import (
"context"

. "github.com/onsi/ginkgo"
)

var _ = Describe("When testing K8S conformance", func() {

K8SConformanceSpec(context.TODO(), func() K8SConformanceSpecInput {
return K8SConformanceSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
}
})

})