From aff78e7056c540ee90539fb260e10b499e2dc481 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Fri, 21 Apr 2023 11:40:56 +0200 Subject: [PATCH] Move Devfile param to WatchParams and biuld adapter only once --- pkg/dev/kubedev/kubedev.go | 58 ++++++----------- .../adapters/kubernetes/component/adapter.go | 65 +++++++++---------- .../kubernetes/component/adapter_test.go | 9 ++- .../adapters/kubernetes/component/push.go | 13 ++-- pkg/devfile/adapters/types.go | 5 +- 5 files changed, 70 insertions(+), 80 deletions(-) diff --git a/pkg/dev/kubedev/kubedev.go b/pkg/dev/kubedev/kubedev.go index 678a653f511..a18e03e7744 100644 --- a/pkg/dev/kubedev/kubedev.go +++ b/pkg/dev/kubedev/kubedev.go @@ -46,6 +46,8 @@ type DevClient struct { execClient exec.Client deleteClient _delete.Client configAutomountClient configAutomount.Client + + adapter component.Adapter } var _ dev.Client = (*DevClient)(nil) @@ -62,6 +64,17 @@ func NewDevClient( deleteClient _delete.Client, configAutomountClient configAutomount.Client, ) *DevClient { + adapter := component.NewKubernetesAdapter( + kubernetesClient, + prefClient, + portForwardClient, + bindingClient, + syncClient, + execClient, + configAutomountClient, + filesystem, + ) + return &DevClient{ kubernetesClient: kubernetesClient, prefClient: prefClient, @@ -73,6 +86,7 @@ func NewDevClient( execClient: execClient, deleteClient: deleteClient, configAutomountClient: configAutomountClient, + adapter: adapter, } } @@ -88,18 +102,6 @@ func (o *DevClient) Start( devfileObj = odocontext.GetDevfileObj(ctx) ) - adapter := component.NewKubernetesAdapter( - o.kubernetesClient, - o.prefClient, - o.portForwardClient, - o.bindingClient, - o.syncClient, - o.execClient, - o.configAutomountClient, - o.filesystem, - *devfileObj, - ) - pushParameters := adapters.PushParameters{ IgnoredFiles: options.IgnorePaths, Debug: options.Debug, @@ -108,13 +110,14 @@ func (o *DevClient) Start( RandomPorts: options.RandomPorts, CustomForwardedPorts: options.CustomForwardedPorts, ErrOut: errOut, + Devfile: *devfileObj, } klog.V(4).Infoln("Creating inner-loop resources for the component") componentStatus := watch.ComponentStatus{ ImageComponentsAutoApplied: make(map[string]v1alpha2.ImageComponent), } - err := adapter.Push(ctx, pushParameters, &componentStatus) + err := o.adapter.Push(ctx, pushParameters, &componentStatus) if err != nil { return err } @@ -138,38 +141,19 @@ func (o *DevClient) Start( return o.watchClient.WatchAndPush(out, watchParameters, ctx, componentStatus) } -// RegenerateAdapterAndPush regenerates the adapter and pushes the files to remote pod +// RegenerateAdapterAndPush get the new devfile and pushes the files to remote pod func (o *DevClient) regenerateAdapterAndPush(ctx context.Context, pushParams adapters.PushParameters, watchParams watch.WatchParameters, componentStatus *watch.ComponentStatus) error { - var adapter component.ComponentAdapter - adapter, err := o.regenerateComponentAdapterFromWatchParams(watchParams) + devObj, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(""), watchParams.Variables) if err != nil { return fmt.Errorf("unable to generate component from watch parameters: %w", err) } - err = adapter.Push(ctx, pushParams, componentStatus) + pushParams.Devfile = devObj + + err = o.adapter.Push(ctx, pushParams, componentStatus) if err != nil { return fmt.Errorf("watch command was unable to push component: %w", err) } - return nil } - -func (o *DevClient) regenerateComponentAdapterFromWatchParams(parameters watch.WatchParameters) (component.ComponentAdapter, error) { - devObj, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(""), parameters.Variables) - if err != nil { - return nil, err - } - - return component.NewKubernetesAdapter( - o.kubernetesClient, - o.prefClient, - o.portForwardClient, - o.bindingClient, - o.syncClient, - o.execClient, - o.configAutomountClient, - o.filesystem, - devObj, - ), nil -} diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index e4497603eea..d2fda4a7cb4 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -41,7 +41,6 @@ import ( devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/devfile/library/v2/pkg/devfile/generator" - "github.com/devfile/library/v2/pkg/devfile/parser" parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common" dfutil "github.com/devfile/library/v2/pkg/util" @@ -62,8 +61,8 @@ type Adapter struct { configAutomountClient configAutomount.Client fs filesystem.Filesystem // FS is the object used for building image component if present - devfile parser.DevfileObj // Devfile is the object returned by the Devfile parser - logger machineoutput.MachineEventLoggingClient + //devfile parser.DevfileObj // Devfile is the object returned by the Devfile parser + logger machineoutput.MachineEventLoggingClient } var _ ComponentAdapter = (*Adapter)(nil) @@ -78,7 +77,7 @@ func NewKubernetesAdapter( execClient exec.Client, configAutomountClient configAutomount.Client, fs filesystem.Filesystem, - devfile parser.DevfileObj, + // devfile parser.DevfileObj, ) Adapter { return Adapter{ kubeClient: kubernetesClient, @@ -89,7 +88,6 @@ func NewKubernetesAdapter( execClient: execClient, configAutomountClient: configAutomountClient, fs: fs, - devfile: devfile, logger: machineoutput.NewMachineEventLoggingClient(), } @@ -124,7 +122,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c } klog.V(4).Infof("component state: %q\n", componentStatus.State) - err = a.buildPushAutoImageComponents(ctx, a.fs, a.devfile, componentStatus) + err = a.buildPushAutoImageComponents(ctx, a.fs, parameters.Devfile, componentStatus) if err != nil { return err } @@ -139,11 +137,11 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c } // Set the mode to Dev since we are using "odo dev" here - runtime := component.GetComponentRuntimeFromDevfileMetadata(a.devfile.Data.GetMetadata()) + runtime := component.GetComponentRuntimeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata()) labels := odolabels.GetLabels(componentName, appName, runtime, odolabels.ComponentDevMode, false) var updated bool - deployment, updated, err = a.createOrUpdateComponent(ctx, deploymentExists, libdevfile.DevfileCommands{ + deployment, updated, err = a.createOrUpdateComponent(ctx, parameters, deploymentExists, libdevfile.DevfileCommands{ BuildCmd: parameters.DevfileBuildCmd, RunCmd: parameters.DevfileRunCmd, DebugCmd: parameters.DevfileDebugCmd, @@ -156,7 +154,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c // Delete remote resources that are not present in the Devfile selector := odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false) - objectsToRemove, serviceBindingSecretsToRemove, err := a.getRemoteResourcesNotPresentInDevfile(ctx, selector) + objectsToRemove, serviceBindingSecretsToRemove, err := a.getRemoteResourcesNotPresentInDevfile(ctx, parameters, selector) if err != nil { return fmt.Errorf("unable to determine resources to delete: %w", err) } @@ -176,7 +174,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c } // Create all the K8s components defined in the devfile - _, err = a.pushDevfileKubernetesComponents(ctx, labels, odolabels.ComponentDevMode, ownerReference) + _, err = a.pushDevfileKubernetesComponents(ctx, parameters, labels, odolabels.ComponentDevMode, ownerReference) if err != nil { return err } @@ -210,7 +208,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c } // Check if endpoints changed in Devfile - portsToForward, err := libdevfile.GetDevfileContainerEndpointMapping(a.devfile, parameters.Debug) + portsToForward, err := libdevfile.GetDevfileContainerEndpointMapping(parameters.Devfile, parameters.Debug) if err != nil { return err } @@ -280,15 +278,15 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c // PostStart events from the devfile will only be executed when the component // didn't previously exist - if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(a.devfile) { - err = libdevfile.ExecPostStartEvents(ctx, a.devfile, component.NewExecHandler(a.kubeClient, a.execClient, appName, componentName, pod.Name, "Executing post-start command in container", parameters.Show)) + if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(parameters.Devfile) { + err = libdevfile.ExecPostStartEvents(ctx, parameters.Devfile, component.NewExecHandler(a.kubeClient, a.execClient, appName, componentName, pod.Name, "Executing post-start command in container", parameters.Show)) if err != nil { return err } } componentStatus.PostStartEventsDone = true - cmd, err := libdevfile.ValidateAndGetCommand(a.devfile, cmdName, cmdKind) + cmd, err := libdevfile.ValidateAndGetCommand(parameters.Devfile, cmdName, cmdKind) if err != nil { return err } @@ -305,7 +303,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c kubeClient: a.kubeClient, appName: appName, componentName: componentName, - devfile: a.devfile, + devfile: parameters.Devfile, path: path, podName: pod.GetName(), ctx: ctx, @@ -336,7 +334,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c doExecuteBuildCommand := func() error { execHandler := component.NewExecHandler(a.kubeClient, a.execClient, appName, componentName, pod.Name, "Building your application in container", parameters.Show) - return libdevfile.Build(ctx, a.devfile, parameters.DevfileBuildCmd, execHandler) + return libdevfile.Build(ctx, parameters.Devfile, parameters.DevfileBuildCmd, execHandler) } if running { if cmd.Exec == nil || !util.SafeGetBool(cmd.Exec.HotReloadCapable) { @@ -349,7 +347,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c return err } } - err = libdevfile.ExecuteCommandByNameAndKind(ctx, a.devfile, cmdName, cmdKind, &cmdHandler, false) + err = libdevfile.ExecuteCommandByNameAndKind(ctx, parameters.Devfile, cmdName, cmdKind, &cmdHandler, false) if err != nil { return err } @@ -369,7 +367,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c fmt.Fprintln(log.GetStdout()) } - err = a.portForwardClient.StartPortForwarding(ctx, a.devfile, componentName, parameters.Debug, parameters.RandomPorts, log.GetStdout(), parameters.ErrOut, parameters.CustomForwardedPorts) + err = a.portForwardClient.StartPortForwarding(ctx, parameters.Devfile, componentName, parameters.Debug, parameters.RandomPorts, log.GetStdout(), parameters.ErrOut, parameters.CustomForwardedPorts) if err != nil { return adapters.NewErrPortForward(err) } @@ -384,6 +382,7 @@ func (a Adapter) Push(ctx context.Context, parameters adapters.PushParameters, c // Returns the new deployment and if the generation of the deployment has been updated func (a *Adapter) createOrUpdateComponent( ctx context.Context, + parameters adapters.PushParameters, componentExists bool, commands libdevfile.DevfileCommands, deployment *appsv1.Deployment, @@ -396,13 +395,13 @@ func (a *Adapter) createOrUpdateComponent( path = filepath.Dir(devfilePath) ) - runtime := component.GetComponentRuntimeFromDevfileMetadata(a.devfile.Data.GetMetadata()) + runtime := component.GetComponentRuntimeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata()) // Set the labels labels := odolabels.GetLabels(componentName, appName, runtime, odolabels.ComponentDevMode, true) annotations := make(map[string]string) - odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(a.devfile.Data.GetMetadata())) + odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata())) odolabels.AddCommonAnnotations(annotations) klog.V(4).Infof("We are deploying these annotations: %s", annotations) @@ -415,7 +414,7 @@ func (a *Adapter) createOrUpdateComponent( if err != nil { return nil, false, err } - podTemplateSpec, err := generator.GetPodTemplateSpec(a.devfile, generator.PodTemplateParams{ + podTemplateSpec, err := generator.GetPodTemplateSpec(parameters.Devfile, generator.PodTemplateParams{ ObjectMeta: deploymentObjectMeta, PodSecurityAdmissionPolicy: policy, }) @@ -429,13 +428,13 @@ func (a *Adapter) createOrUpdateComponent( initContainers := podTemplateSpec.Spec.InitContainers - containers, err = utils.UpdateContainersEntrypointsIfNeeded(a.devfile, containers, commands.BuildCmd, commands.RunCmd, commands.DebugCmd) + containers, err = utils.UpdateContainersEntrypointsIfNeeded(parameters.Devfile, containers, commands.BuildCmd, commands.RunCmd, commands.DebugCmd) if err != nil { return nil, false, err } // Returns the volumes to add to the PodTemplate and adds volumeMounts to the containers and initContainers - volumes, err := a.buildVolumes(ctx, containers, initContainers) + volumes, err := a.buildVolumes(ctx, parameters, containers, initContainers) if err != nil { return nil, false, err } @@ -459,7 +458,7 @@ func (a *Adapter) createOrUpdateComponent( originalGeneration = deployment.GetGeneration() } - deployment, err = generator.GetDeployment(a.devfile, deployParams) + deployment, err = generator.GetDeployment(parameters.Devfile, deployParams) if err != nil { return nil, false, err } @@ -485,7 +484,7 @@ func (a *Adapter) createOrUpdateComponent( ObjectMeta: serviceObjectMeta, SelectorLabels: selectorLabels, } - svc, err := generator.GetService(a.devfile, serviceParams, parsercommon.DevfileOptions{}) + svc, err := generator.GetService(parameters.Devfile, serviceParams, parsercommon.DevfileOptions{}) if err != nil { return nil, false, err @@ -549,13 +548,13 @@ func (a *Adapter) createOrUpdateComponent( // - (side effect on input parameters) adds volumeMounts to containers and initContainers for the PVCs and Ephemeral volumes // - (side effect on input parameters) adds volumeMounts for automounted volumes // => Returns the list of Volumes to add to the PodTemplate -func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers []corev1.Container) ([]corev1.Volume, error) { +func (a *Adapter) buildVolumes(ctx context.Context, parameters adapters.PushParameters, containers, initContainers []corev1.Container) ([]corev1.Volume, error) { var ( appName = odocontext.GetApplication(ctx) componentName = odocontext.GetComponentName(ctx) ) - runtime := component.GetComponentRuntimeFromDevfileMetadata(a.devfile.Data.GetMetadata()) + runtime := component.GetComponentRuntimeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata()) storageClient := storagepkg.NewClient(componentName, appName, storagepkg.ClientOptions{ Client: a.kubeClient, @@ -570,7 +569,7 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [ // Create PVCs for non-ephemeral Volumes defined in the Devfile // and returns the Ephemeral volumes defined in the Devfile - ephemerals, err := storagepkg.Push(storageClient, a.devfile) + ephemerals, err := storagepkg.Push(storageClient, parameters.Devfile) if err != nil { return nil, err } @@ -600,13 +599,13 @@ func (a *Adapter) buildVolumes(ctx context.Context, containers, initContainers [ utils.AddOdoMandatoryVolume(containers) // Get PVC volumes and Volume Mounts - pvcVolumes, err := storage.GetPersistentVolumesAndVolumeMounts(a.devfile, containers, initContainers, volumeNameToVolInfo, parsercommon.DevfileOptions{}) + pvcVolumes, err := storage.GetPersistentVolumesAndVolumeMounts(parameters.Devfile, containers, initContainers, volumeNameToVolInfo, parsercommon.DevfileOptions{}) if err != nil { return nil, err } allVolumes = append(allVolumes, pvcVolumes...) - ephemeralVolumes, err := storage.GetEphemeralVolumesAndVolumeMounts(a.devfile, containers, initContainers, ephemerals, parsercommon.DevfileOptions{}) + ephemeralVolumes, err := storage.GetEphemeralVolumesAndVolumeMounts(parameters.Devfile, containers, initContainers, ephemerals, parsercommon.DevfileOptions{}) if err != nil { return nil, err } @@ -682,7 +681,7 @@ func (a Adapter) generateDeploymentObjectMeta(ctx context.Context, deployment *a // getRemoteResourcesNotPresentInDevfile compares the list of Devfile K8s component and remote K8s resources // 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; // it ignores the core components (such as deployments, svc, pods; all resources with `component:` label) -func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, selector string) (objectsToRemove, serviceBindingSecretsToRemove []unstructured.Unstructured, err error) { +func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, parameters adapters.PushParameters, selector string) (objectsToRemove, serviceBindingSecretsToRemove []unstructured.Unstructured, err error) { var ( devfilePath = odocontext.GetDevfilePath(ctx) path = filepath.Dir(devfilePath) @@ -710,7 +709,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele } var devfileK8sResources []devfilev1.Component - devfileK8sResources, err = libdevfile.GetK8sAndOcComponentsToPush(a.devfile, true) + devfileK8sResources, err = libdevfile.GetK8sAndOcComponentsToPush(parameters.Devfile, true) if err != nil { return nil, nil, fmt.Errorf("unable to obtain resources from the Devfile: %w", err) } @@ -719,7 +718,7 @@ func (a Adapter) getRemoteResourcesNotPresentInDevfile(ctx context.Context, sele var devfileK8sResourcesUnstructured []unstructured.Unstructured for _, devfileK := range devfileK8sResources { var devfileKUnstructuredList []unstructured.Unstructured - devfileKUnstructuredList, err = libdevfile.GetK8sComponentAsUnstructuredList(a.devfile, devfileK.Name, path, devfilefs.DefaultFs{}) + devfileKUnstructuredList, err = libdevfile.GetK8sComponentAsUnstructuredList(parameters.Devfile, devfileK.Name, path, devfilefs.DefaultFs{}) if err != nil { return nil, nil, fmt.Errorf("unable to read the resource: %w", err) } diff --git a/pkg/devfile/adapters/kubernetes/component/adapter_test.go b/pkg/devfile/adapters/kubernetes/component/adapter_test.go index 2e26c72b96c..c24f45269e1 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter_test.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter_test.go @@ -14,13 +14,14 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "github.com/redhat-developer/odo/pkg/configAutomount" + "github.com/redhat-developer/odo/pkg/devfile/adapters" "github.com/redhat-developer/odo/pkg/libdevfile" "github.com/redhat-developer/odo/pkg/preference" + "github.com/redhat-developer/odo/pkg/testingutil" "github.com/redhat-developer/odo/pkg/util" devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" devfileParser "github.com/devfile/library/v2/pkg/devfile/parser" - "github.com/devfile/library/v2/pkg/testingutil" "github.com/redhat-developer/odo/pkg/kclient" odolabels "github.com/redhat-developer/odo/pkg/labels" @@ -130,12 +131,14 @@ func TestCreateOrUpdateComponent(t *testing.T) { fakePrefClient.EXPECT().GetEphemeralSourceVolume().AnyTimes() fakeConfigAutomount := configAutomount.NewMockClient(ctrl) fakeConfigAutomount.EXPECT().GetAutomountingVolumes().AnyTimes() - componentAdapter := NewKubernetesAdapter(fkclient, fakePrefClient, nil, nil, nil, nil, fakeConfigAutomount, nil, devObj) + componentAdapter := NewKubernetesAdapter(fkclient, fakePrefClient, nil, nil, nil, nil, fakeConfigAutomount, nil) ctx := context.Background() ctx = odocontext.WithApplication(ctx, "app") ctx = odocontext.WithComponentName(ctx, "my-component") ctx = odocontext.WithDevfilePath(ctx, "/path/to/devfile") - _, _, err := componentAdapter.createOrUpdateComponent(ctx, tt.running, libdevfile.DevfileCommands{}, nil) + _, _, err := componentAdapter.createOrUpdateComponent(ctx, adapters.PushParameters{ + Devfile: devObj, + }, tt.running, libdevfile.DevfileCommands{}, nil) // Checks for unexpected error cases if !tt.wantErr == (err != nil) { diff --git a/pkg/devfile/adapters/kubernetes/component/push.go b/pkg/devfile/adapters/kubernetes/component/push.go index eda541dc1ca..b4ecf1390e5 100644 --- a/pkg/devfile/adapters/kubernetes/component/push.go +++ b/pkg/devfile/adapters/kubernetes/component/push.go @@ -91,6 +91,7 @@ func (a *Adapter) buildPushAutoImageComponents(ctx context.Context, fs filesyste // adding the specified labels and ownerreference to them func (a *Adapter) pushDevfileKubernetesComponents( ctx context.Context, + parameters adapters.PushParameters, labels map[string]string, mode string, reference metav1.OwnerReference, @@ -102,23 +103,23 @@ func (a *Adapter) pushDevfileKubernetesComponents( // fetch the "kubernetes inlined components" to create them on cluster // from odo standpoint, these components contain yaml manifest of ServiceBinding - k8sComponents, err := libdevfile.GetK8sAndOcComponentsToPush(a.devfile, false) + k8sComponents, err := libdevfile.GetK8sAndOcComponentsToPush(parameters.Devfile, false) if err != nil { return nil, fmt.Errorf("error while trying to fetch service(s) from devfile: %w", err) } // validate if the GVRs represented by Kubernetes inlined components are supported by the underlying cluster - err = component.ValidateResourcesExist(a.kubeClient, a.devfile, k8sComponents, path) + err = component.ValidateResourcesExist(a.kubeClient, parameters.Devfile, k8sComponents, path) if err != nil { return nil, err } // Set the annotations for the component type annotations := make(map[string]string) - odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(a.devfile.Data.GetMetadata())) + odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(parameters.Devfile.Data.GetMetadata())) // create the Kubernetes objects from the manifest and delete the ones not in the devfile - err = service.PushKubernetesResources(a.kubeClient, a.devfile, k8sComponents, labels, annotations, path, mode, reference) + err = service.PushKubernetesResources(a.kubeClient, parameters.Devfile, k8sComponents, labels, annotations, path, mode, reference) if err != nil { return nil, fmt.Errorf("failed to create Kubernetes resources associated with the component: %w", err) } @@ -126,13 +127,13 @@ func (a *Adapter) pushDevfileKubernetesComponents( } func (a *Adapter) getPushDevfileCommands(parameters adapters.PushParameters) (map[devfilev1.CommandGroupKind]devfilev1.Command, error) { - pushDevfileCommands, err := libdevfile.ValidateAndGetPushCommands(a.devfile, parameters.DevfileBuildCmd, parameters.DevfileRunCmd) + pushDevfileCommands, err := libdevfile.ValidateAndGetPushCommands(parameters.Devfile, parameters.DevfileBuildCmd, parameters.DevfileRunCmd) if err != nil { return nil, fmt.Errorf("failed to validate devfile build and run commands: %w", err) } if parameters.Debug { - pushDevfileDebugCommands, e := libdevfile.ValidateAndGetCommand(a.devfile, parameters.DevfileDebugCmd, devfilev1.DebugCommandGroupKind) + pushDevfileDebugCommands, e := libdevfile.ValidateAndGetCommand(parameters.Devfile, parameters.DevfileDebugCmd, devfilev1.DebugCommandGroupKind) if e != nil { return nil, fmt.Errorf("debug command is not valid: %w", e) } diff --git a/pkg/devfile/adapters/types.go b/pkg/devfile/adapters/types.go index 51b43c8891e..9f19edc1882 100644 --- a/pkg/devfile/adapters/types.go +++ b/pkg/devfile/adapters/types.go @@ -1,12 +1,15 @@ package adapters import ( - "github.com/redhat-developer/odo/pkg/api" "io" + + "github.com/devfile/library/v2/pkg/devfile/parser" + "github.com/redhat-developer/odo/pkg/api" ) // PushParameters is a struct containing the parameters to be used when pushing to a devfile component type PushParameters struct { + Devfile parser.DevfileObj 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 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 IgnoredFiles []string // IgnoredFiles is the list of files to not push up to a component