Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6617dba

Browse files
committedApr 21, 2023
Move Devfile param to WatchParams and biuld adapter only once
1 parent 8170cfb commit 6617dba

File tree

5 files changed

+68
-80
lines changed

5 files changed

+68
-80
lines changed
 

‎pkg/dev/kubedev/kubedev.go

+21-37
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type DevClient struct {
4646
execClient exec.Client
4747
deleteClient _delete.Client
4848
configAutomountClient configAutomount.Client
49+
50+
adapter component.Adapter
4951
}
5052

5153
var _ dev.Client = (*DevClient)(nil)
@@ -62,6 +64,17 @@ func NewDevClient(
6264
deleteClient _delete.Client,
6365
configAutomountClient configAutomount.Client,
6466
) *DevClient {
67+
adapter := component.NewKubernetesAdapter(
68+
kubernetesClient,
69+
prefClient,
70+
portForwardClient,
71+
bindingClient,
72+
syncClient,
73+
execClient,
74+
configAutomountClient,
75+
filesystem,
76+
)
77+
6578
return &DevClient{
6679
kubernetesClient: kubernetesClient,
6780
prefClient: prefClient,
@@ -73,6 +86,7 @@ func NewDevClient(
7386
execClient: execClient,
7487
deleteClient: deleteClient,
7588
configAutomountClient: configAutomountClient,
89+
adapter: adapter,
7690
}
7791
}
7892

@@ -88,18 +102,6 @@ func (o *DevClient) Start(
88102
devfileObj = odocontext.GetDevfileObj(ctx)
89103
)
90104

91-
adapter := component.NewKubernetesAdapter(
92-
o.kubernetesClient,
93-
o.prefClient,
94-
o.portForwardClient,
95-
o.bindingClient,
96-
o.syncClient,
97-
o.execClient,
98-
o.configAutomountClient,
99-
o.filesystem,
100-
*devfileObj,
101-
)
102-
103105
pushParameters := adapters.PushParameters{
104106
IgnoredFiles: options.IgnorePaths,
105107
Debug: options.Debug,
@@ -108,13 +110,14 @@ func (o *DevClient) Start(
108110
RandomPorts: options.RandomPorts,
109111
CustomForwardedPorts: options.CustomForwardedPorts,
110112
ErrOut: errOut,
113+
Devfile: *devfileObj,
111114
}
112115

113116
klog.V(4).Infoln("Creating inner-loop resources for the component")
114117
componentStatus := watch.ComponentStatus{
115118
ImageComponentsAutoApplied: make(map[string]v1alpha2.ImageComponent),
116119
}
117-
err := adapter.Push(ctx, pushParameters, &componentStatus)
120+
err := o.adapter.Push(ctx, pushParameters, &componentStatus)
118121
if err != nil {
119122
return err
120123
}
@@ -138,38 +141,19 @@ func (o *DevClient) Start(
138141
return o.watchClient.WatchAndPush(out, watchParameters, ctx, componentStatus)
139142
}
140143

141-
// RegenerateAdapterAndPush regenerates the adapter and pushes the files to remote pod
144+
// RegenerateAdapterAndPush get the new devfile and pushes the files to remote pod
142145
func (o *DevClient) regenerateAdapterAndPush(ctx context.Context, pushParams adapters.PushParameters, watchParams watch.WatchParameters, componentStatus *watch.ComponentStatus) error {
143-
var adapter component.ComponentAdapter
144146

145-
adapter, err := o.regenerateComponentAdapterFromWatchParams(watchParams)
147+
devObj, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(""), watchParams.Variables)
146148
if err != nil {
147149
return fmt.Errorf("unable to generate component from watch parameters: %w", err)
148150
}
149151

150-
err = adapter.Push(ctx, pushParams, componentStatus)
152+
pushParams.Devfile = devObj
153+
154+
err = o.adapter.Push(ctx, pushParams, componentStatus)
151155
if err != nil {
152156
return fmt.Errorf("watch command was unable to push component: %w", err)
153157
}
154-
155158
return nil
156159
}
157-
158-
func (o *DevClient) regenerateComponentAdapterFromWatchParams(parameters watch.WatchParameters) (component.ComponentAdapter, error) {
159-
devObj, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(""), parameters.Variables)
160-
if err != nil {
161-
return nil, err
162-
}
163-
164-
return component.NewKubernetesAdapter(
165-
o.kubernetesClient,
166-
o.prefClient,
167-
o.portForwardClient,
168-
o.bindingClient,
169-
o.syncClient,
170-
o.execClient,
171-
o.configAutomountClient,
172-
o.filesystem,
173-
devObj,
174-
), nil
175-
}

