Skip to content

Commit 3257c7d

Browse files
authored
Telemetry endpoint for receiving data implemented in REAR client, server and related CRDs (#6) (#134)
1 parent edbffa0 commit 3257c7d

File tree

12 files changed

+159
-8
lines changed

12 files changed

+159
-8
lines changed

apis/reservation/v1alpha1/contract_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ type ContractSpec struct {
5252

5353
// NetworkRequests contains the reference to the resource containing the network requests.
5454
NetworkRequests string `json:"networkRequests,omitempty"`
55+
56+
// IngressTelemetryEndpoint is the endpoint where the ingress telemetry is sent by the provider
57+
IngressTelemetryEndpoint *TelemetryServer `json:"ingressTelemetryEndpoint,omitempty"`
5558
}
5659

5760
// ContractStatus defines the observed state of Contract.

apis/reservation/v1alpha1/reservation_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import (
2020
nodecorev1alpha1 "github.com/fluidos-project/node/apis/nodecore/v1alpha1"
2121
)
2222

23+
// TelemetryServer defines the telemetry server configuration.
24+
type TelemetryServer struct {
25+
// Endpoint is the endpoint where the telemetry is sent by the provider
26+
Endpoint string `json:"endpoint"`
27+
// Intents is the list of intents
28+
Intents []string `json:"intents,omitempty"`
29+
}
30+
2331
// ReservationSpec defines the desired state of Reservation.
2432
type ReservationSpec struct {
2533

@@ -43,6 +51,9 @@ type ReservationSpec struct {
4351

4452
// PeeringCandidate is the reference to the PeeringCandidate of the Reservation
4553
PeeringCandidate nodecorev1alpha1.GenericRef `json:"peeringCandidate,omitempty"`
54+
55+
// IngressTelemetryEndpoint is the endpoint where the ingress telemetry is sent by the provider
56+
IngressTelemetryEndpoint *TelemetryServer `json:"ingressTelemetryEndpoint,omitempty"`
4657
}
4758

4859
// ReservationStatus defines the observed state of Reservation.

apis/reservation/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployments/node/crds/reservation.fluidos.eu_contracts.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@ spec:
281281
- lastUpdateTime
282282
type: object
283283
type: object
284+
ingressTelemetryEndpoint:
285+
description: IngressTelemetryEndpoint is the endpoint where the ingress
286+
telemetry is sent by the provider
287+
properties:
288+
endpoint:
289+
description: Endpoint is the endpoint where the telemetry is sent
290+
by the provider
291+
type: string
292+
intents:
293+
description: Intents is the list of intents
294+
items:
295+
type: string
296+
type: array
297+
required:
298+
- endpoint
299+
type: object
284300
networkRequests:
285301
description: NetworkRequests contains the reference to the resource
286302
containing the network requests.

deployments/node/crds/reservation.fluidos.eu_reservations.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ spec:
119119
- data
120120
- type
121121
type: object
122+
ingressTelemetryEndpoint:
123+
description: IngressTelemetryEndpoint is the endpoint where the ingress
124+
telemetry is sent by the provider
125+
properties:
126+
endpoint:
127+
description: Endpoint is the endpoint where the telemetry is sent
128+
by the provider
129+
type: string
130+
intents:
131+
description: Intents is the list of intents
132+
items:
133+
type: string
134+
type: array
135+
required:
136+
- endpoint
137+
type: object
122138
peeringCandidate:
123139
description: PeeringCandidate is the reference to the PeeringCandidate
124140
of the Reservation

pkg/rear-controller/gateway/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ func (g *Gateway) PurchaseFlavor(ctx context.Context, transactionID string,
144144
return nil, err
145145
}
146146

147+
// Get Reservation from the transaction
148+
reservation, err := getters.GetReservationByTransactionID(ctx, g.client, transactionID)
149+
if err != nil {
150+
return nil, err
151+
}
152+
153+
// Parse the IngressTelemetryEndpoint
154+
ite := parseutil.ParseTelemetryServer(reservation.Spec.IngressTelemetryEndpoint)
155+
147156
klog.Infof("Transaction %s for flavor %s", transactionID, transaction.FlavorID)
148157

149158
var liqoCredentials *models.LiqoCredentials
@@ -156,7 +165,8 @@ func (g *Gateway) PurchaseFlavor(ctx context.Context, transactionID string,
156165
}
157166

158167
body := models.PurchaseRequest{
159-
LiqoCredentials: liqoCredentials,
168+
LiqoCredentials: liqoCredentials,
169+
IngressTelemetryEndpoint: ite,
160170
}
161171

162172
selectorBytes, err := json.Marshal(body)

pkg/rear-controller/gateway/provider.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,13 @@ func (g *Gateway) purchaseFlavor(w http.ResponseWriter, r *http.Request) {
541541
// Create a new contract
542542
klog.Infof("Creating a new contract...")
543543
// Forge the contract object
544-
contract = *resourceforge.ForgeContract(flavorSold, &transaction, liqoCredentials, sellerLiqoCredentials.ClusterID)
544+
contract = *resourceforge.ForgeContract(
545+
flavorSold,
546+
&transaction,
547+
liqoCredentials,
548+
sellerLiqoCredentials.ClusterID,
549+
purchase.IngressTelemetryEndpoint,
550+
)
545551
err = g.client.Create(context.Background(), &contract)
546552
if err != nil {
547553
klog.Errorf("Error creating the Contract: %s", err)

pkg/utils/getters/getters.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ func GetLiqoCredentials(ctx context.Context, cl client.Client) (*nodecorev1alpha
126126
}, nil
127127
}
128128

129+
// GetReservationByTransactionID retrieves the Reservation with the given transaction ID.
130+
func GetReservationByTransactionID(ctx context.Context, c client.Client, transactionID string) (*reservationv1alpha1.Reservation, error) {
131+
// Get all the Reservations
132+
reservations := &reservationv1alpha1.ReservationList{}
133+
if err := c.List(ctx, reservations, client.InNamespace(flags.FluidosNamespace)); err != nil {
134+
klog.Errorf("Error getting the Reservations: %s", err)
135+
return nil, err
136+
}
137+
138+
for i := range reservations.Items {
139+
reservation := reservations.Items[i]
140+
if reservation.Status.TransactionID == transactionID {
141+
return &reservation, nil
142+
}
143+
}
144+
145+
return nil, fmt.Errorf("reservation with transaction ID %s not found", transactionID)
146+
}
147+
129148
// GetAllocationByClusterIDSpec retrieves the name of the allocation with the given in its Specs.
130149
func GetAllocationByClusterIDSpec(ctx context.Context, c client.Client, clusterID string) (nodecorev1alpha1.AllocationList, error) {
131150
filteredAllocations := nodecorev1alpha1.AllocationList{}

pkg/utils/models/gateway.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type PurchaseRequest struct {
2020
// This field is optional and should be used only if the buyer is the Liqo peering target cluster, based on the Flavor you are going to purchase.
2121
// This field may be dismissed in the future version of Liqo.
2222
LiqoCredentials *LiqoCredentials `json:"liqoCredentials,omitempty"`
23+
// IngressTelemetryEndpoint is the endpoint where the buyer wants to receive the telemetry data.
24+
// This field is optional and should be used only if continuous telemetry is needed.
25+
IngressTelemetryEndpoint *TelemetryServer `json:"ingressTelemetryEndpoint,omitempty"`
2326
}
2427

2528
// ReserveRequest is the request model for reserving a Flavor.

pkg/utils/models/reservation.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ type Transaction struct {
3939
ExpirationTime string `json:"expirationTime"`
4040
}
4141

42+
// TelemetryServer represents a TelemetryServer object with its characteristics.
43+
type TelemetryServer struct {
44+
Endpoint string `json:"endpoint"`
45+
Intents []string `json:"intents"`
46+
}
47+
4248
// Contract represents a Contract object with its characteristics.
4349
type Contract struct {
4450
ContractID string `json:"contractID"`
@@ -52,6 +58,7 @@ type Contract struct {
5258
ExtraInformation map[string]string `json:"extraInformation,omitempty"`
5359
Configuration *Configuration `json:"configuration,omitempty"`
5460
NetworkRequests string `json:"networkAuthorizations,omitempty"`
61+
IngressTelemetryEndpoint *TelemetryServer `json:"ingressTelemetryEndpoint,omitempty"`
5562
}
5663

5764
// LiqoCredentials contains the credentials of a Liqo cluster to establish a peering.

0 commit comments

Comments
 (0)