From b991f4a87f9fc394d52790f3b2fae9a81d3449b1 Mon Sep 17 00:00:00 2001 From: Andreas Burger Date: Thu, 17 Oct 2024 11:02:02 +0200 Subject: [PATCH] check whether a network was found (#879) --- .../infrastructure/infraflow/reconcile.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/controller/infrastructure/infraflow/reconcile.go b/pkg/controller/infrastructure/infraflow/reconcile.go index fc1859e19..bfeb65295 100644 --- a/pkg/controller/infrastructure/infraflow/reconcile.go +++ b/pkg/controller/infrastructure/infraflow/reconcile.go @@ -10,6 +10,8 @@ import ( "fmt" "time" + gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1" + gardenv1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper" "github.com/gardener/gardener/pkg/utils/flow" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" @@ -199,13 +201,20 @@ func (fctx *FlowContext) ensureNetwork(ctx context.Context) error { } func (fctx *FlowContext) ensureConfiguredNetwork(_ context.Context) error { - network, err := fctx.access.GetNetworkByID(*fctx.config.Networks.ID) + networkId := *fctx.config.Networks.ID + network, err := fctx.access.GetNetworkByID(networkId) if err != nil { fctx.state.Set(IdentifierNetwork, "") fctx.state.Set(NameNetwork, "") return err } - fctx.state.Set(IdentifierNetwork, *fctx.config.Networks.ID) + if network == nil { + return gardenv1beta1helper.NewErrorWithCodes( + fmt.Errorf("network with ID '%s' was not found", networkId), + gardencorev1beta1.ErrorInfraDependencies, + ) + } + fctx.state.Set(IdentifierNetwork, networkId) fctx.state.Set(NameNetwork, network.Name) return nil }