‎pkg/devfile/adapters/kubernetes/component/adapter.go

+30-33
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141

4242
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
4343
"github.com/devfile/library/v2/pkg/devfile/generator"
44-
"github.com/devfile/library/v2/pkg/devfile/parser"
4544
parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
4645
dfutil "github.com/devfile/library/v2/pkg/util"
4746

@@ -62,8 +61,7 @@ type Adapter struct {
6261
configAutomountClient configAutomount.Client
6362
fs filesystem.Filesystem // FS is the object used for building image component if present
6463

65-
devfile parser.DevfileObj // Devfile is the object returned by the Devfile parser
66-
logger machineoutput.MachineEventLoggingClient
64+
logger machineoutput.MachineEventLoggingClient
6765
}
6866

6967
var _ ComponentAdapter = (*Adapter)(nil)
@@ -78,7 +76,6 @@ func NewKubernetesAdapter(
7876
execClient exec.Client,
7977
configAutomountClient configAutomount.Client,
8078
fs filesystem.Filesystem,
81-
devfile parser.DevfileObj,
8279
) Adapter {
8380
return Adapter{
8481
kubeClient: kubernetesClient,
@@ -89,7 +86,6 @@ func NewKubernetesAdapter(
8986
execClient: execClient,
9087
configAutomountClient: configAutomountClient,
9188
fs: fs,
92-
devfile: devfile,
9389

9490
logger: machineoutput.NewMachineEventLoggingClient(),
9591
}
@@ -124,7 +120,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
124120
}
125121

126122
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)
128124
if err != nil {
129125
return err
130126
}
@@ -139,11 +135,11 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
139135
}
140136

141137
// 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())
143139
labels := odolabels.GetLabels(componentName, appName, runtime, odolabels.ComponentDevMode, false)
144140

145141
var updated bool
146-
deployment, updated, err = a.createOrUpdateComponent(ctx, deploymentExists, libdevfile.DevfileCommands{
142+
deployment, updated, err = a.createOrUpdateComponent(ctx, parameters, deploymentExists, libdevfile.DevfileCommands{
147143
BuildCmd: parameters.DevfileBuildCmd,
148144
RunCmd: parameters.DevfileRunCmd,
149145
DebugCmd: parameters.DevfileDebugCmd,
@@ -156,7 +152,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
156152
// Delete remote resources that are not present in the Devfile
157153
selector := odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false)
158154

159-
objectsToRemove, serviceBindingSecretsToRemove, err := a.getRemoteResourcesNotPresentInDevfile(ctx, selector)
155+
objectsToRemove, serviceBindingSecretsToRemove, err := a.getRemoteResourcesNotPresentInDevfile(ctx, parameters, selector)
160156
if err != nil {
161157
return fmt.Errorf("unable to determine resources to delete: %w", err)
162158
}
@@ -176,7 +172,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
176172
}
177173

178174
// 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)
180176
if err != nil {
181177
return err
182178
}
@@ -210,7 +206,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
210206
}
211207

212208
// Check if endpoints changed in Devfile
213-
portsToForward, err := libdevfile.GetDevfileContainerEndpointMapping(a.devfile, parameters.Debug)
209+
portsToForward, err := libdevfile.GetDevfileContainerEndpointMapping(parameters.Devfile, parameters.Debug)
214210
if err != nil {
215211
return err
216212
}
@@ -280,15 +276,15 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
280276

281277
// PostStart events from the devfile will only be executed when the component
282278
// 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))
285281
if err != nil {
286282
return err
287283
}
288284
}
289285
componentStatus.PostStartEventsDone = true
290286

