@@ -41,7 +41,6 @@ import (
41
41
42
42
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
43
43
"github.com/devfile/library/v2/pkg/devfile/generator"
44
- "github.com/devfile/library/v2/pkg/devfile/parser"
45
44
parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
46
45
dfutil "github.com/devfile/library/v2/pkg/util"
47
46
@@ -62,8 +61,7 @@ type Adapter struct {
62
61
configAutomountClient configAutomount.Client
63
62
fs filesystem.Filesystem // FS is the object used for building image component if present
64
63
65
- devfile parser.DevfileObj // Devfile is the object returned by the Devfile parser
66
- logger machineoutput.MachineEventLoggingClient
64
+ logger machineoutput.MachineEventLoggingClient
67
65
}
68
66
69
67
var _ ComponentAdapter = (* Adapter )(nil )
@@ -78,7 +76,6 @@ func NewKubernetesAdapter(
78
76
execClient exec.Client ,
79
77
configAutomountClient configAutomount.Client ,
80
78
fs filesystem.Filesystem ,
81
- devfile parser.DevfileObj ,
82
79
) Adapter {
83
80
return Adapter {
84
81
kubeClient : kubernetesClient ,
@@ -89,7 +86,6 @@ func NewKubernetesAdapter(
89
86
execClient : execClient ,
90
87
configAutomountClient : configAutomountClient ,
91
88
fs : fs ,
92
- devfile : devfile ,
93
89
94
90
logger : machineoutput .NewMachineEventLoggingClient (),
95
91
}
@@ -124,7 +120,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
124
120
}
125
121
126
122
klog .V (4 ).Infof ("component state: %q\n " , componentStatus .State )
127
- err = a .buildPushAutoImageComponents (ctx , a .fs , a . devfile , componentStatus )
123
+ err = a .buildPushAutoImageComponents (ctx , a .fs , parameters . Devfile , componentStatus )
128
124
if err != nil {
129
125
return err
130
126
}
@@ -139,11 +135,11 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
139
135
}
140
136
141
137
// Set the mode to Dev since we are using "odo dev" here
142
- runtime := component .GetComponentRuntimeFromDevfileMetadata (a . devfile .Data .GetMetadata ())
138
+ runtime := component .GetComponentRuntimeFromDevfileMetadata (parameters . Devfile .Data .GetMetadata ())
143
139
labels := odolabels .GetLabels (componentName , appName , runtime , odolabels .ComponentDevMode , false )
144
140
145
141
var updated bool
146
- deployment , updated , err = a .createOrUpdateComponent (ctx , deploymentExists , libdevfile.DevfileCommands {
142
+ deployment , updated , err = a .createOrUpdateComponent (ctx , parameters , deploymentExists , libdevfile.DevfileCommands {
147
143
BuildCmd : parameters .DevfileBuildCmd ,
148
144
RunCmd : parameters .DevfileRunCmd ,
149
145
DebugCmd : parameters .DevfileDebugCmd ,
@@ -156,7 +152,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
156
152
// Delete remote resources that are not present in the Devfile
157
153
selector := odolabels .GetSelector (componentName , appName , odolabels .ComponentDevMode , false )
158
154
159
- objectsToRemove , serviceBindingSecretsToRemove , err := a .getRemoteResourcesNotPresentInDevfile (ctx , selector )
155
+ objectsToRemove , serviceBindingSecretsToRemove , err := a .getRemoteResourcesNotPresentInDevfile (ctx , parameters , selector )
160
156
if err != nil {
161
157
return fmt .Errorf ("unable to determine resources to delete: %w" , err )
162
158
}
@@ -176,7 +172,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
176
172
}
177
173
178
174
// Create all the K8s components defined in the devfile
179
- _ , err = a .pushDevfileKubernetesComponents (ctx , labels , odolabels .ComponentDevMode , ownerReference )
175
+ _ , err = a .pushDevfileKubernetesComponents (ctx , parameters , labels , odolabels .ComponentDevMode , ownerReference )
180
176
if err != nil {
181
177
return err
182
178
}
@@ -210,7 +206,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
210
206
}
211
207
212
208
// Check if endpoints changed in Devfile
213
- portsToForward , err := libdevfile .GetDevfileContainerEndpointMapping (a . devfile , parameters .Debug )
209
+ portsToForward , err := libdevfile .GetDevfileContainerEndpointMapping (parameters . Devfile , parameters .Debug )
214
210
if err != nil {
215
211
return err
216
212
}
@@ -280,15 +276,15 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
280
276
281
277
// PostStart events from the devfile will only be executed when the component
282
278
// didn't previously exist
283
- if ! componentStatus .PostStartEventsDone && libdevfile .HasPostStartEvents (a . devfile ) {
284
- err = libdevfile .ExecPostStartEvents (ctx , a . devfile , component .NewExecHandler (a .kubeClient , a .execClient , appName , componentName , pod .Name , "Executing post-start command in container" , parameters .Show ))
279
+ if ! componentStatus .PostStartEventsDone && libdevfile .HasPostStartEvents (parameters . Devfile ) {
280
+ err = libdevfile .ExecPostStartEvents (ctx , parameters . Devfile , component .NewExecHandler (a .kubeClient , a .execClient , appName , componentName , pod .Name , "Executing post-start command in container" , parameters .Show ))
285
281
if err != nil {
286
282
return err
287
283
}
288
284
}
289
285
componentStatus .PostStartEventsDone = true
290
286
291
- cmd , err := libdevfile .ValidateAndGetCommand (a . devfile , cmdName , cmdKind )
287
+ cmd , err := libdevfile .ValidateAndGetCommand (parameters . Devfile , cmdName , cmdKind )
292
288
if err != nil {
293
289
return err
294
290
}
@@ -305,7 +301,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
305
301
kubeClient : a .kubeClient ,
306
302
appName : appName ,
307
303
componentName : componentName ,
308
- devfile : a . devfile ,
304
+ devfile : parameters . Devfile ,
309
305
path : path ,
310
306
podName : pod .GetName (),
311
307
ctx : ctx ,
@@ -336,7 +332,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
336
332
doExecuteBuildCommand := func () error {
337
333
execHandler := component .NewExecHandler (a .kubeClient , a .execClient , appName , componentName , pod .Name ,
338
334
"Building your application in container" , parameters .Show )
339
- return libdevfile .Build (ctx , a . devfile , parameters .DevfileBuildCmd , execHandler )
335
+ return libdevfile .Build (ctx , parameters . Devfile , parameters .DevfileBuildCmd , execHandler )
340
336
}
341
337
if running {
342
338
if cmd .Exec == nil || ! util .SafeGetBool (cmd .Exec .HotReloadCapable ) {
@@ -349,7 +345,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
349
345
return err
350
346
}
351
347
}
352
- err = libdevfile .ExecuteCommandByNameAndKind (ctx , a . devfile , cmdName , cmdKind , & cmdHandler , false )
348
+ err = libdevfile .ExecuteCommandByNameAndKind (ctx , parameters . Devfile , cmdName , cmdKind , & cmdHandler , false )
353
349
if err != nil {
354
350
return err
355
351
}
@@ -369,7 +365,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
369
365
fmt .Fprintln (log .GetStdout ())
370
366
}
371
367
372
- err = a .portForwardClient .StartPortForwarding (ctx , a . devfile , componentName , parameters .Debug , parameters .RandomPorts , log .GetStdout (), parameters .ErrOut , parameters .CustomForwardedPorts )
368
+ err = a .portForwardClient .StartPortForwarding (ctx , parameters . Devfile , componentName , parameters .Debug , parameters .RandomPorts , log .GetStdout (), parameters .ErrOut , parameters .CustomForwardedPorts )
373
369
if err != nil {
374
370
return adapters .NewErrPortForward (err )
375
371
}
@@ -384,6 +380,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
384
380
// Returns the new deployment and if the generation of the deployment has been updated
385
381
func (a * Adapter ) createOrUpdateComponent (
386
382
ctx context.Context ,
383
+ parameters adapters.PushParameters ,
387
384
componentExists bool ,
388
385
commands libdevfile.DevfileCommands ,
389
386
deployment * appsv1.Deployment ,
@@ -396,13 +393,13 @@ func (a *Adapter) createOrUpdateComponent(
396
393
path = filepath .Dir (devfilePath )
397
394
)
398
395
399
- runtime := component .GetComponentRuntimeFromDevfileMetadata (a . devfile .Data .GetMetadata ())
396
+ runtime := component .GetComponentRuntimeFromDevfileMetadata (parameters . Devfile .Data .GetMetadata ())
400
397
401
398
// Set the labels
402
399
labels := odolabels .GetLabels (componentName , appName , runtime , odolabels .ComponentDevMode , true )
403
400
404
401
annotations := make (map [string ]string )
405
- odolabels .SetProjectType (annotations , component .GetComponentTypeFromDevfileMetadata (a . devfile .Data .GetMetadata ()))
402
+ odolabels .SetProjectType (annotations , component .GetComponentTypeFromDevfileMetadata (parameters . Devfile .Data .GetMetadata ()))
406
403
odolabels .AddCommonAnnotations (annotations )
407
404
klog .V (4 ).Infof ("We are deploying these annotations: %s" , annotations )
408
405
@@ -415,7 +412,7 @@ func (a *Adapter) createOrUpdateComponent(
415
412
if err != nil {
416
413
return nil , false , err
417
414
}
418
- podTemplateSpec , err := generator .GetPodTemplateSpec (a . devfile , generator.PodTemplateParams {
415
+ podTemplateSpec , err := generator .GetPodTemplateSpec (parameters . Devfile , generator.PodTemplateParams {
419
416
ObjectMeta : deploymentObjectMeta ,
420
417
PodSecurityAdmissionPolicy : policy ,
421
418
})
@@ -429,13 +426,13 @@ func (a *Adapter) createOrUpdateComponent(
429
426
430
427
initContainers := podTemplateSpec .Spec .InitContainers
431
428
432
- containers , err = utils .UpdateContainersEntrypointsIfNeeded (a . devfile , containers , commands .BuildCmd , commands .RunCmd , commands .DebugCmd )
429
+ containers , err = utils .UpdateContainersEntrypointsIfNeeded (parameters . Devfile , containers , commands .BuildCmd , commands .RunCmd , commands .DebugCmd )
433
430
if err != nil {
434
431
return nil , false , err
435
432
}
436
433
437
434
// Returns the volumes to add to the PodTemplate and adds volumeMounts to the containers and initContainers
438
- volumes , err := a .buildVolumes (ctx , containers , initContainers )
435
+ volumes , err := a .buildVolumes (ctx , parameters , containers , initContainers )
439
436
if err != nil {
440
437
return nil , false , err
441
438
}
@@ -459,7 +456,7 @@ func (a *Adapter) createOrUpdateComponent(
459
456
originalGeneration = deployment .GetGeneration ()
460
457
}
461
458
462
- deployment , err = generator .GetDeployment (a . devfile , deployParams )
459
+ deployment , err = generator .GetDeployment (parameters . Devfile , deployParams )
463
460
if err != nil {
464
461
return nil , false , err
465
462
}
@@ -485,7 +482,7 @@ func (a *Adapter) createOrUpdateComponent(
485
482
ObjectMeta : serviceObjectMeta ,
486
483
SelectorLabels : selectorLabels ,
487
484
}
488
- svc , err := generator .GetService (a . devfile , serviceParams , parsercommon.DevfileOptions {})
485
+ svc , err := generator .GetService (parameters . Devfile , serviceParams , parsercommon.DevfileOptions {})
489
486
490
487
if err != nil {
491
488
return nil , false , err
@@ -549,13 +546,13 @@ func (a *Adapter) createOrUpdateComponent(
549
546
// - (side effect on input parameters) adds volumeMounts to containers and initContainers for the PVCs and Ephemeral volumes
550
547
// - (side effect on input parameters) adds volumeMounts for automounted volumes
551
548
// => Returns the list of Volumes to add to the PodTemplate
552
- func (a * Adapter ) buildVolumes (ctx context.Context , containers , initContainers []corev1.Container ) ([]corev1.Volume , error ) {
549
+ func (a * Adapter ) buildVolumes (ctx context.Context , parameters adapters. PushParameters , containers , initContainers []corev1.Container ) ([]corev1.Volume , error ) {
553
550
var (
554
551
appName = odocontext .GetApplication (ctx )
555
552
componentName = odocontext .GetComponentName (ctx )
556
553
)
557
554
558
- runtime := component .GetComponentRuntimeFromDevfileMetadata (a . devfile .Data .GetMetadata ())
555
+ runtime := component .GetComponentRuntimeFromDevfileMetadata (parameters . Devfile .Data .GetMetadata ())
559
556
560
557
storageClient := storagepkg .NewClient (componentName , appName , storagepkg.ClientOptions {
561
558
Client : a .kubeClient ,
@@ -570,7 +567,7 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [
570
567
571
568
// Create PVCs for non-ephemeral Volumes defined in the Devfile
572
569
// and returns the Ephemeral volumes defined in the Devfile
573
- ephemerals , err := storagepkg .Push (storageClient , a . devfile )
570
+ ephemerals , err := storagepkg .Push (storageClient , parameters . Devfile )
574
571
if err != nil {
575
572
return nil , err
576
573
}
@@ -600,13 +597,13 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [
600
597
utils .AddOdoMandatoryVolume (containers )
601
598
602
599
// Get PVC volumes and Volume Mounts
603
- pvcVolumes , err := storage .GetPersistentVolumesAndVolumeMounts (a . devfile , containers , initContainers , volumeNameToVolInfo , parsercommon.DevfileOptions {})
600
+ pvcVolumes , err := storage .GetPersistentVolumesAndVolumeMounts (parameters . Devfile , containers , initContainers , volumeNameToVolInfo , parsercommon.DevfileOptions {})
604
601
if err != nil {
605
602
return nil , err
606
603
}
607
604
allVolumes = append (allVolumes , pvcVolumes ... )
608
605
609
- ephemeralVolumes , err := storage .GetEphemeralVolumesAndVolumeMounts (a . devfile , containers , initContainers , ephemerals , parsercommon.DevfileOptions {})
606
+ ephemeralVolumes , err := storage .GetEphemeralVolumesAndVolumeMounts (parameters . Devfile , containers , initContainers , ephemerals , parsercommon.DevfileOptions {})
610
607
if err != nil {
611
608
return nil , err
612
609
}
@@ -682,7 +679,7 @@ func (a Adapter) generateDeploymentObjectMeta(ctx context.Context, deployment *a
682
679
// getRemoteResourcesNotPresentInDevfile compares the list of Devfile K8s component and remote K8s resources
683
680
// and returns a list of the remote resources not present in the Devfile and in case the SBO is not installed, a list of service binding secrets that must be deleted;
684
681
// it ignores the core components (such as deployments, svc, pods; all resources with `component:<something>` label)
685
- func (a Adapter ) getRemoteResourcesNotPresentInDevfile (ctx context.Context , selector string ) (objectsToRemove , serviceBindingSecretsToRemove []unstructured.Unstructured , err error ) {
682
+ func (a Adapter ) getRemoteResourcesNotPresentInDevfile (ctx context.Context , parameters adapters. PushParameters , selector string ) (objectsToRemove , serviceBindingSecretsToRemove []unstructured.Unstructured , err error ) {
686
683
var (
687
684
devfilePath = odocontext .GetDevfilePath (ctx )
688
685
path = filepath .Dir (devfilePath )
@@ -710,7 +707,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele
710
707
}
711
708
712
709
var devfileK8sResources []devfilev1.Component
713
- devfileK8sResources , err = libdevfile .GetK8sAndOcComponentsToPush (a . devfile , true )
710
+ devfileK8sResources , err = libdevfile .GetK8sAndOcComponentsToPush (parameters . Devfile , true )
714
711
if err != nil {
715
712
return nil , nil , fmt .Errorf ("unable to obtain resources from the Devfile: %w" , err )
716
713
}
@@ -719,7 +716,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele
719
716
var devfileK8sResourcesUnstructured []unstructured.Unstructured
720
717
for _ , devfileK := range devfileK8sResources {
721
718
var devfileKUnstructuredList []unstructured.Unstructured
722
- devfileKUnstructuredList , err = libdevfile .GetK8sComponentAsUnstructuredList (a . devfile , devfileK .Name , path , devfilefs.DefaultFs {})
719
+ devfileKUnstructuredList , err = libdevfile .GetK8sComponentAsUnstructuredList (parameters . Devfile , devfileK .Name , path , devfilefs.DefaultFs {})
723
720
if err != nil {
724
721
return nil , nil , fmt .Errorf ("unable to read the resource: %w" , err )
725
722
}
0 commit comments