Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions pkg/gateway/fabric/geneve/internalfabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,33 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/utils"
)

// getInternalFabric retrieves the InternalFabric resource associated with the given GatewayServer.
// WARNING: this function contains 2 calls to the Kubernetes API using 2 different names.
// This is intended to avoid breaking changes, since the InternalFabric name has changed from GatewayServer name to the GatewayServer cluster ID.
func getInternalFabric(ctx context.Context, cl client.Client, gatewayName, remoteID, ns string) (*networkingv1beta1.InternalFabric, error) {
name, err := utils.ForgeInternalFabricName(ctx, cl, &metav1.ObjectMeta{
Name: gatewayName,
Labels: map[string]string{
consts.RemoteClusterID: remoteID,
},
})

internalFabric := &networkingv1beta1.InternalFabric{}
err := cl.Get(ctx, client.ObjectKey{
Name: remoteID,
err = cl.Get(ctx, client.ObjectKey{
Name: name,
Namespace: ns,
}, internalFabric)
if client.IgnoreNotFound(err) != nil {
return nil, fmt.Errorf("unable to get the internal fabric %q: %w", remoteID, err)
}

err = cl.Get(ctx, client.ObjectKey{
Name: gatewayName,
Namespace: ns,
}, internalFabric)

switch {
case errors.IsNotFound(err):
return nil, fmt.Errorf("could not find internal fabric with names %q and %q: %w", gatewayName, remoteID, err)
case err != nil:
return nil, fmt.Errorf("unable to get the internal fabric %q: %w", gatewayName, err)
}

return internalFabric, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ func ForgeInternalFabricName(ctx context.Context, cl client.Client, meta *metav1
case err != nil:
return "", fmt.Errorf("unable to get the internal fabric %q: %w", meta.Name, err)
}
return internalFabric.Name, nil
return meta.Name, nil
}
Loading