/
enclave_context.go
507 lines (461 loc) · 22.9 KB
/
enclave_context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
* Copyright 2021 Kurtosis Technologies Inc.
*
* 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 enclaves
import (
"context"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/binding_constructors"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/services"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/shared_utils"
"github.com/kurtosis-tech/kurtosis/grpc-file-transfer/golang/grpc_file_streaming"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
"io"
"path"
"strings"
)
type EnclaveUUID string
const (
kurtosisYamlFilename = "kurtosis.yml"
enforceMaxFileSizeLimit = true
)
// Docs available at https://docs.kurtosis.com/sdk/#enclavecontext
type EnclaveContext struct {
client kurtosis_core_rpc_api_bindings.ApiContainerServiceClient
enclaveUuid EnclaveUUID
enclaveName string
}
/*
Creates a new EnclaveContext object with the given parameters.
*/
// TODO Migrate this to take in API container IP & API container GRPC port num, to match the (better) way that
// Typescript does it, so that the user doesn't have to figure out how to instantiate the ApiContainerServiceClient on their own!
func NewEnclaveContext(
client kurtosis_core_rpc_api_bindings.ApiContainerServiceClient,
enclaveUuid EnclaveUUID,
enclaveName string,
) *EnclaveContext {
return &EnclaveContext{
client: client,
enclaveUuid: enclaveUuid,
enclaveName: enclaveName,
}
}
// Docs available at https://docs.kurtosis.com/sdk/#getenclaveuuid---enclaveuuid
func (enclaveCtx *EnclaveContext) GetEnclaveUuid() EnclaveUUID {
return enclaveCtx.enclaveUuid
}
// Docs available at https://docs.kurtosis.com/sdk/#getenclavename---string
func (enclaveCtx *EnclaveContext) GetEnclaveName() string {
return enclaveCtx.enclaveName
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkscriptstring-serializedstarlarkscript-boolean-dryrun---streamstarlarkrunresponseline-responselines-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkScript(
ctx context.Context,
mainFunctionName string,
serializedScript string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) {
ctxWithCancel, cancelCtxFunc := context.WithCancel(ctx)
executeStartosisScriptArgs := binding_constructors.NewRunStarlarkScriptArgs(mainFunctionName, serializedScript, serializedParams, dryRun, parallelism, experimentalFeatures)
starlarkResponseLineChan := make(chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine)
stream, err := enclaveCtx.client.RunStarlarkScript(ctxWithCancel, executeStartosisScriptArgs)
if err != nil {
cancelCtxFunc() // manually call the cancel function as something went wrong
return nil, nil, stacktrace.Propagate(err, "Unexpected error happened executing Kurtosis script.")
}
go runReceiveStarlarkResponseLineRoutine(cancelCtxFunc, stream, starlarkResponseLineChan)
return starlarkResponseLineChan, cancelCtxFunc, nil
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkscriptblockingstring-serializedstarlarkscript-boolean-dryrun---starlarkrunresult-runresult-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkScriptBlocking(ctx context.Context, mainFunctionName string, serializedScript string, serializedParams string, dryRun bool, parallelism int32, experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag) (*StarlarkRunResult, error) {
starlarkRunResponseLineChan, _, err := enclaveCtx.RunStarlarkScript(ctx, mainFunctionName, serializedScript, serializedParams, dryRun, parallelism, experimentalFeatures)
if err != nil {
return nil, stacktrace.Propagate(err, "Error requesting Starlark Script run")
}
starlarkResponse := ReadStarlarkRunResponseLineBlocking(starlarkRunResponseLineChan)
return starlarkResponse, getErrFromStarlarkRunResult(starlarkResponse)
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkpackagestring-packagerootpath-string-serializedparams-boolean-dryrun---streamstarlarkrunresponseline-responselines-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkPackage(
ctx context.Context,
packageRootPath string,
relativePathToMainFile string,
mainFunctionName string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) {
executionStartedSuccessfully := false
ctxWithCancel, cancelCtxFunc := context.WithCancel(ctx)
defer func() {
if !executionStartedSuccessfully {
cancelCtxFunc() // cancel the context as something went wrong
}
}()
starlarkResponseLineChan := make(chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine)
executeStartosisPackageArgs, err := enclaveCtx.assembleRunStartosisPackageArg(packageRootPath, relativePathToMainFile, mainFunctionName, serializedParams, dryRun, parallelism, experimentalFeatures)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "Error preparing package '%s' for execution", packageRootPath)
}
err = enclaveCtx.uploadStarlarkPackage(executeStartosisPackageArgs.PackageId, packageRootPath)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "Error uploading package '%s' prior to executing it", packageRootPath)
}
stream, err := enclaveCtx.client.RunStarlarkPackage(ctxWithCancel, executeStartosisPackageArgs)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "Unexpected error happened executing Starlark package '%v'", packageRootPath)
}
go runReceiveStarlarkResponseLineRoutine(cancelCtxFunc, stream, starlarkResponseLineChan)
executionStartedSuccessfully = true
return starlarkResponseLineChan, cancelCtxFunc, nil
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkpackageblockingstring-packagerootpath-string-serializedparams-boolean-dryrun---starlarkrunresult-runresult-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkPackageBlocking(
ctx context.Context,
packageRootPath string,
relativePathToMainFile string,
mainFunctionName string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (*StarlarkRunResult, error) {
starlarkRunResponseLineChan, _, err := enclaveCtx.RunStarlarkPackage(ctx, packageRootPath, relativePathToMainFile, mainFunctionName, serializedParams, dryRun, parallelism, experimentalFeatures)
if err != nil {
return nil, stacktrace.Propagate(err, "Error running Starlark package")
}
starlarkResponse := ReadStarlarkRunResponseLineBlocking(starlarkRunResponseLineChan)
return starlarkResponse, getErrFromStarlarkRunResult(starlarkResponse)
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkremotepackagestring-packageid-string-serializedparams-boolean-dryrun---streamstarlarkrunresponseline-responselines-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkRemotePackage(
ctx context.Context,
packageId string,
relativePathToMainFile string,
mainFunctionName string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) {
executionStartedSuccessfully := false
ctxWithCancel, cancelCtxFunc := context.WithCancel(ctx)
defer func() {
if !executionStartedSuccessfully {
cancelCtxFunc() // cancel the context as something went wrong
}
}()
starlarkResponseLineChan := make(chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine)
executeStartosisScriptArgs := binding_constructors.NewRunStarlarkRemotePackageArgs(packageId, relativePathToMainFile, mainFunctionName, serializedParams, dryRun, parallelism, experimentalFeatures)
stream, err := enclaveCtx.client.RunStarlarkPackage(ctxWithCancel, executeStartosisScriptArgs)
if err != nil {
return nil, nil, stacktrace.Propagate(err, "Unexpected error happened executing Starlark package '%v'", packageId)
}
go runReceiveStarlarkResponseLineRoutine(cancelCtxFunc, stream, starlarkResponseLineChan)
executionStartedSuccessfully = true
return starlarkResponseLineChan, cancelCtxFunc, nil
}
// Docs available at https://docs.kurtosis.com/sdk/#runstarlarkremotepackageblockingstring-packageid-string-serializedparams-boolean-dryrun---starlarkrunresult-runresult-error-error
func (enclaveCtx *EnclaveContext) RunStarlarkRemotePackageBlocking(
ctx context.Context,
packageId string,
relativePathToMainFile string,
mainFunctionName string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (*StarlarkRunResult, error) {
starlarkRunResponseLineChan, _, err := enclaveCtx.RunStarlarkRemotePackage(ctx, packageId, relativePathToMainFile, mainFunctionName, serializedParams, dryRun, parallelism, experimentalFeatures)
if err != nil {
return nil, stacktrace.Propagate(err, "Error running remote Starlark package")
}
starlarkResponse := ReadStarlarkRunResponseLineBlocking(starlarkRunResponseLineChan)
return starlarkResponse, getErrFromStarlarkRunResult(starlarkResponse)
}
// Docs available at https://docs.kurtosis.com/sdk#getservicecontextstring-serviceidentifier---servicecontext-servicecontext
func (enclaveCtx *EnclaveContext) GetServiceContext(serviceIdentifier string) (*services.ServiceContext, error) {
serviceIdentifierMapForArgs := map[string]bool{serviceIdentifier: true}
getServiceInfoArgs := binding_constructors.NewGetServicesArgs(serviceIdentifierMapForArgs)
response, err := enclaveCtx.client.GetServices(context.Background(), getServiceInfoArgs)
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred when trying to get info for service '%v'",
serviceIdentifier)
}
serviceInfo, found := response.GetServiceInfo()[serviceIdentifier]
if !found {
return nil, stacktrace.NewError("Failed to retrieve service information for service '%v'", serviceIdentifier)
}
if serviceInfo.GetPrivateIpAddr() == "" {
return nil, stacktrace.NewError(
"Kurtosis API reported an empty private IP address for service '%v' - this should never happen, and is a bug with Kurtosis!",
serviceIdentifier)
}
serviceCtxPrivatePorts, err := convertApiPortsToServiceContextPorts(serviceInfo.GetPrivatePorts())
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred converting the private ports returned by the API to ports usable by the service context")
}
serviceCtxPublicPorts, err := convertApiPortsToServiceContextPorts(serviceInfo.GetMaybePublicPorts())
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred converting the public ports returned by the API to ports usable by the service context")
}
serviceContext := services.NewServiceContext(
enclaveCtx.client,
services.ServiceName(serviceIdentifier),
services.ServiceUUID(serviceInfo.ServiceUuid),
serviceInfo.GetPrivateIpAddr(),
serviceCtxPrivatePorts,
serviceInfo.GetMaybePublicIpAddr(),
serviceCtxPublicPorts,
)
return serviceContext, nil
}
// Docs available at https://docs.kurtosis.com/sdk#getservices---mapservicename--serviceuuid-serviceidentifiers
func (enclaveCtx *EnclaveContext) GetServices() (map[services.ServiceName]services.ServiceUUID, error) {
getServicesArgs := binding_constructors.NewGetServicesArgs(map[string]bool{})
response, err := enclaveCtx.client.GetServices(context.Background(), getServicesArgs)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting the services in the enclave")
}
serviceInfos := make(map[services.ServiceName]services.ServiceUUID, len(response.GetServiceInfo()))
for serviceIdStr, responseServiceInfo := range response.GetServiceInfo() {
serviceName := services.ServiceName(serviceIdStr)
serviceUuid := services.ServiceUUID(responseServiceInfo.GetServiceUuid())
serviceInfos[serviceName] = serviceUuid
}
return serviceInfos, nil
}
// Docs available at https://docs.kurtosis.com/sdk#uploadfilesstring-pathtoupload-string-artifactname
func (enclaveCtx *EnclaveContext) UploadFiles(pathToUpload string, artifactName string) (services.FilesArtifactUUID, services.FileArtifactName, error) {
content, contentSize, _, err := shared_utils.CompressPath(pathToUpload, enforceMaxFileSizeLimit)
if err != nil {
return "", "", stacktrace.Propagate(err,
"There was an error compressing the file '%v' before upload",
pathToUpload)
}
defer content.Close()
// TODO: add content hash to API as well since we have it, as an optional field
client, err := enclaveCtx.client.UploadFilesArtifact(context.Background())
if err != nil {
return "", "", stacktrace.Propagate(err, "An error was encountered initiating the data upload to the API Container.")
}
clientStream := grpc_file_streaming.NewClientStream[kurtosis_core_rpc_api_bindings.StreamedDataChunk, kurtosis_core_rpc_api_bindings.UploadFilesArtifactResponse](client)
response, err := clientStream.SendData(
artifactName,
content,
contentSize,
func(previousChunkHash string, contentChunk []byte) (*kurtosis_core_rpc_api_bindings.StreamedDataChunk, error) {
return &kurtosis_core_rpc_api_bindings.StreamedDataChunk{
Data: contentChunk,
PreviousChunkHash: previousChunkHash,
Metadata: &kurtosis_core_rpc_api_bindings.DataChunkMetadata{
Name: artifactName,
},
}, nil
},
)
if err != nil {
return "", "", stacktrace.Propagate(err, "An error was encountered while uploading data to the API Container.")
}
return services.FilesArtifactUUID(response.GetUuid()), services.FileArtifactName(response.GetName()), nil
}
// Docs available at https://docs.kurtosis.com/sdk#storewebfilesstring-urltodownload-string-artifactname
func (enclaveCtx *EnclaveContext) StoreWebFiles(ctx context.Context, urlToStoreWeb string, artifactName string) (services.FilesArtifactUUID, error) {
args := binding_constructors.NewStoreWebFilesArtifactArgs(urlToStoreWeb, artifactName)
response, err := enclaveCtx.client.StoreWebFilesArtifact(ctx, args)
if err != nil {
return "", stacktrace.Propagate(err, "An error occurred downloading files artifact from URL '%v'", urlToStoreWeb)
}
return services.FilesArtifactUUID(response.Uuid), nil
}
// Docs available at https://docs.kurtosis.com/sdk#downloadfilesartifact-fileidentifier-string
func (enclaveCtx *EnclaveContext) DownloadFilesArtifact(ctx context.Context, artifactIdentifier string) ([]byte, error) {
args := binding_constructors.DownloadFilesArtifactArgs(artifactIdentifier)
client, err := enclaveCtx.client.DownloadFilesArtifact(ctx, args)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred initiating the download of files artifact '%v'", artifactIdentifier)
}
clientStream := grpc_file_streaming.NewClientStream[kurtosis_core_rpc_api_bindings.StreamedDataChunk, []byte](client)
fileContent, err := clientStream.ReceiveData(
artifactIdentifier,
func(dataChunk *kurtosis_core_rpc_api_bindings.StreamedDataChunk) ([]byte, string, error) {
return dataChunk.Data, dataChunk.PreviousChunkHash, nil
},
)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred downloading files artifact '%v'", artifactIdentifier)
}
return fileContent, nil
}
func (enclaveCtx *EnclaveContext) InspectFilesArtifact(ctx context.Context, artifactName services.FileArtifactName) (*kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsResponse, error) {
// TODO(vcolombo): Add a more intuitive return type to this call instead of returning the RPC response
response, err := enclaveCtx.client.InspectFilesArtifactContents(ctx, &kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsRequest{
FileNamesAndUuid: &kurtosis_core_rpc_api_bindings.FilesArtifactNameAndUuid{
FileName: string(artifactName),
FileUuid: "",
},
})
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred inspecting file artifacts")
}
return response, nil
}
// Docs available at https://docs.kurtosis.com/sdk#getexistingandhistoricalserviceidentifiers---serviceidentifiers-serviceidentifiers
func (enclaveCtx *EnclaveContext) GetExistingAndHistoricalServiceIdentifiers(ctx context.Context) (*services.ServiceIdentifiers, error) {
response, err := enclaveCtx.client.GetExistingAndHistoricalServiceIdentifiers(ctx, &emptypb.Empty{})
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred while fetching existing and historical identifiers")
}
return services.NewServiceIdentifiers(enclaveCtx.enclaveName, response.AllIdentifiers), nil
}
// Docs available at https://docs.kurtosis.com/#getallfilesartifactnamesanduuids---filesartifactnameanduuid-filesartifactnamesanduuids
func (enclaveCtx *EnclaveContext) GetAllFilesArtifactNamesAndUuids(ctx context.Context) ([]*kurtosis_core_rpc_api_bindings.FilesArtifactNameAndUuid, error) {
response, err := enclaveCtx.client.ListFilesArtifactNamesAndUuids(ctx, &emptypb.Empty{})
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred while fetching file names and uuids")
}
return response.GetFileNamesAndUuids(), nil
}
// ====================================================================================================
//
// Private helper methods
//
// ====================================================================================================
// convertApiPortsToServiceContextPorts returns a converted map where Port objects associated with strings in [apiPorts] are
// properly converted to PortSpec objects.
// Returns error if:
// - Any protocol associated with a port in [apiPorts] is invalid (eg. not currently supported).
// - Any port number associated with a port [apiPorts] is higher than the max port number.
func convertApiPortsToServiceContextPorts(apiPorts map[string]*kurtosis_core_rpc_api_bindings.Port) (map[string]*services.PortSpec, error) {
result := map[string]*services.PortSpec{}
for portId, apiPortSpec := range apiPorts {
apiTransportProtocol := apiPortSpec.GetTransportProtocol()
serviceCtxTransportProtocol := services.TransportProtocol(apiTransportProtocol)
if !serviceCtxTransportProtocol.IsValid() {
return nil, stacktrace.NewError("Received unrecognized protocol '%v' from the API", apiTransportProtocol)
}
portNumUint32 := apiPortSpec.GetNumber()
if portNumUint32 > services.MaxPortNum {
return nil, stacktrace.NewError(
"Received port number '%v' from the API which is higher than the max allowed port number '%v'",
portNumUint32,
services.MaxPortNum,
)
}
portNumUint16 := uint16(portNumUint32)
apiMaybeApplicationProtocol := apiPortSpec.GetMaybeApplicationProtocol()
result[portId] = services.NewPortSpec(
portNumUint16,
serviceCtxTransportProtocol,
apiMaybeApplicationProtocol,
)
}
return result, nil
}
func runReceiveStarlarkResponseLineRoutine(cancelCtxFunc context.CancelFunc, stream grpc.ClientStream, kurtosisResponseLineChan chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) {
defer func() {
close(kurtosisResponseLineChan)
cancelCtxFunc()
}()
for {
responseLine := new(kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine)
err := stream.RecvMsg(responseLine)
if err == io.EOF {
logrus.Debugf("Successfully reached the end of the response stream. Closing.")
return
}
if err != nil {
logrus.Errorf("Unexpected error happened reading the stream. Client might have cancelled the stream\n%v", err.Error())
return
}
kurtosisResponseLineChan <- responseLine
}
}
func getErrFromStarlarkRunResult(result *StarlarkRunResult) error {
if result.InterpretationError != nil {
return stacktrace.NewError(result.InterpretationError.GetErrorMessage())
}
if len(result.ValidationErrors) > 0 {
errorMessages := []string{}
for _, validationErr := range result.ValidationErrors {
errorMessages = append(errorMessages, validationErr.GetErrorMessage())
}
return stacktrace.NewError("Found %v validation errors: %v", len(result.ValidationErrors), strings.Join(errorMessages, "\n"))
}
if result.ExecutionError != nil {
return stacktrace.NewError(result.ExecutionError.GetErrorMessage())
}
return nil
}
func (enclaveCtx *EnclaveContext) assembleRunStartosisPackageArg(
packageRootPath string,
relativePathToMainFile string,
mainFunctionName string,
serializedParams string,
dryRun bool,
parallelism int32,
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
) (*kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs, error) {
kurtosisYamlFilepath := path.Join(packageRootPath, kurtosisYamlFilename)
kurtosisYaml, err := ParseKurtosisYaml(kurtosisYamlFilepath)
if err != nil {
return nil, stacktrace.Propagate(err, "There was an error parsing the '%v' at '%v'", kurtosisYamlFilename, packageRootPath)
}
return binding_constructors.NewRunStarlarkPackageArgs(kurtosisYaml.PackageName, relativePathToMainFile, mainFunctionName, serializedParams, dryRun, parallelism, experimentalFeatures), nil
}
func (enclaveCtx *EnclaveContext) uploadStarlarkPackage(packageId string, packageRootPath string) error {
logrus.Infof("Compressing package '%v' at '%v' for upload", packageId, packageRootPath)
compressedModule, commpressedModuleSize, _, err := shared_utils.CompressPath(packageRootPath, enforceMaxFileSizeLimit)
if err != nil {
return stacktrace.Propagate(err, "There was an error compressing module '%v' before upload", packageRootPath)
}
defer compressedModule.Close()
logrus.Infof("Uploading and executing package '%v'", packageId)
// TODO: add content hash to API here as well
client, err := enclaveCtx.client.UploadStarlarkPackage(context.Background())
if err != nil {
return stacktrace.Propagate(err, "An error was encountered initiating the data upload to the API Container.")
}
clientStream := grpc_file_streaming.NewClientStream[kurtosis_core_rpc_api_bindings.StreamedDataChunk, emptypb.Empty](client)
_, err = clientStream.SendData(
packageId,
compressedModule,
commpressedModuleSize,
func(previousChunkHash string, contentChunk []byte) (*kurtosis_core_rpc_api_bindings.StreamedDataChunk, error) {
return &kurtosis_core_rpc_api_bindings.StreamedDataChunk{
Data: contentChunk,
PreviousChunkHash: previousChunkHash,
Metadata: &kurtosis_core_rpc_api_bindings.DataChunkMetadata{
Name: packageId,
},
}, nil
},
)
if err != nil {
return stacktrace.Propagate(err, "An error was encountered while uploading data to the API Container.")
}
return nil
}