291-
cmd, err := libdevfile.ValidateAndGetCommand(a.devfile, cmdName, cmdKind)
287+
cmd, err := libdevfile.ValidateAndGetCommand(parameters.Devfile, cmdName, cmdKind)
292288
if err != nil {
293289
return err
294290
}
@@ -305,7 +301,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
305301
kubeClient: a.kubeClient,
306302
appName: appName,
307303
componentName: componentName,
308-
devfile: a.devfile,
304+
devfile: parameters.Devfile,
309305
path: path,
310306
podName: pod.GetName(),
311307
ctx: ctx,
@@ -336,7 +332,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
336332
doExecuteBuildCommand := func() error {
337333
execHandler := component.NewExecHandler(a.kubeClient, a.execClient, appName, componentName, pod.Name,
338334
"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)
340336
}
341337
if running {
342338
if cmd.Exec == nil || !util.SafeGetBool(cmd.Exec.HotReloadCapable) {
@@ -349,7 +345,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
349345
return err
350346
}
351347
}
352-
err = libdevfile.ExecuteCommandByNameAndKind(ctx, a.devfile, cmdName, cmdKind, &cmdHandler, false)
348+
err = libdevfile.ExecuteCommandByNameAndKind(ctx, parameters.Devfile, cmdName, cmdKind, &cmdHandler, false)
353349
if err != nil {
354350
return err
355351
}
@@ -369,7 +365,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
369365
fmt.Fprintln(log.GetStdout())
370366
}
371367

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)
373369
if err != nil {
374370
return adapters.NewErrPortForward(err)
375371
}
@@ -384,6 +380,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c
384380
// Returns the new deployment and if the generation of the deployment has been updated
385381
func (a *Adapter) createOrUpdateComponent(
386382
ctx context.Context,
383+
parameters adapters.PushParameters,
387384
componentExists bool,
388385
commands libdevfile.DevfileCommands,
389386
deployment *appsv1.Deployment,
@@ -396,13 +393,13 @@ func (a *Adapter) createOrUpdateComponent(
396393
path = filepath.Dir(devfilePath)
397394
)
398395

399-
runtime := component.GetComponentRuntimeFromDevfileMetadata(a.devfile.Data.GetMetadata())
396+
runtime := component.GetComponentRuntimeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata())
400397

401398
// Set the labels
402399
labels := odolabels.GetLabels(componentName, appName, runtime, odolabels.ComponentDevMode, true)
403400

404401
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()))
406403
odolabels.AddCommonAnnotations(annotations)
407404
klog.V(4).Infof("We are deploying these annotations: %s", annotations)
408405

