Skip to content

Commit

Permalink
cleaning up dependencies among FLUIDOS Node CRDs (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
fracappa authored Sep 6, 2024
1 parent 8abfdbf commit 8d17d9c
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 209 deletions.
8 changes: 3 additions & 5 deletions apis/advertisement/v1alpha1/peeringcandidate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (

// PeeringCandidateSpec defines the desired state of PeeringCandidate.
type PeeringCandidateSpec struct {
SolverID string `json:"solverID"`

Flavor nodecorev1alpha1.Flavor `json:"flavor"`

Available bool `json:"available"`
InterestedSolverIDs []string `json:"interestedSolverIDs"`
Flavor nodecorev1alpha1.Flavor `json:"flavor"`
Available bool `json:"available"`
}

// PeeringCandidateStatus defines the observed state of PeeringCandidate.
Expand Down
5 changes: 5 additions & 0 deletions apis/advertisement/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions apis/nodecore/v1alpha1/allocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ const (

// AllocationSpec defines the desired state of Allocation.
type AllocationSpec struct {
// This is the ID of the intent for which the allocation was created.
// It is used by the Node Orchestrator to identify the correct allocation for a given intent
IntentID string `json:"intentID"`

// This flag indicates if the allocation is a forwarding allocation
// if true it represents only a placeholder to undertand that the cluster is just a proxy to another cluster
Forwarding bool `json:"forwarding,omitempty"`
Expand Down
11 changes: 0 additions & 11 deletions apis/nodecore/v1alpha1/solver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ type SolverStatus struct {
// SolverPhase describes the status of the Solver generated by the Node Orchestrator.
// It is useful to understand if the solver is still running or if it has finished or failed.
SolverPhase PhaseStatus `json:"solverPhase,omitempty"`

// Allocation contains the allocation that the solver has eventually created for the intent.
// It can correspond to a virtual node
// The Node Orchestrator will use this allocation to fulfill the intent.
Allocation GenericRef `json:"allocation,omitempty"`

// Contract contains the Contract that the Contract Manager has eventually created with the candidate.
Contract GenericRef `json:"contract,omitempty"`

// Credentials contains the LiqoCredentials found in the Contract.
Credentials LiqoCredentials `json:"credentials,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
3 changes: 0 additions & 3 deletions apis/nodecore/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,14 @@ spec:
- lastUpdateTime
type: object
type: object
solverID:
type: string
interestedSolverIDs:
items:
type: string
type: array
required:
- available
- flavor
- solverID
- interestedSolverIDs
type: object
status:
description: PeeringCandidateStatus defines the observed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ spec:
- lastUpdateTime
type: object
type: object
solverID:
type: string
interestedSolverIDs:
items:
type: string
type: array
required:
- available
- flavor
- solverID
- interestedSolverIDs
type: object
status:
description: PeeringCandidateStatus defines the observed state of PeeringCandidate.
Expand Down
7 changes: 0 additions & 7 deletions deployments/node/crds/nodecore.fluidos.eu_allocations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ spec:
This flag indicates if the allocation is a forwarding allocation
if true it represents only a placeholder to undertand that the cluster is just a proxy to another cluster
type: boolean
intentID:
description: |-
This is the ID of the intent for which the allocation was created.
It is used by the Node Orchestrator to identify the correct allocation for a given intent
type: string
required:
- intentID
type: object
status:
description: AllocationStatus defines the observed state of Allocation.
Expand Down
46 changes: 0 additions & 46 deletions deployments/node/crds/nodecore.fluidos.eu_solvers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,57 +115,11 @@ spec:
status:
description: SolverStatus defines the observed state of Solver.
properties:
allocation:
description: |-
Allocation contains the allocation that the solver has eventually created for the intent.
It can correspond to a virtual node
The Node Orchestrator will use this allocation to fulfill the intent.
properties:
name:
description: The name of the resource to be referenced.
type: string
namespace:
description: |-
The namespace containing the resource to be referenced. It should be left
empty in case of cluster-wide resources.
type: string
type: object
consumePhase:
description: |-
ConsumePhase describes the status of the Consume phase where the VFM (Liqo) is enstablishing
a peering with the candidate node.
type: string
contract:
description: Contract contains the Contract that the Contract Manager
has eventually created with the candidate.
properties:
name:
description: The name of the resource to be referenced.
type: string
namespace:
description: |-
The namespace containing the resource to be referenced. It should be left
empty in case of cluster-wide resources.
type: string
type: object
credentials:
description: Credentials contains the LiqoCredentials found in the
Contract.
properties:
clusterID:
type: string
clusterName:
type: string
endpoint:
type: string
token:
type: string
required:
- clusterID
- clusterName
- endpoint
- token
type: object
discoveryPhase:
description: |-
DiscoveryPhase describes the status of the Discovery where the Discovery Manager
Expand Down
6 changes: 3 additions & 3 deletions deployments/node/samples/allocation.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: nodecore.fluidos.eu/v1alpha1
kind: Allocation
metadata:
name: allocation-sample
name: allocation-sample-whatever
namespace: fluidos
spec:
# Get it from the solver
intentID: intent-sample
# intentID: intent-sample
# Retrieve information from the reservation and the contract bou d to it
contract:
name: contract-fluidos.eu-k8slice-07eadba8bf32d8d6f142b6726592956a-43a4
name: contract-fluidos.eu-k8slice-7413576d05fe8e93c719e13eab156c5c-ae7e
namespace: fluidos
14 changes: 7 additions & 7 deletions deployments/node/samples/reservation.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: reservation.fluidos.eu/v1alpha1
kind: Reservation
metadata:
name: reservation-sample
name: reservation-solver-sample-2
namespace: fluidos
spec:
solverID: solver-sample-1
solverID: solver-sample-2
# Set it as you want, following needs and requests in the solver.
# Optional
configuration:
Expand All @@ -17,7 +17,7 @@ spec:
pods: "110"
# Retrieve from PeeringCandidate chosen to reserve
peeringCandidate:
name: peeringcandidate-fluidos.eu-k8slice-24f77877ba11ce29a25f95ec33a244c5
name: peeringcandidate-fluidos.eu-k8slice-7413576d05fe8e93c719e13eab156c5c
namespace: fluidos
# Set it to reserve
reserve: true
Expand All @@ -26,10 +26,10 @@ spec:
# Retrieve from PeeringCandidate Flavor Owner field
seller:
domain: fluidos.eu
ip: 172.18.0.7:30001
nodeID: ac7jspin96
ip: 172.19.0.2:30001
nodeID: ejbbzmacn0
# Retrieve from configmap
buyer:
domain: fluidos.eu
ip: 172.18.0.5:30000
nodeID: 4sqa7o2wsh
ip: 172.19.0.5:30000
nodeID: e9d2mzsbcf
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
name: solver-sample-3
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"
intentID: "intent-sample-3"
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func (r *ReservationReconciler) handleReserve(ctx context.Context,

// Set the peering candidate as not available
peeringCandidate.Spec.Available = false
peeringCandidate.Spec.SolverID = reservation.Spec.SolverID
if err := r.Update(ctx, peeringCandidate); err != nil {
klog.Errorf("Error when updating PeeringCandidate %s status before reconcile: %s", req.NamespacedName, err)
return ctrl.Result{}, err
Expand All @@ -187,7 +186,6 @@ func (r *ReservationReconciler) handleReserve(ctx context.Context,

// Set the peering candidate as available again
peeringCandidate.Spec.Available = true
peeringCandidate.Spec.SolverID = ""
if err := r.Update(ctx, peeringCandidate); err != nil {
klog.Errorf("Error when updating PeeringCandidate %s status before reconcile: %s", req.NamespacedName, err)
return ctrl.Result{}, err
Expand Down Expand Up @@ -341,7 +339,6 @@ func (r *ReservationReconciler) handlePurchase(ctx context.Context,
}

peeringCandidate.Spec.Available = true
peeringCandidate.Spec.SolverID = ""
if err := r.Update(ctx, &peeringCandidate); err != nil {
klog.Errorf("Error when updating PeeringCandidate %s status before reconcile: %s", req.NamespacedName, err)
return ctrl.Result{}, err
Expand Down
22 changes: 7 additions & 15 deletions pkg/rear-controller/discovery-manager/peeringcandidate_wh.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func (v *PCValidator) HandleCreate(_ context.Context, req admission.Request) adm
return admission.Errored(http.StatusBadRequest, fmt.Errorf("failed to decode peering candidate: %w", err))
}

if !pc.Spec.Available && pc.Spec.SolverID == "" {
return admission.Denied("If peering candidate is not available, solver ID must be set")
if pc.Spec.Available && len(pc.Spec.InterestedSolverIDs) == 0 {
return admission.Denied("Can't create a peering candidate wihout a triggering solver")
}

if pc.Spec.Available && pc.Spec.SolverID != "" {
return admission.Denied("If peering candidate is available, solver ID must not be set")
if !pc.Spec.Available {
return admission.Denied("Can't create a peering candidate with Available flag set to false")
}

return admission.Allowed("")
Expand Down Expand Up @@ -108,20 +108,12 @@ func (v *PCValidator) HandleUpdate(_ context.Context, req admission.Request) adm
return admission.Errored(http.StatusBadRequest, fmt.Errorf("failed to decode peering old candidate: %w", err))
}

// PC can be updated only if:
// - both Reserved flag and SolverID are not set (i.e. it is not reserved)
// - both Reserved flag and SolverID are set and you want to clear both in the same time

if !pcOld.Spec.Available && pcOld.Spec.SolverID == "" {
return admission.Allowed("")
}

if !pcOld.Spec.Available && pcOld.Spec.SolverID != "" && pc.Spec.Available && pc.Spec.SolverID == "" {
return admission.Allowed("")
if !pcOld.Spec.Available && !pc.Spec.Available {
return admission.Denied("Peering candidate can be updated if Available flag is changed from false to true")
}

//nolint:lll // This is a long line
return admission.Denied("peering candidate can be updated only if it is not reserved or if both Reserved flag and SolverID are set and you want to clear both in the same time")
return admission.Allowed("")
}

// DecodePeeringCandidate decodes the PeeringCandidate.
Expand Down
2 changes: 1 addition & 1 deletion pkg/rear-controller/gateway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (g *Gateway) purchaseFlavor(w http.ResponseWriter, r *http.Request) {

// Create allocation
klog.Infof("Creating allocation...")
allocation := *resourceforge.ForgeAllocation(&contract, "")
allocation := *resourceforge.ForgeAllocation(&contract)
err = g.client.Create(context.Background(), &allocation)
if err != nil {
klog.Errorf("Error creating the Allocation: %s", err)
Expand Down
Loading

0 comments on commit 8d17d9c

Please sign in to comment.