@@ -3,64 +3,55 @@ package e2e
3
3
import (
4
4
. "github.com/onsi/ginkgo/v2"
5
5
. "github.com/onsi/gomega"
6
+ "github.com/onsi/gomega/format"
6
7
configv1 "github.com/openshift/api/config/v1"
7
8
mapiv1alpha1 "github.com/openshift/api/machine/v1alpha1"
8
9
mapiv1beta1 "github.com/openshift/api/machine/v1beta1"
9
10
"github.com/openshift/cluster-capi-operator/e2e/framework"
10
11
corev1 "k8s.io/api/core/v1"
11
- apierrors "k8s.io/apimachinery/pkg/api/errors"
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
- clusterv1 "sigs. k8s.io/cluster-api/api/v1beta1 "
13
+ " k8s.io/utils/ptr "
14
14
"sigs.k8s.io/controller-runtime/pkg/client"
15
15
yaml "sigs.k8s.io/yaml"
16
16
17
17
"github.com/openshift/cluster-api-provider-openstack/openshift/pkg/infraclustercontroller"
18
18
19
- infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7 "
19
+ infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1 "
20
20
)
21
21
22
22
const (
23
23
openStackMachineTemplateName = "openstack-machine-template"
24
24
)
25
25
26
26
var _ = Describe ("Cluster API OpenStack MachineSet" , Ordered , func () {
27
- var openStackMachineTemplate * infrav1.OpenStackMachineTemplate
28
- var machineSet * clusterv1.MachineSet
29
27
var mapiMachineSpec * mapiv1alpha1.OpenstackProviderSpec
30
28
31
29
BeforeAll (func () {
32
30
if platform != configv1 .OpenStackPlatformType {
33
31
Skip ("Skipping OpenStack E2E tests" )
34
32
}
35
- framework .CreateCoreCluster (cl , clusterName , "OpenStackCluster" )
36
33
mapiMachineSpec = getOpenStackMAPIProviderSpec (cl )
37
34
})
38
35
39
- AfterEach (func () {
40
- if platform != configv1 .OpenStackPlatformType {
41
- // Because AfterEach always runs, even when tests are skipped, we have to
42
- // explicitly skip it here for other platforms.
43
- Skip ("Skipping OpenStack E2E tests" )
44
- }
45
- framework .DeleteMachineSets (cl , machineSet )
46
- framework .WaitForMachineSetsDeleted (cl , machineSet )
47
- framework .DeleteObjects (cl , openStackMachineTemplate )
48
- })
49
-
50
- It ("should be able to run a machine" , func () {
51
- openStackMachineTemplate = createOpenStackMachineTemplate (cl , mapiMachineSpec )
36
+ It ("should be able to run a machine with implicit cluster default network" , func () {
37
+ openStackMachineTemplate := createOpenStackMachineTemplate (cl , mapiMachineSpec )
52
38
53
- machineSet = framework .CreateMachineSet (cl , framework .NewMachineSetParams (
39
+ machineSet : = framework .CreateMachineSet (cl , framework .NewMachineSetParams (
54
40
"openstack-machineset" ,
55
41
clusterName ,
56
42
"" ,
57
43
1 ,
58
44
corev1.ObjectReference {
59
45
Kind : "OpenStackMachineTemplate" ,
60
46
APIVersion : infraAPIVersion ,
61
- Name : openStackMachineTemplateName ,
47
+ Name : openStackMachineTemplate . Name ,
62
48
},
63
49
))
50
+ DeferCleanup (func () {
51
+ By ("Deleting machineset " + machineSet .Name )
52
+ Expect (cl .Delete (ctx , machineSet )).To (Succeed ())
53
+ framework .WaitForMachineSetsDeleted (cl , machineSet )
54
+ })
64
55
65
56
framework .WaitForMachineSet (cl , machineSet .Name )
66
57
})
@@ -104,68 +95,48 @@ func createOpenStackMachineTemplate(cl client.Client, mapiProviderSpec *mapiv1al
104
95
105
96
if mapiProviderSpec .RootVolume != nil {
106
97
rootVolume = & infrav1.RootVolume {
107
- Size : mapiProviderSpec .RootVolume .Size ,
108
- VolumeType : mapiProviderSpec .RootVolume .VolumeType ,
109
- AvailabilityZone : mapiProviderSpec .RootVolume .Zone ,
98
+ SizeGiB : mapiProviderSpec .RootVolume .Size ,
99
+ BlockDeviceVolume : infrav1.BlockDeviceVolume {
100
+ Type : mapiProviderSpec .RootVolume .VolumeType ,
101
+ AvailabilityZone : & infrav1.VolumeAvailabilityZone {
102
+ From : infrav1 .VolumeAZFromName ,
103
+ Name : ptr .To (infrav1 .VolumeAZName (mapiProviderSpec .RootVolume .Zone )),
104
+ },
105
+ },
110
106
}
111
107
} else {
112
108
image = mapiProviderSpec .Image
113
109
}
114
110
115
- // NOTE(stephenfin): We intentionally ignore additional networks for now since we don't care
116
- // about e.g. Manila shares. We can re-evaluate this if necessary.
117
- ports := []infrav1.PortOpts {}
118
- for _ , subnet := range mapiProviderSpec .Networks [0 ].Subnets {
119
- port := infrav1.PortOpts {
120
- FixedIPs : []infrav1.FixedIP {
121
- {
122
- Subnet : & infrav1.SubnetFilter {
123
- // NOTE(stephenfin): Only one of name or ID will be set.
124
- ID : subnet .Filter .ID ,
125
- Name : subnet .Filter .Name ,
126
- Tags : subnet .Filter .Tags ,
127
- },
128
- },
129
- },
130
- }
131
- ports = append (ports , port )
132
- }
133
- port := infrav1.PortOpts {
134
- Network : & infrav1.NetworkFilter {
135
- // The installer still sets NetworkParam.Filter.ID rather than NetworkParam.ID,
136
- // at least as of 4.15.
137
- ID : mapiProviderSpec .Networks [0 ].Filter .ID , //nolint:staticcheck
138
- Name : mapiProviderSpec .Networks [0 ].Filter .Name ,
139
- },
111
+ // NOTE(stephenfin): We intentionally ignore additional security for now.
112
+ var securityGroupParam infrav1.SecurityGroupParam
113
+ securityGroup := mapiProviderSpec .SecurityGroups [0 ]
114
+ if securityGroup .UUID != "" {
115
+ securityGroupParam = infrav1.SecurityGroupParam {ID : & securityGroup .UUID }
116
+ } else {
117
+ securityGroupParam = infrav1.SecurityGroupParam {Filter : & infrav1.SecurityGroupFilter {Name : securityGroup .Name }}
140
118
}
141
- ports = append (ports , port )
142
-
143
- // NOTE(stephenfin): Ditto for security groups
144
- securityGroups := []infrav1.SecurityGroupFilter {
145
- {
146
- Name : mapiProviderSpec .SecurityGroups [0 ].Name ,
147
- ID : mapiProviderSpec .SecurityGroups [0 ].UUID ,
148
- },
119
+ securityGroups := []infrav1.SecurityGroupParam {
120
+ securityGroupParam ,
149
121
}
150
122
123
+ // We intentionally omit ports so the machine will default its network
124
+ // from the OpenStackCluster created by the infracluster controller.
151
125
openStackMachineSpec := infrav1.OpenStackMachineSpec {
152
- CloudName : infraclustercontroller .CloudName ,
153
- Flavor : mapiProviderSpec .Flavor ,
126
+ Flavor : mapiProviderSpec .Flavor ,
154
127
IdentityRef : & infrav1.OpenStackIdentityReference {
155
- Kind : "Secret" ,
156
- Name : infraclustercontroller .CredentialsSecretName ,
128
+ CloudName : infraclustercontroller . CloudName ,
129
+ Name : infraclustercontroller .CredentialsSecretName ,
157
130
},
158
- Image : image ,
159
- Ports : ports ,
131
+ Image : infrav1.ImageParam {Filter : & infrav1.ImageFilter {Name : & image }},
160
132
RootVolume : rootVolume ,
161
133
SecurityGroups : securityGroups ,
162
- Tags : mapiProviderSpec .Tags ,
163
134
}
164
135
165
136
openStackMachineTemplate := & infrav1.OpenStackMachineTemplate {
166
137
ObjectMeta : metav1.ObjectMeta {
167
- Name : openStackMachineTemplateName ,
168
- Namespace : framework .CAPINamespace ,
138
+ GenerateName : openStackMachineTemplateName + "-" ,
139
+ Namespace : framework .CAPINamespace ,
169
140
},
170
141
Spec : infrav1.OpenStackMachineTemplateSpec {
171
142
Template : infrav1.OpenStackMachineTemplateResource {
@@ -174,9 +145,10 @@ func createOpenStackMachineTemplate(cl client.Client, mapiProviderSpec *mapiv1al
174
145
},
175
146
}
176
147
177
- if err := cl .Create (ctx , openStackMachineTemplate ); err != nil && ! apierrors .IsAlreadyExists (err ) {
178
- Expect (err ).ToNot (HaveOccurred ())
179
- }
148
+ Expect (cl .Create (ctx , openStackMachineTemplate )).To (Succeed (), format .Object (openStackMachineTemplate , 1 ))
149
+ DeferCleanup (func () error {
150
+ return cl .Delete (ctx , openStackMachineTemplate )
151
+ })
180
152
181
153
return openStackMachineTemplate
182
154
}
0 commit comments