Skip to content

Commit

Permalink
Allocation controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cannarelladev committed Oct 25, 2023
1 parent 42ae08a commit c81fbd5
Show file tree
Hide file tree
Showing 63 changed files with 1,680 additions and 867 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ linters-settings:
locale: US
ignore-words:
- "Flavour"
- "Flavours"
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
Expand Down
50 changes: 50 additions & 0 deletions apis/nodecore/v1alpha1/allocation_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022-2023 FLUIDOS Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import "github.com/fluidos-project/node/pkg/utils/tools"

// SetStatus sets the status of the allocation.
func (allocation *Allocation) SetStatus(status Status, msg string) {
allocation.Status.Status = status
allocation.Status.LastUpdateTime = tools.GetTimeNow()
allocation.Status.Message = msg
}

/*
// SetPurchasePhase sets the ReserveAndBuy phase of the solver
func (allocation *Allocation) SetReserveAndBuyStatus(phase Phase) {
solver.Status.ReserveAndBuy = phase
solver.Status.SolverPhase.LastChangeTime = tools.GetTimeNow()
}
// SetFindCandidateStatus sets the FindCandidate phase of the solver
func (allocation *Allocation) SetFindCandidateStatus(phase Phase) {
solver.Status.FindCandidate = phase
solver.Status.SolverPhase.LastChangeTime = tools.GetTimeNow()
}
// SetDiscoveryStatus sets the discovery phase of the solver
func (allocation *Allocation) SetDiscoveryStatus(phase Phase) {
solver.Status.DiscoveryPhase = phase
solver.Status.SolverPhase.LastChangeTime = tools.GetTimeNow()
}
// SetReservationStatus sets the reservation phase of the solver
func (allocation *Allocation) SetReservationStatus(phase Phase) {
solver.Status.ReservationPhase = phase
solver.Status.SolverPhase.LastChangeTime = tools.GetTimeNow()
}
*/
47 changes: 33 additions & 14 deletions apis/nodecore/v1alpha1/allocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,79 @@ import (

type NodeType string
type Status string
type Destination string

Check warning on line 23 in apis/nodecore/v1alpha1/allocation_types.go

View workflow job for this annotation

GitHub Actions / Lint golang files

exported: exported type Destination should have comment or be unexported (revive)

// NodeType is the type of the node: Node (Physical node of the cluster) or VirtualNode (Remote node owned by a different cluster).
const (
Node NodeType = "Node"
VirtualNode NodeType = "VirtualNode"
)

// Status is the status of the allocation.
const (
Active Status = "Active"
Reserved Status = "Reserved"
Released Status = "Released"
Inactive Status = "Inactive"
Error Status = "Error"
)

// Destination is the destination of the allocation: Local (the allocation will be used locally)
// or Remote (the allocation will be used from a remote cluster).
const (
Remote Destination = "Remote"
Local Destination = "Local"
)

// AllocationSpec defines the desired state of Allocation
type AllocationSpec struct {
// This is the ID of the cluster that owns the allocation.
RemoteClusterID string `json:"remoteClusterID,omitempty"`

// CustomerID

// 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
// 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 is the corresponding Node or VirtualNode name
// This is the corresponding Node or VirtualNode local name
NodeName string `json:"nodeName"`

// This specifies the type of the node: Node (Physical node of the cluster) or VirtualNode (Remote node owned by a different cluster)
Type NodeType `json:"type"`

// 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
// This specifies if the destination of the allocation is local or remote so if the allocation will be used locally or from a remote cluster
Destination Destination `json:"destination"`

// 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"`

// This Flavour describes the characteristics of the allocation, it is based on the Flavour CRD from which it was created
Flavour Flavour `json:"flavour"`

// This is the dimension of the allocation, it is based on the Flavour CRD from which it was created
Partition *Partition `json:"partition,omitempty"`
// This flags indicates if the Flavour from which the allocation was created was partitioned or not
Partitioned bool `json:"partitioned"`

// This is the dimension of the allocation
Resources *Characteristics `json:"partition,omitempty"`
}

// AllocationStatus defines the observed state of Allocation
// AllocationStatus defines the observed state of Allocation.
type AllocationStatus struct {

// This allow to know the current status of the allocation
Status Status `json:"status"`

// The creation time of the allocation object
CreationTime metav1.Time `json:"creationTime"`
Status Status `json:"status,omitempty"`

// The last time the allocation was updated
LastUpdateTime metav1.Time `json:"lastUpdateTime"`
LastUpdateTime string `json:"lastUpdateTime,omitempty"`

// Message contains the last message of the allocation
Message string `json:"message,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Allocation is the Schema for the allocations API
// Allocation is the Schema for the allocations API.
type Allocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
28 changes: 18 additions & 10 deletions apis/nodecore/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ package v1alpha1

import "k8s.io/apimachinery/pkg/api/resource"

// Set of constants for the phases of the FLUIDOS Node modules.
const (
//PhaseReady Phase = "Ready"
PhaseSolved Phase = "Solved"
PhaseFailed Phase = "Failed"
PhaseRunning Phase = "Running"
PhaseIdle Phase = "Idle"
PhaseTimeout Phase = "Timed Out"
PhaseBackoff Phase = "Backoff"
PhaseActive Phase = "Active"
PhasePending Phase = "Pending"
PhaseInactive Phase = "Inactive"
PhaseSolved Phase = "Solved"
PhaseFailed Phase = "Failed"
PhaseRunning Phase = "Running"
PhaseAllocating Phase = "Allocating"
PhaseIdle Phase = "Idle"
PhaseTimeout Phase = "Timed Out"
PhaseActive Phase = "Active"
PhasePending Phase = "Pending"
PhaseInactive Phase = "Inactive"
)

// GenericRef represents a reference to a generic Kubernetes resource,
Expand Down Expand Up @@ -57,6 +57,14 @@ type Partition struct {
Storage resource.Quantity `json:"storage,omitempty"`
}

// LiqoCredentials contains the credentials of a Liqo cluster to enstablish a peering.
type LiqoCredentials struct {
ClusterID string `json:"clusterID"`
ClusterName string `json:"clusterName"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`
}

// toString() returns a string representation of the GenericRef.
/* func (r GenericRef) toString() string {
if r.Namespace != "" {
Expand Down
6 changes: 6 additions & 0 deletions apis/nodecore/v1alpha1/solver_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func (solver *Solver) SetPhase(phase Phase, msg string) {
solver.Status.SolverPhase.EndTime = t
}

// SetPeeringStatus sets the Peering phase of the solver.
func (solver *Solver) SetPeeringStatus(phase Phase) {
solver.Status.Peering = phase
solver.Status.SolverPhase.LastChangeTime = tools.GetTimeNow()
}

// SetPurchasePhase sets the ReserveAndBuy phase of the solver
func (solver *Solver) SetReserveAndBuyStatus(phase Phase) {
solver.Status.ReserveAndBuy = phase
Expand Down
6 changes: 6 additions & 0 deletions apis/nodecore/v1alpha1/solver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ type SolverStatus struct {
// It can correspond to a virtual node
// The Node Orchestrator will use this allocation to fullfill 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
27 changes: 21 additions & 6 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.

10 changes: 1 addition & 9 deletions apis/reservation/v1alpha1/contract_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ import (
nodecorev1alpha1 "github.com/fluidos-project/node/apis/nodecore/v1alpha1"
)

// LiqoCredentials contains the credentials of a Liqo cluster to enstablish a peering.
type LiqoCredentials struct {
ClusterID string `json:"clusterID"`
ClusterName string `json:"clusterName"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`
}

// ContractSpec defines the desired state of Contract.
type ContractSpec struct {
// This is the flavour on which the contract is based. It is used to lifetime maintain the critical characteristics of the contract.
Expand All @@ -50,7 +42,7 @@ type ContractSpec struct {
Seller nodecorev1alpha1.NodeIdentity `json:"seller"`

// This credentials will be used by the customer to connect and enstablish a peering with the seller FLUIDOS Node through Liqo.
SellerCredentials LiqoCredentials `json:"sellerCredentials"`
SellerCredentials nodecorev1alpha1.LiqoCredentials `json:"sellerCredentials"`

// This is the expiration time of the contract. It can be empty if the contract is not time limited.
ExpirationTime string `json:"expirationTime,omitempty"`
Expand Down
15 changes: 0 additions & 15 deletions apis/reservation/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions pkg/utils/doc.go → cmd/local-resource-manager/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package utils contains shared utility methods for the FLUIDOS environment.
package utils
// Package main is the entrypoint for the local resource manager
package main
26 changes: 14 additions & 12 deletions cmd/local-resource-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

nodecorev1alpha1 "github.com/fluidos-project/node/apis/nodecore/v1alpha1"
localResourceManager "github.com/fluidos-project/node/pkg/local-resource-manager"
localresourcemanager "github.com/fluidos-project/node/pkg/local-resource-manager"
"github.com/fluidos-project/node/pkg/utils/flags"
)

Expand All @@ -50,14 +50,15 @@ func main() {
flag.StringVar(&flags.AMOUNT, "amount", "", "Amount of money set for the flavours of this node")
flag.StringVar(&flags.CURRENCY, "currency", "", "Currency of the money set for the flavours of this node")
flag.StringVar(&flags.PERIOD, "period", "", "Period set for the flavours of this node")
flag.StringVar(&flags.RESOURCE_TYPE, "resources-types", "k8s-fluidos", "Type of the Flavour related to k8s resources")
flag.StringVar(&flags.CPU_MIN, "cpu-min", "0", "Minimum CPU value")
flag.StringVar(&flags.MEMORY_MIN, "memory-min", "0", "Minimum memory value")
flag.StringVar(&flags.CPU_STEP, "cpu-step", "0", "CPU step value")
flag.StringVar(&flags.MEMORY_STEP, "memory-step", "0", "Memory step value")
flag.Int64Var(&flags.MIN_COUNT, "min-count", 0, "Minimum number of flavours")
flag.Int64Var(&flags.MAX_COUNT, "max-count", 0, "Maximum number of flavours")
flag.StringVar(&flags.RESOURCE_NODE_LABEL, "node-resource-label", "node-role.fluidos.eu/resources", "Label used to filter the k8s nodes from which create flavours")
flag.StringVar(&flags.ResourceType, "resources-types", "k8s-fluidos", "Type of the Flavour related to k8s resources")
flag.StringVar(&flags.CPUMin, "cpu-min", "0", "Minimum CPU value")
flag.StringVar(&flags.MemoryMin, "memory-min", "0", "Minimum memory value")
flag.StringVar(&flags.CPUStep, "cpu-step", "0", "CPU step value")
flag.StringVar(&flags.MemoryStep, "memory-step", "0", "Memory step value")
flag.Int64Var(&flags.MinCount, "min-count", 0, "Minimum number of flavours")
flag.Int64Var(&flags.MaxCount, "max-count", 0, "Maximum number of flavours")
flag.StringVar(&flags.ResourceNodeLabel, "node-resource-label", "node-role.fluidos.eu/resources",
"Label used to filter the k8s nodes from which create flavours")

flag.Parse()

Expand All @@ -68,7 +69,7 @@ func main() {
os.Exit(1)
}

err = localResourceManager.Start(context.Background(), cl)
err = localresourcemanager.Start(context.Background(), cl)
if err != nil {
setupLog.Error(err, "Unable to start LocalResourceManager")
os.Exit(1)
Expand All @@ -78,6 +79,7 @@ func main() {
mux.HandleFunc("/healthz", healthHandler) // health check endpoint
mux.HandleFunc("/readyz", healthHandler) // readiness check endpoint

//nolint:gosec // We don't need this kind of security check
server := &http.Server{
Addr: probeAddr,
Handler: mux,
Expand All @@ -90,7 +92,7 @@ func main() {
}
}

func healthHandler(w http.ResponseWriter, r *http.Request) {
func healthHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
_, _ = w.Write([]byte("OK"))
}
Loading

0 comments on commit c81fbd5

Please sign in to comment.