@@ -20,7 +20,6 @@ import (
2020 metalmodels "github.com/metal-stack/metal-go/api/models"
2121
2222 corev1 "k8s.io/api/core/v1"
23- apierrors "k8s.io/apimachinery/pkg/api/errors"
2423 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2524 "k8s.io/apimachinery/pkg/runtime"
2625 "k8s.io/utils/ptr"
@@ -285,6 +284,33 @@ func (e2e *E2EContext) NewE2ECluster(cfg ClusterConfig) *E2ECluster {
285284 }
286285}
287286
287+ func (e2e * E2ECluster ) Variables () map [string ]string {
288+ vars := make (map [string ]string )
289+
290+ for k := range e2e .E2EContext .E2EConfig .Variables {
291+ vars [k ] = e2e .E2EContext .envOrVar (k )
292+ }
293+
294+ vars ["METAL_API_URL" ] = e2e .E2EContext .envOrVar ("METAL_API_URL" )
295+ vars ["METAL_API_HMAC" ] = e2e .E2EContext .envOrVar ("METAL_API_HMAC" )
296+ vars ["METAL_API_HMAC_AUTH_TYPE" ] = e2e .E2EContext .envOrVar ("METAL_API_HMAC_AUTH_TYPE" )
297+
298+ vars ["NAMESPACE" ] = e2e .NamespaceName
299+ vars ["METAL_PROJECT_ID" ] = e2e .E2EContext .Environment .project
300+ vars ["METAL_PARTITION" ] = e2e .E2EContext .Environment .partition
301+ vars ["METAL_NODE_NETWORK_ID" ] = * e2e .Refs .NodeNetwork .ID
302+ vars ["FIREWALL_MACHINE_SIZE" ] = e2e .FirewallSize
303+ vars ["FIREWALL_MACHINE_IMAGE" ] = e2e .FirewallImage
304+ vars ["FIREWALL_MACHINE_NETWORKS" ] = "[" + strings .Join (e2e .FirewallNetworks , "," ) + "]"
305+ vars ["CONTROL_PLANE_IP" ] = e2e .ControlPlaneIP
306+ vars ["CONTROL_PLANE_MACHINE_SIZE" ] = e2e .ControlPlaneMachineSize
307+ vars ["CONTROL_PLANE_MACHINE_IMAGE" ] = e2e .ControlPlaneMachineImage
308+ vars ["WORKER_MACHINE_SIZE" ] = e2e .WorkerMachineSize
309+ vars ["WORKER_MACHINE_IMAGE" ] = e2e .WorkerMachineImage
310+
311+ return vars
312+ }
313+
288314// common
289315
290316func (e2e * E2ECluster ) SetupNamespace (ctx context.Context ) * corev1.Namespace {
@@ -322,7 +348,6 @@ func (e2e *E2ECluster) SetupMetalStackPreconditions(ctx context.Context) {
322348
323349func (e2e * E2ECluster ) Teardown (ctx context.Context ) {
324350 e2e .teardownCluster (ctx )
325- e2e .teardownClusterResourceSets (ctx )
326351 e2e .teardownControlPlaneIP (ctx )
327352 e2e .teardownFirewall (ctx )
328353 e2e .teardownNodeNetwork (ctx )
@@ -422,10 +447,15 @@ func (e2e *E2ECluster) setupFirewall(ctx context.Context) {
422447 },
423448 }
424449
425- fw , err := e2e .E2EContext .Environment .Metal .Firewall ().AllocateFirewall (metalfw .NewAllocateFirewallParamsWithContext (ctx ).WithBody (fcr ), nil )
426- Expect (err ).ToNot (HaveOccurred (), "failed to allocate firewall" )
450+ Eventually (func () error {
451+ fw , err := e2e .E2EContext .Environment .Metal .Firewall ().AllocateFirewall (metalfw .NewAllocateFirewallParamsWithContext (ctx ).WithBody (fcr ), nil )
452+ if err != nil {
453+ return err
454+ }
427455
428- e2e .Refs .Firewall = fw .Payload
456+ e2e .Refs .Firewall = fw .Payload
457+ return nil
458+ }, e2e .E2EContext .E2EConfig .GetIntervals ("metal-stack" , "wait-firewall-allocate" )... ).ShouldNot (HaveOccurred (), "firewall not available" )
429459}
430460
431461func (e2e * E2ECluster ) teardownFirewall (ctx context.Context ) {
@@ -440,6 +470,10 @@ func (e2e *E2ECluster) teardownFirewall(ctx context.Context) {
440470}
441471
442472func (e2e * E2ECluster ) setupControlPlaneIP (ctx context.Context ) {
473+ if e2e .ControlPlaneIP != "" {
474+ return
475+ }
476+
443477 By ("Setup Control Plane IP" )
444478
445479 ipr := & metalmodels.V1IPAllocateRequest {
@@ -451,12 +485,15 @@ func (e2e *E2ECluster) setupControlPlaneIP(ctx context.Context) {
451485 fmt .Sprintf ("%s=%s" , "e2e-test" , e2e .SpecName ),
452486 },
453487 Networkid : ptr .To (e2e .E2EContext .Environment .publicNetwork ),
488+ Type : ptr .To (metalmodels .V1IPAllocateRequestTypeStatic ),
454489 }
455490
456491 ip , err := e2e .E2EContext .Environment .Metal .IP ().AllocateIP (metalip .NewAllocateIPParamsWithContext (ctx ).WithBody (ipr ), nil )
457492 Expect (err ).ToNot (HaveOccurred (), "failed to allocate control plane IP" )
493+ Expect (ip .Payload .Ipaddress ).NotTo (BeNil (), "allocated control plane IP has no IP address" )
458494
459495 e2e .Refs .ControlPlaneIP = ip .Payload
496+ e2e .ControlPlaneIP = * e2e .Refs .ControlPlaneIP .Ipaddress
460497}
461498
462499func (e2e * E2ECluster ) teardownControlPlaneIP (ctx context.Context ) {
@@ -488,22 +525,7 @@ func (e2e *E2ECluster) GenerateAndApplyClusterTemplate(ctx context.Context) {
488525 InfrastructureProvider : "capms:v0.6.1" ,
489526 LogFolder : path .Join (e2e .E2EContext .Environment .artifactsPath , "clusters" , e2e .ClusterName ),
490527 // KubeconfigPath: "",
491- ClusterctlVariables : map [string ]string {
492- // "METAL_API_URL": "",
493- // "METAL_API_HMAC": "",
494- "METAL_PROJECT_ID" : e2e .E2EContext .Environment .project ,
495- // "POD_CIDR": "",
496- "METAL_PARTITION" : e2e .E2EContext .Environment .partition ,
497- "METAL_NODE_NETWORK_ID" : * e2e .Refs .NodeNetwork .ID ,
498- "FIREWALL_MACHINE_SIZE" : e2e .FirewallSize ,
499- "FIREWALL_MACHINE_IMAGE" : e2e .FirewallImage ,
500- "FIREWALL_MACHINE_NETWORKS" : "[" + strings .Join (e2e .FirewallNetworks , "," ) + "]" ,
501- "CONTROL_PLANE_IP" : e2e .ControlPlaneIP ,
502- "CONTROL_PLANE_MACHINE_SIZE" : e2e .ControlPlaneMachineSize ,
503- "CONTROL_PLANE_MACHINE_IMAGE" : e2e .ControlPlaneMachineImage ,
504- "WORKER_MACHINE_SIZE" : e2e .WorkerMachineSize ,
505- "WORKER_MACHINE_IMAGE" : e2e .WorkerMachineImage ,
506- },
528+ ClusterctlVariables : e2e .Variables (),
507529 })
508530
509531 By ("Apply cluster template" )
@@ -535,20 +557,6 @@ func (e2e *E2ECluster) teardownCluster(ctx context.Context) {
535557 }, e2e .E2EContext .E2EConfig .GetIntervals ("default" , "wait-delete-cluster" )... )
536558}
537559
538- func (e2e * E2ECluster ) teardownClusterResourceSets (ctx context.Context ) {
539- sets := framework .GetClusterResourceSets (ctx , framework.GetClusterResourceSetsInput {
540- Lister : e2e .E2EContext .Environment .Bootstrap .GetClient (),
541- Namespace : e2e .NamespaceName ,
542- })
543-
544- for _ , s := range sets {
545- err := e2e .E2EContext .Environment .Bootstrap .GetClient ().Delete (ctx , s )
546- if err != nil && ! apierrors .IsNotFound (err ) {
547- Expect (err ).NotTo (HaveOccurred (), "failed to delete cluster resourceset" )
548- }
549- }
550- }
551-
552560// deleteClusterAndWait deletes a cluster object and waits for it to be gone.
553561// TODO: remove once cluster expectation has been fixed in framework
554562func deleteClusterAndWait (ctx context.Context , input framework.DeleteClusterAndWaitInput , intervals ... any ) {
0 commit comments