Skip to content

Commit 2034667

Browse files
committed
Create cluster-api-tests-ext command for origin e2e
1 parent 483b633 commit 2034667

File tree

10,411 files changed

+2878304
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

10,411 files changed

+2878304
-195
lines changed

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,16 @@ issues:
134134
- gochecknoglobals
135135
- err113
136136
- wrapcheck
137+
138+
# Exclude some linters from running on tests files.
139+
- path: e2e/.*|e2e/framework/.*
140+
linters:
141+
- gocyclo
142+
- dupl
143+
- gosec
144+
- gochecknoglobals
145+
- err113
146+
- wrapcheck
147+
- funlen
148+
- prealloc
149+
- revive

Dockerfile.rhel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.20 AS builder
22
WORKDIR /go/src/github.com/openshift/cluster-capi-operator
33
COPY . .
4-
RUN make build
4+
RUN make build && \
5+
mkdir -p /tmp/build && \
6+
cp /go/src/github.com/openshift/cluster-capi-operator/bin/cluster-api-tests-ext /tmp/build/cluster-api-tests-ext && \
7+
gzip /tmp/build/cluster-api-tests-ext
58

69
FROM registry.ci.openshift.org/ocp/4.20:base-rhel9
710
COPY --from=builder /go/src/github.com/openshift/cluster-capi-operator/bin/cluster-capi-operator .
811
COPY --from=builder /go/src/github.com/openshift/cluster-capi-operator/bin/machine-api-migration .
912
COPY --from=builder /go/src/github.com/openshift/cluster-capi-operator/manifests /manifests
13+
COPY --from=builder /tmp/build/cluster-api-tests-ext.gz .
1014

11-
LABEL io.openshift.release.operator true
15+
LABEL io.k8s.display-name="OpenShift Cluster CAPI Operator" \
16+
io.openshift.release.operator=true \
17+
io.openshift.tags="openshift,tests,e2e,e2e-extension"

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ verify: fmt lint
2424
test: verify unit
2525

2626
# Build binaries
27-
build: operator migration manifests-gen
27+
build: operator migration manifests-gen cluster-api-tests-ext
2828

2929
.PHONY: manifests-gen
3030
manifests-gen:
@@ -39,6 +39,10 @@ migration:
3939
# building migration
4040
go build -o bin/machine-api-migration cmd/machine-api-migration/main.go
4141

42+
cluster-api-tests-ext:
43+
# building cluster-api-tests-ext
44+
go build -o bin/cluster-api-tests-ext ./cmd/cluster-api-tests-ext
45+
4246
.PHONY: localtestenv
4347
localtestenv: .localtestenv
4448

@@ -52,7 +56,7 @@ unit: .localtestenv
5256

5357
.PHONY: e2e
5458
e2e:
55-
./hack/test.sh "./e2e/..." 30m
59+
./hack/test.sh "./e2e/..." 60m
5660

5761
# Run against the configured Kubernetes cluster in ~/.kube/config
5862
run:

cmd/cluster-api-tests-ext/main.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2024 Red Hat, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package main
15+
16+
import (
17+
"fmt"
18+
"os"
19+
20+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
21+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
22+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
23+
"github.com/spf13/cobra"
24+
25+
// If using ginkgo, import your tests here.
26+
_ "github.com/openshift/cluster-capi-operator/e2e"
27+
)
28+
29+
func main() {
30+
extensionRegistry := e.NewRegistry()
31+
capiExtension := e.NewExtension("openshift", "payload", "cluster-capi-operator")
32+
extensionRegistry.Register(capiExtension)
33+
34+
capiExtension.AddSuite(e.Suite{
35+
Name: "capio/conformance/parallel",
36+
Parents: []string{
37+
"openshift/conformance/parallel",
38+
},
39+
Qualifiers: []string{`!labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance")`},
40+
})
41+
42+
capiExtension.AddSuite(e.Suite{
43+
Name: "capio/conformance/serial",
44+
Parents: []string{
45+
"openshift/conformance/serial",
46+
},
47+
Qualifiers: []string{`labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance")`},
48+
})
49+
50+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
51+
if err != nil {
52+
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
53+
}
54+
55+
capiExtension.AddSpecs(specs)
56+
57+
root := &cobra.Command{
58+
Long: "Cluster CAPI Operator tests extension for OpenShift",
59+
}
60+
61+
root.AddCommand(cmd.DefaultExtensionCommands(extensionRegistry)...)
62+
63+
if err := func() error {
64+
return root.Execute()
65+
}(); err != nil {
66+
os.Exit(1)
67+
}
68+
}

