Skip to content

Commit

Permalink
Added grpc server, liqo credentials getter, fixed and improved resour…
Browse files Browse the repository at this point in the history
…ces and models
  • Loading branch information
cannarelladev committed Oct 17, 2023
1 parent 6e22326 commit e2cac2a
Show file tree
Hide file tree
Showing 18 changed files with 534 additions and 124 deletions.
7 changes: 5 additions & 2 deletions apis/reservation/v1alpha1/contract_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ContractSpec struct {
Flavour nodecorev1alpha1.Flavour `json:"flavour"`

// TransactionID is the ID of the transaction that this contract is part of
TransactionID string `json:"transactionID,omitempty"`
TransactionID string `json:"transactionID"`

// The partition represents the dimension of the resources sold/bought.
// So it will reflect the dimension of the resources allocated on the remote cluster and reflected on the local virtual node.
Expand All @@ -46,11 +46,14 @@ type ContractSpec struct {
// This is the Node identity of the buyer FLUIDOS Node.
Buyer nodecorev1alpha1.NodeIdentity `json:"buyer"`

// BuyerClusterID is the Liqo ClusterID used by the seller to search a contract and the related resources during the peering phase.
BuyerClusterID string `json:"buyerClusterID"`

// This is the Node identity of the seller FLUIDOS Node.
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.
Credentials *LiqoCredentials `json:"credentials,omitempty"`
SellerCredentials 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
3 changes: 3 additions & 0 deletions apis/reservation/v1alpha1/reservation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type ReservationSpec struct {
// This is the Node identity of the buyer FLUIDOS Node.
Buyer nodecorev1alpha1.NodeIdentity `json:"buyer"`

// BuyerClusterID is the Liqo ClusterID used by the seller to search a contract and the related resources during the peering phase.
BuyerClusterID string `json:"buyerClusterID"`

// This is the Node identity of the seller FLUIDOS Node.
Seller nodecorev1alpha1.NodeIdentity `json:"seller"`

Expand Down
3 changes: 3 additions & 0 deletions apis/reservation/v1alpha1/transaction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type TransactionSpec struct {
// Buyer is the buyer Identity of the Fluidos Node that is reserving the Flavour
Buyer nodecorev1alpha1.NodeIdentity `json:"buyer"`

// ClusterID is the Liqo ClusterID of the Fluidos Node that is reserving the Flavour
ClusterID string `json:"clusterID"`

// Partition is the partition of the flavour that is being reserved
Partition Partition `json:"partition,omitempty"`

Expand Down
6 changes: 1 addition & 5 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.

23 changes: 21 additions & 2 deletions cmd/rear-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
contractmanager "github.com/fluidos-project/node/pkg/rear-controller/contract-manager"
discoverymanager "github.com/fluidos-project/node/pkg/rear-controller/discovery-manager"
gateway "github.com/fluidos-project/node/pkg/rear-controller/gateway"
"github.com/fluidos-project/node/pkg/rear-controller/grpc"
"github.com/fluidos-project/node/pkg/utils/flags"
//+kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -90,17 +91,30 @@ func main() {

cache := mgr.GetCache()

indexFunc := func(obj client.Object) []string {
// Index the TransactionID field of the Contract CRD
indexFuncTransaction := func(obj client.Object) []string {
contract := obj.(*reservationv1alpha1.Contract)
return []string{contract.Spec.TransactionID}
}

if err := cache.IndexField(context.Background(), &reservationv1alpha1.Contract{}, "spec.transactionID", indexFunc); err != nil {
// Index the ClusterID field of the Contract CRD
indexFuncClusterID := func(obj client.Object) []string {
contract := obj.(*reservationv1alpha1.Contract)
return []string{contract.Spec.BuyerClusterID}
}

if err := cache.IndexField(context.Background(), &reservationv1alpha1.Contract{}, "spec.transactionID", indexFuncTransaction); err != nil {
setupLog.Error(err, "unable to create index for field", "field", "spec.transactionID")
os.Exit(1)
}

if err := cache.IndexField(context.Background(), &reservationv1alpha1.Contract{}, "spec.buyerClusterID", indexFuncClusterID); err != nil {
setupLog.Error(err, "unable to create index for field", "field", "spec.buyerClusterID")
os.Exit(1)
}

gw := gateway.NewGateway(mgr.GetClient())
grpcServer := grpc.NewGrpcServer(mgr.GetClient())

if err = (&discoverymanager.DiscoveryReconciler{
Client: mgr.GetClient(),
Expand Down Expand Up @@ -140,6 +154,11 @@ func main() {
gw.StartHttpServer()
}()

// Start the REAR GRPC server
go func() {
grpcServer.Start()
}()

// TODO: Uncomment this when the webhook is ready. For now it does not work (Ale)
// pcv := discoverymanager.NewPCValidator(mgr.GetClient())

Expand Down
44 changes: 26 additions & 18 deletions deployments/node/crds/reservation.fluidos.eu_contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,11 @@ spec:
- ip
- nodeID
type: object
credentials:
description: This credentials will be used by the customer to connect
and enstablish a peering with the seller FLUIDOS Node through Liqo.
properties:
clusterID:
type: string
clusterName:
type: string
endpoint:
type: string
token:
type: string
required:
- clusterID
- clusterName
- endpoint
- token
type: object
buyerClusterID:
description: BuyerClusterID is the Liqo ClusterID used by the seller
to search a contract and the related resources during the peering
phase.
type: string
expirationTime:
description: This is the expiration time of the contract. It can be
empty if the contract is not time limited.
Expand Down Expand Up @@ -380,14 +367,35 @@ spec:
- ip
- nodeID
type: object
sellerCredentials:
description: This credentials will be used by the customer to connect
and enstablish a peering with the seller FLUIDOS Node through Liqo.
properties:
clusterID:
type: string
clusterName:
type: string
endpoint:
type: string
token:
type: string
required:
- clusterID
- clusterName
- endpoint
- token
type: object
transactionID:
description: TransactionID is the ID of the transaction that this
contract is part of
type: string
required:
- buyer
- buyerClusterID
- flavour
- seller
- sellerCredentials
- transactionID
type: object
status:
description: ContractStatus defines the observed state of Contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ spec:
- ip
- nodeID
type: object
buyerClusterID:
description: BuyerClusterID is the Liqo ClusterID used by the seller
to search a contract and the related resources during the peering
phase.
type: string
partition:
description: Parition is the partition of the flavour that is being
reserved
Expand Down Expand Up @@ -166,6 +171,7 @@ spec:
type: string
required:
- buyer
- buyerClusterID
- seller
- solverID
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ spec:
- ip
- nodeID
type: object
clusterID:
description: ClusterID is the Liqo ClusterID of the Fluidos Node that
is reserving the Flavour
type: string
flavourID:
description: FlavourID is the ID of the flavour that is being reserved
type: string
Expand Down Expand Up @@ -99,6 +103,7 @@ spec:
type: string
required:
- buyer
- clusterID
- flavourID
type: object
status:
Expand Down
54 changes: 32 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ go 1.21.0

require (
github.com/gorilla/mux v1.8.0
k8s.io/api v0.28.0
k8s.io/apimachinery v0.28.0
k8s.io/client-go v0.28.0
github.com/liqotech/liqo v0.9.4
google.golang.org/grpc v1.59.0-dev
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
k8s.io/klog/v2 v2.100.1
k8s.io/metrics v0.28.0
sigs.k8s.io/controller-runtime v0.15.0
k8s.io/metrics v0.28.2
sigs.k8s.io/controller-runtime v0.15.1
)

require (
github.com/aws/aws-sdk-go v1.44.213 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand All @@ -30,8 +33,9 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -40,29 +44,35 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
github.com/virtual-kubelet/virtual-kubelet v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20221114191408-850992195362 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20220504211119-3d4a969bb56b // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/apiextensions-apiserver v0.28.2 // indirect
k8s.io/component-base v0.28.2 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.28.2 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
Loading

0 comments on commit e2cac2a

Please sign in to comment.