Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting peering allocation phase #112

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
3 changes: 2 additions & 1 deletion deployments/node/samples/allocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ spec:
# Retrieve information from the reservation and the contract bou d to it
contract:
name: contract-fluidos.eu-k8slice-7413576d05fe8e93c719e13eab156c5c-ae7e
namespace: fluidos
namespace: fluidos

11 changes: 6 additions & 5 deletions deployments/node/samples/reservation.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: reservation.fluidos.eu/v1alpha1
kind: Reservation
metadata:
name: reservation-solver-sample-2
name: reservation-solver-sample
namespace: fluidos
spec:
solverID: solver-sample-2
Expand All @@ -17,7 +17,7 @@ spec:
pods: "110"
# Retrieve from PeeringCandidate chosen to reserve
peeringCandidate:
name: peeringcandidate-fluidos.eu-k8slice-7413576d05fe8e93c719e13eab156c5c
name: peeringcandidate-fluidos.eu-k8slice-0e682ec3133811bb0d52b6373c339f81
namespace: fluidos
# Set it to reserve
reserve: true
Expand All @@ -26,10 +26,11 @@ spec:
# Retrieve from PeeringCandidate Flavor Owner field
seller:
domain: fluidos.eu
ip: 172.19.0.2:30001
nodeID: ejbbzmacn0
ip: 172.19.0.4:30001
nodeID: 4ahrqttvng
# Retrieve from configmap
buyer:
domain: fluidos.eu
ip: 172.19.0.5:30000
nodeID: e9d2mzsbcf
nodeID: rd5ks7x9yz

4 changes: 2 additions & 2 deletions deployments/node/samples/solver.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: nodecore.fluidos.eu/v1alpha1
kind: Solver
metadata:
name: solver-sample-3
name: solver-sample
namespace: fluidos
spec:
# This is the Selector used to find a Flavor (FLUIDOS node) that matches the requirements
Expand Down Expand Up @@ -37,7 +37,7 @@ spec:
data:
value: 110
# The intentID is the ID of the intent that the solver should satisfy
intentID: "intent-sample-3"
intentID: "intent-sample"
# This flag is used to indicate that the solver should find a candidate (FLUIDOS node)
findCandidate: true
# This flag is used to indicate that the solver should reserve and buy the resources from the candidate (FLUIDOS node)
Expand Down
55 changes: 36 additions & 19 deletions pkg/rear-manager/allocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,46 @@ func (r *AllocationReconciler) handleK8SliceConsumerAllocation(ctx context.Conte

// Get the Liqo credentials for the peering target cluster, that in this scenario is the provider
credentials := contract.Spec.PeeringTargetCredentials

// Establish peering
klog.InfofDepth(1, "Allocation %s is peering with cluster %s", req.NamespacedName, credentials.ClusterName)
_, err := virtualfabricmanager.PeerWithCluster(ctx, r.Client, credentials.ClusterID,
credentials.ClusterName, credentials.Endpoint, credentials.Token)
// Check if a Liqo peering has been already established
_, err := fcutils.GetForeignClusterByID(ctx, r.Client, credentials.ClusterID)
if err != nil {
klog.Errorf("Error when peering with cluster %s: %s", credentials.ClusterName, err)
allocation.SetStatus(nodecorev1alpha1.Error, "Error when peering with cluster "+credentials.ClusterName)
if err := r.updateAllocationStatus(ctx, allocation); err != nil {
klog.Errorf("Error when updating Solver %s status: %s", req.NamespacedName, err)
return ctrl.Result{}, err
if apierrors.IsNotFound(err) {
// Establish peering
klog.InfofDepth(1, "Allocation %s is peering with cluster %s", req.NamespacedName, credentials.ClusterName)
_, err := virtualfabricmanager.PeerWithCluster(ctx, r.Client, credentials.ClusterID,
credentials.ClusterName, credentials.Endpoint, credentials.Token)
if err != nil {
klog.Errorf("Error when peering with cluster %s: %s", credentials.ClusterName, err)
allocation.SetStatus(nodecorev1alpha1.Error, "Error when peering with cluster "+credentials.ClusterName)
if err := r.updateAllocationStatus(ctx, allocation); err != nil {
klog.Errorf("Error when updating Solver %s status: %s", req.NamespacedName, err)
return ctrl.Result{}, err
}
return ctrl.Result{}, err
}
// Peering established
klog.Infof("Allocation %s has started the peering with cluster %s", req.NamespacedName.Name, credentials.ClusterName)

// Change the status of the Allocation to Active
allocation.SetStatus(nodecorev1alpha1.Active, "Allocation is now Active")
if err := r.updateAllocationStatus(ctx, allocation); err != nil {
klog.Errorf("Error when updating Solver %s status: %s", req.NamespacedName, err)
return ctrl.Result{}, err
}
} else {
klog.Errorf("Error when getting ForeignCluster %s: %v", credentials.ClusterID, err)
allocation.SetStatus(nodecorev1alpha1.Error, "Error when getting ForeignCluster")
if err := r.updateAllocationStatus(ctx, allocation); err != nil {
klog.Errorf("Error when updating Allocation %s status: %v", req.NamespacedName, err)
return ctrl.Result{}, err
}
}
return ctrl.Result{}, err
} else {
// Peering already established
klog.Infof("Allocation %s has already peered with cluster %s", req.NamespacedName.Name, credentials.ClusterName)
return ctrl.Result{}, nil
}
// Peering established
klog.Infof("Allocation %s has started the peering with cluster %s", req.NamespacedName.Name, credentials.ClusterName)

// Change the status of the Allocation to Active
allocation.SetStatus(nodecorev1alpha1.Active, "Allocation is now Active")
if err := r.updateAllocationStatus(ctx, allocation); err != nil {
klog.Errorf("Error when updating Solver %s status: %s", req.NamespacedName, err)
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
case nodecorev1alpha1.Released:
// The Allocation is released,
Expand Down
Loading