e2e/aws_test.go renamed to e2e/aws.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Red Hat, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package e2e
216

317
import (
@@ -28,7 +42,7 @@ const (
2842
machineSetOpenshiftLabelKey = "machine.openshift.io/cluster-api-machineset"
2943
)
3044

31-
var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
45+
var _ = Describe("Cluster API AWS MachineSet", Ordered, Label("Conformance"), Label("Serial"), func() {
3246
var (
3347
awsMachineTemplate *awsv1.AWSMachineTemplate
3448
machineSet *clusterv1.MachineSet
@@ -38,11 +52,12 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
3852
)
3953

4054
BeforeAll(func() {
55+
InitCommonVariables()
4156
if platform != configv1.AWSPlatformType {
4257
Skip("Skipping AWS E2E tests")
4358
}
44-
mapiDefaultMS, mapiDefaultProviderSpec = getDefaultAWSMAPIProviderSpec(cl)
45-
awsClient = createAWSClient(mapiDefaultProviderSpec.Placement.Region)
59+
mapiDefaultMS, mapiDefaultProviderSpec = getDefaultAWSMAPIProviderSpec(cl, ctx)
60+
awsClient = createAWSClient(ctx, mapiDefaultProviderSpec.Placement.Region)
4661
})
4762

4863
AfterEach(func() {
@@ -51,8 +66,8 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
5166
// explicitly skip it here for other platforms.
5267
Skip("Skipping AWS E2E tests")
5368
}
54-
framework.DeleteMachineSets(cl, machineSet)
55-
framework.WaitForMachineSetsDeleted(cl, machineSet)
69+
framework.DeleteMachineSets(cl, ctx, machineSet)
70+
framework.WaitForMachineSetsDeleted(cl, ctx, machineSet)
5671
framework.DeleteObjects(cl, awsMachineTemplate)
5772
})
5873

@@ -62,7 +77,7 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
6277
Expect(err).ToNot(HaveOccurred())
6378
}
6479

65-
machineSet = framework.CreateMachineSet(cl, framework.NewMachineSetParams(
80+
machineSet = framework.CreateMachineSet(cl, ctx, framework.NewMachineSetParams(
6681
"aws-machineset",
6782
clusterName,
6883
"",
@@ -75,13 +90,13 @@ var _ = Describe("Cluster API AWS MachineSet", Ordered, func() {
7590
"worker-user-data",
7691
))
7792

78-
framework.WaitForMachineSet(cl, machineSet.Name, machineSet.Namespace)
93+
framework.WaitForMachineSet(cl, ctx, machineSet.Name, machineSet.Namespace)
7994

8095
compareInstances(awsClient, mapiDefaultMS.Name, "aws-machineset")
8196
})
8297
})
8398

84-
func getDefaultAWSMAPIProviderSpec(cl client.Client) (*mapiv1.MachineSet, *mapiv1.AWSMachineProviderConfig) {
99+
func getDefaultAWSMAPIProviderSpec(cl client.Client, ctx context.Context) (*mapiv1.MachineSet, *mapiv1.AWSMachineProviderConfig) {
85100
machineSetList := &mapiv1.MachineSetList{}
86101
Expect(cl.List(ctx, machineSetList, client.InNamespace(framework.MAPINamespace))).To(Succeed())
87102

@@ -158,15 +173,17 @@ func newAWSMachineTemplate(mapiProviderSpec *mapiv1.AWSMachineProviderConfig) *a
158173
return awsMachineTemplate
159174
}
160175

161-
func createAWSClient(region string) *ec2.EC2 {
176+
func createAWSClient(ctx context.Context, region string) *ec2.EC2 {
162177
var secret corev1.Secret
163-
Expect(cl.Get(context.Background(), client.ObjectKey{
178+
179+
Expect(cl.Get(ctx, client.ObjectKey{
164180
Namespace: framework.CAPINamespace,
165181
Name: "capa-manager-bootstrap-credentials",
166182
}, &secret)).To(Succeed())
167183

168184
accessKey := secret.Data["aws_access_key_id"]
169185
Expect(accessKey).ToNot(BeNil())
186+
170187
secretAccessKey := secret.Data["aws_secret_access_key"]
171188
Expect(secretAccessKey).ToNot(BeNil())
172189

@@ -188,6 +205,7 @@ func createAWSClient(region string) *ec2.EC2 {
188205
func getMAPICreatedInstance(awsClient *ec2.EC2, msName string) ec2.Instance {
189206
Expect(awsClient).ToNot(BeNil())
190207
Expect(msName).ToNot(BeEmpty())
208+
191209
mapiMachineList := &mapiv1.MachineList{}
192210
Expect(cl.List(ctx, mapiMachineList, client.InNamespace(framework.MAPINamespace), client.MatchingLabels{
193211
machineSetOpenshiftLabelKey: msName,
@@ -219,6 +237,7 @@ func getMAPICreatedInstance(awsClient *ec2.EC2, msName string) ec2.Instance {
219237
func getCAPICreatedInstance(awsClient *ec2.EC2, msName string) ec2.Instance {
220238
Expect(awsClient).ToNot(BeNil())
221239
Expect(msName).ToNot(BeEmpty())
240+
222241
capiMachineList := &awsv1.AWSMachineList{}
223242

224243
Expect(cl.List(ctx, capiMachineList, client.InNamespace(framework.CAPINamespace), client.MatchingLabels{
@@ -244,6 +263,7 @@ func getCAPICreatedInstance(awsClient *ec2.EC2, msName string) ec2.Instance {
244263

245264
func compareInstances(awsClient *ec2.EC2, mapiMsName, capiMsName string) {
246265
By("Comparing instances created by MAPI and CAPI")
266+
247267
mapiEC2Instance := getMAPICreatedInstance(awsClient, mapiMsName)
248268
capiEC2Instance := getCAPICreatedInstance(awsClient, capiMsName)
249269

@@ -272,7 +292,7 @@ func compareInstances(awsClient *ec2.EC2, mapiMsName, capiMsName string) {
272292
"PrivateIpAddress",
273293
)
274294

275-
ignorePrivateIpFields := cmpopts.IgnoreFields(ec2.InstancePrivateIpAddress{},
295+
ignorePrivateIPFields := cmpopts.IgnoreFields(ec2.InstancePrivateIpAddress{},
276296
"PrivateDnsName",
277297
"PrivateIpAddress",
278298
)
@@ -284,7 +304,7 @@ func compareInstances(awsClient *ec2.EC2, mapiMsName, capiMsName string) {
284304
ignoreInstanceFields,
285305
ignoreBlockDeviceFields,
286306
ignoreNicFields,
287-
ignorePrivateIpFields,
307+
ignorePrivateIPFields,
288308
ignoreTags,
289309
}
290310

e2e/azure_test.go renamed to e2e/azure.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Red Hat, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package e2e
216

317
import (
@@ -27,12 +41,13 @@ const (
2741
capzManagerBootstrapCredentials = "capz-manager-bootstrap-credentials"
2842
)
2943

30-
var _ = Describe("Cluster API Azure MachineSet", Ordered, func() {
44+
var _ = Describe("Cluster API Azure MachineSet", Ordered, Label("Conformance"), Label("Serial"), func() {
3145
var azureMachineTemplate *azurev1.AzureMachineTemplate
3246
var machineSet *clusterv1.MachineSet
3347
var mapiMachineSpec *mapiv1.AzureMachineProviderSpec
3448

3549
BeforeAll(func() {
50+
InitCommonVariables()
3651
if platform != configv1.AzurePlatformType {
3752
Skip("Skipping Azure E2E tests")
3853
}
@@ -45,15 +60,15 @@ var _ = Describe("Cluster API Azure MachineSet", Ordered, func() {
4560
// explicitly skip it here for other platforms.
4661
Skip("Skipping Azure E2E tests")
4762
}
48-
framework.DeleteMachineSets(cl, machineSet)
49-
framework.WaitForMachineSetsDeleted(cl, machineSet)
63+
framework.DeleteMachineSets(cl, ctx, machineSet)
64+
framework.WaitForMachineSetsDeleted(cl, ctx, machineSet)
5065
framework.DeleteObjects(cl, azureMachineTemplate)
5166
})
5267

5368
It("should be able to run a machine", func() {
5469
azureMachineTemplate = createAzureMachineTemplate(cl, mapiMachineSpec)
5570

56-
machineSet = framework.CreateMachineSet(cl, framework.NewMachineSetParams(
71+
machineSet = framework.CreateMachineSet(cl, ctx, framework.NewMachineSetParams(
5772
"azure-machineset",
5873
clusterName,
5974
"",
@@ -66,7 +81,7 @@ var _ = Describe("Cluster API Azure MachineSet", Ordered, func() {
6681
"worker-user-data",
6782
))
6883

69-
framework.WaitForMachineSet(cl, machineSet.Name, machineSet.Namespace)
84+
framework.WaitForMachineSet(cl, ctx, machineSet.Name, machineSet.Namespace)
7085
})
7186

7287
})
@@ -97,15 +112,16 @@ func createAzureMachineTemplate(cl client.Client, mapiProviderSpec *mapiv1.Azure
97112
Expect(mapiProviderSpec.OSDisk.OSType).ToNot(BeEmpty())
98113
Expect(mapiProviderSpec.VMSize).ToNot(BeEmpty())
99114

100-
azure_credentials_secret := corev1.Secret{}
101-
azure_credentials_secret_key := types.NamespacedName{Name: "capz-manager-bootstrap-credentials", Namespace: "openshift-cluster-api"}
102-
err := cl.Get(context.Background(), azure_credentials_secret_key, &azure_credentials_secret)
115+
azureCredentialsSecret := corev1.Secret{}
116+
azureCredentialsSecretKey := types.NamespacedName{Name: "capz-manager-bootstrap-credentials", Namespace: "openshift-cluster-api"}
117+
err := cl.Get(context.Background(), azureCredentialsSecretKey, &azureCredentialsSecret)
103118
Expect(err).To(BeNil(), "capz-manager-bootstrap-credentials secret should exist")
104-
subscriptionID := azure_credentials_secret.Data["azure_subscription_id"]
119+
120+
subscriptionID := azureCredentialsSecret.Data["azure_subscription_id"]
105121
azureImageID := fmt.Sprintf("/subscriptions/%s%s", subscriptionID, mapiProviderSpec.Image.ResourceID)
106122

107123
var (
108-
identity azurev1.VMIdentity = azurev1.VMIdentityNone
124+
identity = azurev1.VMIdentityNone
109125
userAssignedIdentities []azurev1.UserAssignedIdentity
110126
)
111127

@@ -114,6 +130,7 @@ func createAzureMachineTemplate(cl client.Client, mapiProviderSpec *mapiv1.Azure
114130
if !strings.HasPrefix(mi, "/subscriptions/") {
115131
providerID = fmt.Sprintf("azure:///subscriptions/%s/resourcegroups/%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities/%s", subscriptionID, mapiProviderSpec.ResourceGroup, mi)
116132
}
133+
117134
userAssignedIdentities = []azurev1.UserAssignedIdentity{{ProviderID: providerID}}
118135
identity = azurev1.VMIdentityUserAssigned
119136
}

0 commit comments

Comments
 (0)