@@ -18,36 +18,33 @@ import (
1818 "context"
1919 "fmt"
2020
21- "k8s.io/apimachinery/pkg/api/errors "
21+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1 "
2222 "sigs.k8s.io/controller-runtime/pkg/client"
2323
2424 networkingv1beta1 "github.com/liqotech/liqo/apis/networking/v1beta1"
25+ "github.com/liqotech/liqo/pkg/consts"
26+ "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/utils"
2527)
2628
2729// getInternalFabric retrieves the InternalFabric resource associated with the given GatewayServer.
2830// WARNING: this function contains 2 calls to the Kubernetes API using 2 different names.
2931// This is intended to avoid breaking changes, since the InternalFabric name has changed from GatewayServer name to the GatewayServer cluster ID.
3032func getInternalFabric (ctx context.Context , cl client.Client , gatewayName , remoteID , ns string ) (* networkingv1beta1.InternalFabric , error ) {
33+ name , err := utils .ForgeInternalFabricName (ctx , cl , & metav1.ObjectMeta {
34+ Name : gatewayName ,
35+ Labels : map [string ]string {
36+ consts .RemoteClusterID : remoteID ,
37+ },
38+ })
39+
3140 internalFabric := & networkingv1beta1.InternalFabric {}
32- err : = cl .Get (ctx , client.ObjectKey {
33- Name : remoteID ,
41+ err = cl .Get (ctx , client.ObjectKey {
42+ Name : name ,
3443 Namespace : ns ,
3544 }, internalFabric )
3645 if client .IgnoreNotFound (err ) != nil {
3746 return nil , fmt .Errorf ("unable to get the internal fabric %q: %w" , remoteID , err )
3847 }
3948
40- err = cl .Get (ctx , client.ObjectKey {
41- Name : gatewayName ,
42- Namespace : ns ,
43- }, internalFabric )
44-
45- switch {
46- case errors .IsNotFound (err ):
47- return nil , fmt .Errorf ("could not find internal fabric with names %q and %q: %w" , gatewayName , remoteID , err )
48- case err != nil :
49- return nil , fmt .Errorf ("unable to get the internal fabric %q: %w" , gatewayName , err )
50- }
51-
5249 return internalFabric , nil
5350}
0 commit comments