@@ -23,9 +23,11 @@ import (
23
23
"errors"
24
24
"fmt"
25
25
"path/filepath"
26
+ "reflect"
26
27
"strings"
27
28
"time"
28
29
30
+ "github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
29
31
. "github.com/onsi/ginkgo"
30
32
. "github.com/onsi/gomega"
31
33
appsv1 "k8s.io/api/apps/v1"
@@ -129,6 +131,47 @@ var _ = Describe("e2e tests", func() {
129
131
})
130
132
131
133
Describe ("Workload cluster (without lb)" , func () {
134
+ It ("Should create port(s) with custom options" , func () {
135
+ shared .Byf ("Creating a cluster" )
136
+ clusterName := fmt .Sprintf ("cluster-%s" , namespace .Name )
137
+ configCluster := defaultConfigCluster (clusterName , namespace .Name )
138
+ configCluster .ControlPlaneMachineCount = pointer .Int64Ptr (1 )
139
+ configCluster .WorkerMachineCount = pointer .Int64Ptr (1 )
140
+ configCluster .Flavor = shared .FlavorDefault
141
+ _ = createCluster (ctx , configCluster , specName )
142
+
143
+ shared .Byf ("Creating MachineDeployment with custom port options" )
144
+ md3Name := clusterName + "-md-3"
145
+ customPortOptions := & []infrav1.PortOpts {
146
+ {Description : "primary" },
147
+ }
148
+ framework .CreateMachineDeployment (ctx , framework.CreateMachineDeploymentInput {
149
+ Creator : e2eCtx .Environment .BootstrapClusterProxy .GetClient (),
150
+ MachineDeployment : makeMachineDeployment (namespace .Name , md3Name , clusterName , "" , 1 ),
151
+ BootstrapConfigTemplate : makeJoinBootstrapConfigTemplate (namespace .Name , md3Name ),
152
+ InfraMachineTemplate : makeOpenStackMachineTemplateWithPortOptions (namespace .Name , clusterName , md3Name , customPortOptions ),
153
+ })
154
+
155
+ shared .Byf ("Expecting MachineDeployment to be created successfully" )
156
+ Eventually (func () bool {
157
+ eventList := getEvents (namespace .Name )
158
+ portError := "Failed to create server with custom port options"
159
+ return isErrorEventExists (namespace .Name , md3Name , "FailedCreateServer" , portError , eventList )
160
+ }, e2eCtx .E2EConfig .GetIntervals (specName , "wait-worker-nodes" )... ).Should (BeFalse ())
161
+
162
+ filterNone := ports.ListOpts {}
163
+ plist1 , err := shared .DumpOpenStackPorts (e2eCtx , filterNone )
164
+ Expect (err ).To (BeNil ())
165
+ Expect (plist1 ).NotTo (BeNil ())
166
+
167
+ filterOne := ports.ListOpts {Description : "primary" }
168
+ plist2 , err := shared .DumpOpenStackPorts (e2eCtx , filterOne )
169
+ Expect (err ).To (BeNil ())
170
+ count := len (* plist2 )
171
+ Expect (count ).To (Equal (1 ))
172
+ found := portContainsProperty (* plist2 , "Description" , "primary" )
173
+ Expect (found ).Should (BeTrue ())
174
+ })
132
175
It ("It should be creatable and deletable" , func () {
133
176
shared .Byf ("Creating a cluster" )
134
177
clusterName := fmt .Sprintf ("cluster-%s" , namespace .Name )
@@ -294,6 +337,29 @@ func makeOpenStackMachineTemplate(namespace, clusterName, name string, subnetID
294
337
}
295
338
}
296
339
340
+ func makeOpenStackMachineTemplateWithPortOptions (namespace , clusterName , name string , portOpts * []infrav1.PortOpts ) * infrav1.OpenStackMachineTemplate {
341
+ return & infrav1.OpenStackMachineTemplate {
342
+ ObjectMeta : metav1.ObjectMeta {
343
+ Name : name ,
344
+ Namespace : namespace ,
345
+ },
346
+ Spec : infrav1.OpenStackMachineTemplateSpec {
347
+ Template : infrav1.OpenStackMachineTemplateResource {
348
+ Spec : infrav1.OpenStackMachineSpec {
349
+ Flavor : e2eCtx .E2EConfig .GetVariable (shared .OpenStackNodeMachineFlavor ),
350
+ Image : e2eCtx .E2EConfig .GetVariable (shared .OpenStackImageName ),
351
+ SSHKeyName : shared .DefaultSSHKeyPairName ,
352
+ CloudName : e2eCtx .E2EConfig .GetVariable (shared .OpenStackCloud ),
353
+ CloudsSecret : & corev1.SecretReference {
354
+ Name : fmt .Sprintf ("%s-cloud-config" , clusterName ),
355
+ },
356
+ Ports : * portOpts ,
357
+ },
358
+ },
359
+ },
360
+ }
361
+ }
362
+
297
363
// makeJoinBootstrapConfigTemplate returns a KubeadmConfigTemplate which can be used
298
364
// to test different error cases. As we're missing e.g. the cloud provider conf it cannot
299
365
// be used to successfully add nodes to a cluster.
@@ -417,3 +483,19 @@ func isCloudProviderInitialized(taints []corev1.Taint) bool {
417
483
}
418
484
return true
419
485
}
486
+
487
+ // Verifies that a Port contains a valid property with a correct value.
488
+ func portContainsProperty (plist interface {}, property string , value interface {}) bool {
489
+ ports := reflect .ValueOf (plist )
490
+ portsCount := ports .Len ()
491
+ for i := 0 ; i < portsCount ; i ++ {
492
+ currentPort := ports .Index (i )
493
+ searchProperty := currentPort .FieldByName (property )
494
+ correctValue := searchProperty .Interface () == value
495
+ if correctValue {
496
+ return true
497
+ }
498
+ }
499
+ // Non-existing property or incorrect value
500
+ return false
501
+ }
0 commit comments