-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Makes use of the capi e2e framework * Simple test for `clusterctl init` * Added a script to run clusterctl e2e tests. The script will issue a `make docker-build` and setup env var to load image into kind. * Added a `clusterctl config cluster` test.
- Loading branch information
1 parent
f208101
commit 219e74f
Showing
7 changed files
with
949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// +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 ( | ||
"fmt" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
clusterctlclient "sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client" | ||
clusterctlrepo "sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client/repository" | ||
"sigs.k8s.io/cluster-api/test/framework/management/kind" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var _ = Describe("clusterctl config cluster", func() { | ||
Describe("basic", func() { | ||
var ( | ||
cfgFile string // default is $HOME/clusterctl.yaml | ||
kindCluster *kind.Cluster | ||
kindClient client.Client | ||
clusterName string | ||
kubernetesVersion string | ||
coreProvider string | ||
coreVersion string | ||
bootstrapProvider string | ||
bootstrapVersion string | ||
infrastructureProvider string | ||
infrastructureVersion string | ||
tmpDir string | ||
template clusterctlrepo.Template | ||
) | ||
BeforeEach(func() { | ||
clusterName = "e2e-workload-cluster" | ||
kubernetesVersion = "1.14.2" | ||
coreProvider = "cluster-api" | ||
coreVersion = "v0.3.0" | ||
bootstrapProvider = "kubeadm-bootstrap" | ||
bootstrapVersion = "v0.3.0" | ||
infrastructureProvider = "docker" | ||
infrastructureVersion = "v0.3.0" | ||
var err error | ||
|
||
// Create the mgmt cluster and client | ||
kindCluster, kindClient, err = CreateKindClusterAndClient() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// Create clusterctl.yaml | ||
tmpDir = createTempDir() | ||
cfgFile = createLocalTestClusterCtlConfig(tmpDir, "clusterctl.yaml", "DOCKER_SERVICE_DOMAIN: \"docker.cluster.local\"") | ||
// Let's setup some varibles for the workload cluster template | ||
os.Setenv("DOCKER_SERVICE_CIDRS", "\"10.96.0.0/12\"") | ||
os.Setenv("DOCKER_POD_CIDRS", "\"192.168.0.0/16\"") | ||
|
||
c, err := clusterctlclient.New(cfgFile) | ||
Expect(err).ToNot(HaveOccurred()) | ||
initOpt := clusterctlclient.InitOptions{ | ||
Kubeconfig: kindCluster.KubeconfigPath, | ||
CoreProvider: coreProvider + ":" + coreVersion, | ||
BootstrapProviders: []string{bootstrapProvider + ":" + bootstrapVersion}, | ||
InfrastructureProviders: []string{infrastructureProvider + ":" + infrastructureVersion}, | ||
} | ||
_, _, err = c.Init(initOpt) | ||
Expect(err).ToNot(HaveOccurred()) | ||
// Confirm controllers exists | ||
CheckAndWaitDeploymentExists(kindClient, "capi-system", "capi-controller-manager") | ||
CheckAndWaitDeploymentExists(kindClient, "capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager") | ||
CheckAndWaitDeploymentExists(kindClient, "capd-system", "capd-controller-manager") | ||
|
||
options := clusterctlclient.GetClusterTemplateOptions{ | ||
Kubeconfig: kindCluster.KubeconfigPath, | ||
InfrastructureProvider: infrastructureProvider, | ||
BootstrapProvider: bootstrapProvider, | ||
ClusterName: clusterName, | ||
Flavor: "", | ||
// TargetNamespace: targetNamespace, | ||
KubernetesVersion: kubernetesVersion, | ||
ControlPlaneMachineCount: 1, | ||
WorkerMachineCount: 0, | ||
} | ||
|
||
template, err = c.GetClusterTemplate(options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
}) | ||
|
||
AfterEach(func() { | ||
fmt.Fprintf(GinkgoWriter, "Tearing down kind cluster\n") | ||
kindCluster.Teardown(ctx) | ||
os.RemoveAll(tmpDir) | ||
}) | ||
|
||
Context("using default infra and bootstrap provider", func() { | ||
It("should generate a yaml file for a workload cluster", func() { | ||
provider := template.Name() | ||
Expect(provider).To(Equal(infrastructureProvider)) | ||
version := template.Version() | ||
Expect(version).To(Equal(infrastructureVersion)) | ||
bootstrap := template.Bootstrap() | ||
Expect(bootstrap).To(Equal(bootstrapProvider)) | ||
|
||
variables := template.Variables() | ||
fmt.Fprintf(GinkgoWriter, "%v", variables) | ||
yaml, err := template.Yaml() | ||
Expect(err).ToNot(HaveOccurred()) | ||
yaml = append(yaml, '\n') | ||
fmt.Fprintf(GinkgoWriter, "%v", string(yaml)) | ||
|
||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// +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" | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestE2E(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "ClusterCtl E2E Suite") | ||
} | ||
|
||
const ( | ||
setupTimeout = 10 * 60 | ||
) | ||
|
||
var ( | ||
ctx context.Context | ||
managerImage string | ||
) | ||
|
||
var _ = BeforeSuite(func() { | ||
ctx = context.Background() | ||
// Docker image to load into the kind cluster for testing | ||
managerImage = os.Getenv("MANAGER_IMAGE") | ||
if managerImage == "" { | ||
managerImage = "gcr.io/k8s-staging-capi-docker/capd-manager-amd64:dev" | ||
} | ||
}, setupTimeout) | ||
|
||
var _ = AfterSuite(func() { | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module sigs.k8s.io/cluster-api/cmd/clusterctl/test/e2e | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/onsi/ginkgo v1.11.0 | ||
github.com/onsi/gomega v1.8.1 | ||
k8s.io/api v0.0.0-20191121015604-11707872ac1c | ||
k8s.io/client-go v11.0.0+incompatible | ||
sigs.k8s.io/cluster-api v0.2.9 | ||
sigs.k8s.io/cluster-api/test/framework v0.0.0-20200125173702-54f26d7fd2b5 | ||
sigs.k8s.io/cluster-api/test/infrastructure/docker v0.0.0-20200125173702-54f26d7fd2b5 | ||
sigs.k8s.io/controller-runtime v0.4.0 | ||
) | ||
|
||
replace ( | ||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90 | ||
sigs.k8s.io/cluster-api => ../../../.. | ||
sigs.k8s.io/cluster-api/test/framework => ../../../../test/framework | ||
) |
Oops, something went wrong.