From 2fc274947d0f03d6ac1138f3d6d02ef2d4a038fa Mon Sep 17 00:00:00 2001 From: Robert Hoppe Date: Sun, 25 Feb 2024 20:19:18 +0100 Subject: [PATCH] Introduce improved WaitHandler for the Networking (#210) Co-authored-by: Robert Hoppe --- pkg/services/iaas-api/v1alpha/wait.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/services/iaas-api/v1alpha/wait.go b/pkg/services/iaas-api/v1alpha/wait.go index f3f2e3f..68e5f6d 100644 --- a/pkg/services/iaas-api/v1alpha/wait.go +++ b/pkg/services/iaas-api/v1alpha/wait.go @@ -11,16 +11,23 @@ import ( ) // WaitHandler wait for the network to be created and return it. -func (*V1CreateNetworkResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID openapiTypes.UUID) *wait.Handler { +func (*V1CreateNetworkResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID openapiTypes.UUID, name string) *wait.Handler { return wait.New(func() (res interface{}, done bool, err error) { resp, err := c.V1ListNetworksInProject(ctx, projectID) if err != nil { return nil, false, err } - if resp.JSON200 != nil { - // the network is created successfully - return nil, true, nil + if resp.JSON200 != nil && len(resp.JSON200.Items) > 0 { + for _, n := range resp.JSON200.Items { + if n.Name == name { + // the network is created successfully + return n, true, nil + } + } + + // the network that is created was not found + return nil, false, nil } if resp.JSON400 != nil { @@ -37,6 +44,7 @@ func (*V1CreateNetworkResponse) WaitHandler(ctx context.Context, c *ClientWithRe // if the server returns 403 then we can't retry the same request because the result will be the same return nil, false, errors.New(resp.JSON403.Msg) } + // in all other cases we will retry the request until the network is not created or an error occurred. return nil, false, nil })