@@ -415,7 +412,7 @@ func (a *Adapter) createOrUpdateComponent(
415412
if err != nil {
416413
return nil, false, err
417414
}
418-
podTemplateSpec, err := generator.GetPodTemplateSpec(a.devfile, generator.PodTemplateParams{
415+
podTemplateSpec, err := generator.GetPodTemplateSpec(parameters.Devfile, generator.PodTemplateParams{
419416
ObjectMeta: deploymentObjectMeta,
420417
PodSecurityAdmissionPolicy: policy,
421418
})
@@ -429,13 +426,13 @@ func (a *Adapter) createOrUpdateComponent(
429426

430427
initContainers := podTemplateSpec.Spec.InitContainers
431428

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)
433430
if err != nil {
434431
return nil, false, err
435432
}
436433

437434
// 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)
439436
if err != nil {
440437
return nil, false, err
441438
}
@@ -459,7 +456,7 @@ func (a *Adapter) createOrUpdateComponent(
459456
originalGeneration = deployment.GetGeneration()
460457
}
461458

462-
deployment, err = generator.GetDeployment(a.devfile, deployParams)
459+
deployment, err = generator.GetDeployment(parameters.Devfile, deployParams)
463460
if err != nil {
464461
return nil, false, err
465462
}
@@ -485,7 +482,7 @@ func (a *Adapter) createOrUpdateComponent(
485482
ObjectMeta: serviceObjectMeta,
486483
SelectorLabels: selectorLabels,
487484
}
488-
svc, err := generator.GetService(a.devfile, serviceParams, parsercommon.DevfileOptions{})
485+
svc, err := generator.GetService(parameters.Devfile, serviceParams, parsercommon.DevfileOptions{})
489486

490487
if err != nil {
491488
return nil, false, err
@@ -549,13 +546,13 @@ func (a *Adapter) createOrUpdateComponent(
549546
// - (side effect on input parameters) adds volumeMounts to containers and initContainers for the PVCs and Ephemeral volumes
550547
// - (side effect on input parameters) adds volumeMounts for automounted volumes
551548
// => 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) {
553550
var (
554551
appName = odocontext.GetApplication(ctx)
555552
componentName = odocontext.GetComponentName(ctx)
556553
)
557554

558-
runtime := component.GetComponentRuntimeFromDevfileMetadata(a.devfile.Data.GetMetadata())
555+
runtime := component.GetComponentRuntimeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata())
559556

560557
storageClient := storagepkg.NewClient(componentName, appName, storagepkg.ClientOptions{
561558
Client: a.kubeClient,
@@ -570,7 +567,7 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [
570567

571568
// Create PVCs for non-ephemeral Volumes defined in the Devfile
572569
// 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)
574571
if err != nil {
575572
return nil, err
576573
}
@@ -600,13 +597,13 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [
600597
utils.AddOdoMandatoryVolume(containers)
601598

602599
// 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{})
604601
if err != nil {
605602
return nil, err
606603
}
607604
allVolumes = append(allVolumes, pvcVolumes...)
608605

609-
ephemeralVolumes, err := storage.GetEphemeralVolumesAndVolumeMounts(a.devfile, containers, initContainers, ephemerals, parsercommon.DevfileOptions{})
606+
ephemeralVolumes, err := storage.GetEphemeralVolumesAndVolumeMounts(parameters.Devfile, containers, initContainers, ephemerals, parsercommon.DevfileOptions{})
610607
if err != nil {
611608
return nil, err
612609
}
@@ -682,7 +679,7 @@ func (a Adapter) generateDeploymentObjectMeta(ctx context.Context, deployment *a
682679
// getRemoteResourcesNotPresentInDevfile compares the list of Devfile K8s component and remote K8s resources
683680
// 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;
684681
// 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) {
686683
var (
687684
devfilePath = odocontext.GetDevfilePath(ctx)
688685
path = filepath.Dir(devfilePath)
@@ -710,7 +707,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele
710707
}
711708

712709
var devfileK8sResources []devfilev1.Component
713-
devfileK8sResources, err = libdevfile.GetK8sAndOcComponentsToPush(a.devfile, true)
710+
devfileK8sResources, err = libdevfile.GetK8sAndOcComponentsToPush(parameters.Devfile, true)
714711
if err != nil {
715712
return nil, nil, fmt.Errorf("unable to obtain resources from the Devfile: %w", err)
716713
}
@@ -719,7 +716,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele
719716
var devfileK8sResourcesUnstructured []unstructured.Unstructured
720717
for _, devfileK := range devfileK8sResources {
721718
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{})
723720
if err != nil {
724721
return nil, nil, fmt.Errorf("unable to read the resource: %w", err)
725722
}

‎pkg/devfile/adapters/kubernetes/component/adapter_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import (
1414
"k8s.io/apimachinery/pkg/runtime/schema"
1515

1616
"github.com/redhat-developer/odo/pkg/configAutomount"
17+
"github.com/redhat-developer/odo/pkg/devfile/adapters"
1718
"github.com/redhat-developer/odo/pkg/libdevfile"
1819
"github.com/redhat-developer/odo/pkg/preference"
20+
"github.com/redhat-developer/odo/pkg/testingutil"
1921
"github.com/redhat-developer/odo/pkg/util"
2022

2123
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
2224
devfileParser "github.com/devfile/library/v2/pkg/devfile/parser"
23-
"github.com/devfile/library/v2/pkg/testingutil"
2425

2526
"github.com/redhat-developer/odo/pkg/kclient"
2627
odolabels "github.com/redhat-developer/odo/pkg/labels"
@@ -130,12 +131,14 @@ func TestCreateOrUpdateComponent(t *testing.T) {
130131
fakePrefClient.EXPECT().GetEphemeralSourceVolume().AnyTimes()
131132
fakeConfigAutomount := configAutomount.NewMockClient(ctrl)
132133
fakeConfigAutomount.EXPECT().GetAutomountingVolumes().AnyTimes()
133-
componentAdapter := NewKubernetesAdapter(fkclient, fakePrefClient, nil, nil, nil, nil, fakeConfigAutomount, nil, devObj)
134+
componentAdapter := NewKubernetesAdapter(fkclient, fakePrefClient, nil, nil, nil, nil, fakeConfigAutomount, nil)
134135
ctx := context.Background()
135136
ctx = odocontext.WithApplication(ctx, "app")
136137
ctx = odocontext.WithComponentName(ctx, "my-component")
137138
ctx = odocontext.WithDevfilePath(ctx, "/path/to/devfile")
138-
_, _, err := componentAdapter.createOrUpdateComponent(ctx, tt.running, libdevfile.DevfileCommands{}, nil)
139+
_, _, err := componentAdapter.createOrUpdateComponent(ctx, adapters.PushParameters{
140+
Devfile: devObj,
141+
}, tt.running, libdevfile.DevfileCommands{}, nil)
139142

140143
// Checks for unexpected error cases
141144
if !tt.wantErr == (err != nil) {

‎pkg/devfile/adapters/kubernetes/component/push.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (a *Adapter) buildPushAutoImageComponents(ctx context.Context, fs filesyste
9191
// adding the specified labels and ownerreference to them
9292
func (a *Adapter) pushDevfileKubernetesComponents(
9393
ctx context.Context,
94+
parameters adapters.PushParameters,
9495
labels map[string]string,
9596
mode string,
9697
reference metav1.OwnerReference,
@@ -102,37 +103,37 @@ func (a *Adapter) pushDevfileKubernetesComponents(
102103

103104
// fetch the "kubernetes inlined components" to create them on cluster
104105
// from odo standpoint, these components contain yaml manifest of ServiceBinding
105-
k8sComponents, err := libdevfile.GetK8sAndOcComponentsToPush(a.devfile, false)
106+
k8sComponents, err := libdevfile.GetK8sAndOcComponentsToPush(parameters.Devfile, false)
106107
if err != nil {
107108
return nil, fmt.Errorf("error while trying to fetch service(s) from devfile: %w", err)
108109
}
109110

110111
// validate if the GVRs represented by Kubernetes inlined components are supported by the underlying cluster
111-
err = component.ValidateResourcesExist(a.kubeClient, a.devfile, k8sComponents, path)
112+
err = component.ValidateResourcesExist(a.kubeClient, parameters.Devfile, k8sComponents, path)
112113
if err != nil {
113114
return nil, err
114115
}
115116

116117
// Set the annotations for the component type
117118
annotations := make(map[string]string)
118-
odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(a.devfile.Data.GetMetadata()))
119+
odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata()))
119120

120121
// create the Kubernetes objects from the manifest and delete the ones not in the devfile
121-
err = service.PushKubernetesResources(a.kubeClient, a.devfile, k8sComponents, labels, annotations, path, mode, reference)
122+
err = service.PushKubernetesResources(a.kubeClient, parameters.Devfile, k8sComponents, labels, annotations, path, mode, reference)
122123
if err != nil {
123124
return nil, fmt.Errorf("failed to create Kubernetes resources associated with the component: %w", err)
124125
}
125126
return k8sComponents, nil
126127
}
127128

128129
func (a *Adapter) getPushDevfileCommands(parameters adapters.PushParameters) (map[devfilev1.CommandGroupKind]devfilev1.Command, error) {
129-
pushDevfileCommands, err := libdevfile.ValidateAndGetPushCommands(a.devfile, parameters.DevfileBuildCmd, parameters.DevfileRunCmd)
130+
pushDevfileCommands, err := libdevfile.ValidateAndGetPushCommands(parameters.Devfile, parameters.DevfileBuildCmd, parameters.DevfileRunCmd)
130131
if err != nil {
131132
return nil, fmt.Errorf("failed to validate devfile build and run commands: %w", err)
132133
}
133134

134135
if parameters.Debug {
135-
pushDevfileDebugCommands, e := libdevfile.ValidateAndGetCommand(a.devfile, parameters.DevfileDebugCmd, devfilev1.DebugCommandGroupKind)
136+
pushDevfileDebugCommands, e := libdevfile.ValidateAndGetCommand(parameters.Devfile, parameters.DevfileDebugCmd, devfilev1.DebugCommandGroupKind)
136137
if e != nil {
137138
return nil, fmt.Errorf("debug command is not valid: %w", e)
138139
}

‎pkg/devfile/adapters/types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package adapters
22

33
import (
4-
"github.com/redhat-developer/odo/pkg/api"
54
"io"
5+
6+
"github.com/devfile/library/v2/pkg/devfile/parser"
7+
"github.com/redhat-developer/odo/pkg/api"
68
)
79

810
// PushParameters is a struct containing the parameters to be used when pushing to a devfile component
911
type PushParameters struct {
12+
Devfile parser.DevfileObj
1013
WatchFiles []string // Optional: WatchFiles is the list of changed files detected by odo watch. If empty or nil, odo will check .odo/odo-file-index.json to determine changed files
1114
WatchDeletedFiles []string // Optional: WatchDeletedFiles is the list of deleted files detected by odo watch. If empty or nil, odo will check .odo/odo-file-index.json to determine deleted files
1215
IgnoredFiles []string // IgnoredFiles is the list of files to not push up to a component

0 commit comments

Comments
 (0)
Please sign in to comment.