337 Commits

Author SHA1 Message Date
Armel Soro
00d39889b7 Make sure to run parallel commands part of a composite command in parallel (#7075)
* Make sure to run parallel commands part of a composite command in parallel

* Display warnings in case there are errors when executing pre-stop events

* Fix the command_composite_parallel.go implementation by lowering the case of the sub-command names

Since this passed the Devfile validation logic, we should use the same logic as in command_composite.go
2023-09-06 21:15:01 +02:00
Philippe Martin
9605c92ede Remove API Server from experimental mode, set UI Server as experimental (#6985)
* Remove API Server from experimental mode, set UI Server as experimental

* Adapt api-server integration tests

* Disable --api-server by default in the tests

They are enabled only if `options.StartAPIServer`
is explicitly enabled.
This is to avoid potential port conflicting issue,
especially on Windows - see [1]

[1] https://github.com/redhat-developer/odo/issues/6939

* Error out if `--api-server-port` is set but `--api-server` is false

---------

Co-authored-by: Armel Soro <asoro@redhat.com>
2023-07-21 12:11:08 +02:00
Armel Soro
6e725952bd Display information about the running API Server and web UI in odo describe component output (#6964)
* refactor: Set the experimental mode env var in a single place for the '--api-server' related tests

* Add integration tests highlighting the expectations

* Make the state client return the API server ports per platform

'odo dev' might be running on both cluster and podman,
so we might end up with several API servers.

* Make 'odo describe component' return information about the API Server and web UI

This is viewable only when running 'odo describe component'
with the experimental mode enabled.

* fixup! refactor: Set the experimental mode env var in a single place for the '--api-server' related tests

* Unit-test describe#filterByPlatform logic

* Simplify logic for 'describe#filterByPlatform', as suggested in review

Co-authored-by: Philippe Martin <phmartin@redhat.com>

---------

Co-authored-by: Philippe Martin <phmartin@redhat.com>
2023-07-18 16:31:14 +02:00
Armel Soro
4479c24dfe Display list of commands from the local devfile in odo describe component output (#6944)
* Add integration tests highlighting the expectations

* Add and fill a 'Commands' field from the DevfileData struct returned by `describe`

* Display commands in the human-readable output of 'odo describe'

* Add documentation and sample outputs
2023-07-03 10:19:06 -04:00
Philippe Martin
94e32303bd Implement API endpoints (#6915)
* Pass odo context to api server

* Get /instance

* DELETE /instance implementation

* Move describe logic to pkg/component/describe

* Get /component implementation

* POST /component/command implementation

* Fix example by replacing action with name

* Fix integration test

* Integration tests

* Add comment for PushWatcher

* Test DELETE /instance without --no-watch

* Apply suggestions from code review

Co-authored-by: Armel Soro <armel@rm3l.org>

* Return an error if not ready for push

* Fix windows tests

* Fix tests for Windows

---------

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-06-26 16:00:49 +02:00
Philippe Martin
6bc30110ba Display outputs when executing odo run (#6865)
* Change NewRunHandler params with Options

* Pass an options to RunHandler to show logs

* Hide spinner and std output since outputs are displayed

* Integration tests with failing command

* Fix outputs

* use raw terminal and local standard i/o streams

* Fix podman i/o

* Fix stdout/err

* Test if in/out are terminal

* command reference doc
2023-06-12 10:45:31 -04:00
Philippe Martin
330b724753 Add an odo run command to manually execute command during odo dev (#6857)
* Add a run command

* Check command name passed as arg

* Check platform is available

* Add a Run method to the DevClient

* Run command on cluster

* Add test with run command on cluster

* Implement and test run on podman

* Enhance test to check that command has been executed in container

* Fix `odo help` test

* Refactor common code for podman/cluster

* Test Apply commands on Kubernetes/Images

* Test  a msg is displayed when executing odo run without odo dev

* Review

* makes GetRunningPodFromSelector return only Running pods on Podman
2023-06-02 09:33:21 -04:00
Philippe Martin
9a239c4e77 Use a single handler for executing all commands (#6826)
* Document current implementations of command handlers

* Add unit tests for execHAndler

* Refactor pkg/devfile/image to inject Backend as dependency

* Use same handler for kubedev/podmandev

* Fail after SelectBackend==nil only if backend is needed

* Move runHandler to dev/common

* Unit tests for runHandler

* Create a component.ExecuteTerminatingCommand

* ExecuteTerminatingCommand/ExecuteNonTerminatingCommand for Handler

* Fix calling other command types

* Consider parent group to determine if a command is terminating

* Replace component.execHandler by common.runHandler

* Remove execHandler

* Make runHandler and most of fields private and pass containersRunning to handler

* Pass containersRunning value

* deploy using common Handler

* Fix tests

* Use specific Dev/Deploy mode for Apply

* Fix cmdline for job

* Fix unit tests

* Pass appName and componentName with ctx to handler

* Move handler to pkg/component package

* Update doc

* Unit tests Deploy

* Unit tests Build

* Unit tests Run

* Unit tests PostStart

* Unit tests PreStop

* Update doc

* Fix Podman tests

* Fix hotReload on podman

* Change podman version timeout to 30s for tests

* Cleanup + fix doc
2023-05-26 11:01:21 -04:00
Armel Soro
ec747b4ab3 Allow using imageName as a selector (#6768)
* Add integration tests highlighting our expectations

* Bump Devfile library to latest commit

f041d79870

* Expose preference that allows users to globally configure an image registry

* Return the effective Devfile view by default from the initial context

This is supposed to be read-only, so that tools can rely on it
and to the operations they need to perform right away.

Raw Devfile objects can still be obtained upon request
if there is need to update them (for example via 'odo add/remove
binding' commands.

* Pass the image registry preference to the Devfile parser to build the effective view

* Fix 'odo init' integration tests

- The test spec was actually not doing what it was supposed to do
- Now 'odo init' returns a complete Devfile, where the parent is flattened,
  because the goal of 'odo init' is to bootstrap a Devfile.
  Previously, 'odo init' would not download the parent referenced,
  making it hard to understand the resulting Devfile.

* Document how odo now handles relative image names as selectors

* fixup! Document how odo now handles relative image names as selectors

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Revert "Fix 'odo init' integration tests"

This reverts commit 78868b03fd.

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Do not make `odo init` return an effective Devfile as a result

This would change the behavior of `odo init`.

Furthermore, due to an issue [1] in the Devfile library,
it is not possible to parse some Devfiles with parents linked as GitHub URLs (like GitHub release artifacts).

[1] https://github.com/devfile/api/issues/1119

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* fixup! Document how odo now handles relative image names as selectors

---------

Co-authored-by: Philippe Martin <phmartin@redhat.com>
2023-05-22 10:45:27 -04:00
Philippe Martin
56d0b6f95e Fix HotReloadCapable Build command (#6696)
* On cluster, run Build command again only if Build command itself is not hotReloadCapable

* On Podman, execute Build command only if itself is not hotReloadcapable

* Handle hotReloadCapable in handler

* Add integration tests

* Update doc

* review
2023-05-04 10:20:21 -04:00
Armel Soro
4bab9285fb Allow to cancel execution of odo dev at any phase (e.g. if build command is taking long) (#6736)
* Add test cases simulating build or run commands that take very long

* Pass a context around to relevant functions and methods

This will allow to handle cancellations and timeouts and deadlines as needed

* Pass the context to Podman exec command too

* fixup! Add test cases simulating build or run commands that take very long
2023-04-20 17:12:28 +00:00
Philippe Martin
26c90d7c4d Remove podman from experimental mode (#6628)
* Remove podman from experimental mode

* Remove env var for odo dev

* Cleanup tests and sources about experimental mode

* Hide "Experimental mode" doc page

* Cleanup latest commit

* doc odo dev --platform podman

* Doc other commands

* Apply suggestions from code review

Co-authored-by: Armel Soro <armel@rm3l.org>

* Remove more ODO_EXPERIMENTAL_MODE from latest commits on main

* Remove reference to Experimental mode from blog posts

---------

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-03-06 14:17:39 +01:00
Philippe Martin
79504e3663 Describe non-odo component (#6615)
* Do not add odo/app on selector for named describe

* Display route

* Add integration tests

* Fix unit test
2023-02-27 13:41:45 +01:00
Armel Soro
162a193130 Fix UX inconsistency when handling commands bound to events (#6574)
* Do not display the full command-line when handling exec commands and no msg is specified

Displaying it adds a lot of unnecessary clutter.

* Display a shorter message when handling commands bound to 'pre-stop' events

This is to be more consistent with how the other messages are displayed.

* Display a shorter message when handling commands bound to 'post-start' events

This is to be more consistent with how the other messages are displayed.

* Fix integration tests

* fixup! Fix integration tests
2023-02-06 23:13:14 -05:00
Armel Soro
eeda644cc9 Add support for OpenShift Devfile components (#6548)
* Add integration test case

Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Add ApplyOpenShift method to handler

* Test openhift component with odo dev

* Rename GetKubernetesComponentsToPush to GetK8sAndOcComponentsToPush and modify if to obtain both k8s and oc components

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix unit test failures with delete_test

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* update ListClusterResourcesToDeleteFromDevfile to fetch openshift component,Add ListOpenShiftComponents

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* fix testcase 'should have deleted the old resource and created the new resource' and add helper function ReplaceStrings

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* fix debug test to check openshift component

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* Update GetBindingsFromDevfile to include openshift components

* Update offline tests

* Add openshift component to devfiles

* Update tests

* Fix binding tests

* Fix RemoveBinding unit tests

* Handle OpenShift components when removing binding

* odo describe component displaysOpenShift components

* Remove unused function

---------

Signed-off-by: Parthvi Vala <pvala@redhat.com>
Signed-off-by: anandrkskd <anandrkskd@gmail.com>
Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>
Co-authored-by: Parthvi Vala <pvala@redhat.com>
2023-02-03 14:30:24 +01:00
Armel Soro
83d98c2a52 Implement odo delete component --running-in (#6485)
* Add '--running-in' CLI flag to 'odo delete component'

* Use the provided 'running-in' to filter resources candidate for deletion on both cluster and Podman

* Update 'odo delete component' confirmation and success messages to mention the provided value for 'running-in'

* Add unit test cases

* Add integration test cases

* Extract sample outputs from delete-component command reference docs

* Add documentation for the '--running-in' flag
2023-01-23 17:50:22 -05:00
Parthvi Vala
19f8e0ebdb Update devfile/library to support pod-overrides and container-overrides attributes and add integration test for it (#6512)
* Update the Devfile library

* Add test for container-overrides and pod-overrides attributes

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Attempt at fixing CI failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix CI failure

* Attempt at fixing OC integration test failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use random name in integration test

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Rebase and fix integration test failure

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Make integration test work for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Temp attempt at fixing podman test for GH

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Another attempt at fixing CI test for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* One more attempt at fixing integration test for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2023-01-23 15:21:18 -05:00
Philippe Martin
682e5176d2 [podman] show logs when command fails (#6481)
* Implement GetRunningPodFromSelector for podman

* Implement GetPodLogs for podman

* Same message in podman/cluster

* Integration tests

* Return stream of stdout/err
2023-01-16 10:52:07 -05:00
Philippe Martin
ce8fdc1d5b Rename generic run-on flag into platform (#6445)
* Rename pkg/odo/commonflags/run_on.go to pkg/odo/commonflags/platform.go and change runOn to platform

* Rename feature

* Rename into pkg/odo/commonflags/context/

* Update comments

* Update doc

* fix comment

* Update integration tests

* Duplicate runningOn field with platform + deprecated runningOn

* Mark RunningOn as Deprecated

* Do not modify blog post

* Fix typo

* Add exception for SA1019

* odo describe component

* Fix integration tests for odo describe component
2023-01-03 13:51:51 -05:00
Armel Soro
6ed95b7e6f Make odo describe component show information about components running on Podman (#6431)
* Allow using the '--run-on' flag with 'odo describe component'

* Add "platform" to the ForwardedPort output

* Move RunningMode* structs to a dedicated file and add (tested) method for merging running modes

* Add RunningOn field to the Component API

* Make component#GetRunningModes able to return all modes for all specified platforms

* Do not display the namespace from NoComponentFoundError if no namespace is set

* Add more validation logic to the 'describe component' CLI

* Update 'odo describe component' logic for Devfile-based component

* Update 'odo describe component' logic for name-based component

This checks for the component with such name on all platforms.
If it finds several components on both platforms, it needs to extract
Devfile information from those resources.
To do so, it checks if the relevant labels (project type and name) are matching.
It errors out if they do not match, because this would imply that we
don't know what to display as Devfile information.

* Conditionally display "running on" information in human-readable output.

This is displayed only if the "run-on" feature is enabled.

* Implement GetAllResourcesFromSelector in the PodmanCli client

* Add more unit tests

* Update integration tests

* fixup! Update integration tests

* fixup! fixup! Update integration tests
2023-01-02 14:12:58 -05:00
Philippe Martin
451d8106da odo delete component on podman with --name (#6437)
* odo delete component with name

* Add unit test

* Add integration tests

* common printDevfileComponents

* fix name

* spinners + newlines

* Update info message with podman and/or cluster
2023-01-02 05:44:42 -05:00
Philippe Martin
4617cfdfff odo delete component deletes components running on podman (#6418)
* Make odo delete component work without kubeconfig

* Make odo delete component work when non auth

* Support run-on flag

* Do not delete cluster resources when running on podman

* No error when deleting component by name without cluster

* Refacto cleanup pod

* Add PodLs and KubeGenerate methods to pkg/podman

* List and delete Podman Pods

* Add integration tests

* Fix msg + when experimental is disabled

* Review (except UT)

* Add unit test

* restrict platforms earlier
2022-12-22 10:57:35 -05:00
Parthvi Vala
a39931388e Add support for parsing multiple k8s definition in a single Devfile K8s component (#6372)
* Rename GetK8sManifestWithVariablesSubstituted to GetK8sManifestsWithVariablesSubstituted

* Add GetK8sComponentAsUnstructuredList; add support for multiple manifests in a single k8s component

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use GetK8sComponentAsUnstructuredList in binding/remove.go

* Use GetK8sComponentAsUnstructuredList in component/component_test.go

* Use GetK8sComponentAsUnstructuredList in libdevfile/component_kubernetes_utils.go

* Use GetK8sComponentAsUnstructuredList in service/service.go

* Use GetK8sComponentAsUnstructuredList in devfile/adapters/kubernetes/component/adapter.go

* Add documentation for GetK8sComponentAsUnstructuredList and remove GetK8sComponentAsUnstructured

* Fix createOrUpdateServiceForComponent to fetch only the service created for the component

* Add integration test for odo deploy

* Add integration test for odo dev

* Attempt at fixing list/describe binding tests; fixes old mishap

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Check for empty list of binding

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2022-12-07 03:24:02 -05:00
Philippe Martin
0c008c6be9 odo list component shows components running on podman (#6366)
* Enable run-on flag

* List all components

* Select specific platform with --run-on flag

* Make podmanClient nil if no podman client is accessible

* integration test

* Delay the display of warnings related to experimental features

* Add logs displaying podman commands executed

* Use None when Running On is empty

* odo list
2022-12-06 11:01:56 -05:00
Armel Soro
5660093167 Use go-cmp instead of reflect.DeepEqual to compare unit test results (#6343) 2022-11-24 07:24:32 -05:00
Philippe Martin
4c30c8ef0c More tests without cluster (#6303)
* Run build-images command without cluster

* Test odo remove binding without cluster

* Make odo describe component work without cluster

* Tests: configure cluster depending on nocluster label

* Make odo list component work when --namespace is not used

* Test odo list component before deployment without cluster

* Some Generic tests

* Unset KUBERNETES_SERVICE_HOST to disable in-cluster config

* Set KUBECONFIG to empty file for no-cluster tests

* Run no-cluster tests on Windows

* Fix ListIngresses related changes

* Add warning/error when no cluster connection is available
2022-11-21 11:06:04 -05:00
Parthvi Vala
ec503536b7 List Routes/Ingresses created by odo deploy in odo describe component (#6244)
* List routes/ingresses deployed by odo in the describe output

* Remove ListDyanmicResourcesFromSelector and use ListDyanmicResources instead by add a selector argument to it

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Update pkg/api/component.go

Co-authored-by: Armel Soro <armel@rm3l.org>

* Replace DyanmicClient for ingress with a kubeclient

* Show ing/route name if *.hosts is empty

* Change API format

* Ignore owned ing/routes

* Add devfile with default backend ingress

* Add tests for named describe command

* mock kclient

* Fix integration test failure

* Fix integration test failure with registry

* Add test for ingress with default backend

* Add unit test for ListRoutesAndIngresses

* Add documentation

* Fix circular dependency and test failures

* Update upstream docs

* Fix integration test and add unit test for owner reference

* DRY the unit test code

* Update pkg/component/component.go

Co-authored-by: Philippe Martin <contact@elol.fr>

* Use context to obtain app

* rm3l's review

Signed-off-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Armel Soro <armel@rm3l.org>
Co-authored-by: Philippe Martin <contact@elol.fr>
2022-11-18 16:22:06 +00:00
Philippe Martin
e6fd6862ac Make functions for executing run command reusable (#6277) 2022-11-02 17:04:31 -04:00
Armel Soro
918a4e97fb Make 'pkg/logs' platform-agnostic (#6251)
* Panic if platform for Exec is not supported yet

This will make the error more visible,
instead of hiding it.

* Use a consistent receiver name in 'pkg/kclient.Client#DeploymentWatcher'

* Make 'pkg/logs/LogsClient' rely on the generic 'platform.Client'

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Make 'pkg/component#Log' function rely on the generic 'platform.Client'

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Make the 'execHandler' in 'pkg/component' rely on the generic 'platform.Client'

Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Move 'matchOwnerReferenceWithResources' unit tests from 'pkg/logs' to 'pkg/kclient'

Those tests are specific to the Kubernetes implementation.

Co-authored-by: Philippe Martin <phmartin@redhat.com>
2022-11-01 10:59:17 -04:00
Philippe Martin
a2345c35c3 Build context as part of GenericRun (#6202)
* Remove non existing --project flag

* do not set the namespace as it is already the set one

* Use ctx to pass namespace

* Remove KClient from old context

* Pass appname through Context

* Remove unnecessary ctx builders

* Remove unused LocalConfigProvider from old context

* Move DevfileObj outside of Context EnvSpecificInfo

* Move DevfilePath outside of Context EnvSpecificInfoD

* Remove unused componentContext from old context

* Remove context flag

* Pre-run Init in a generic way

* Pass working directory in context

* Get Devfile and pass it in ctx, and use it for odo dev

* add binding: use new context

* build-images: use new context

* create namespace: use new context

* list namespace: use new context

* set namespace: use new context

* delete namespace: use new context

* delete component: use new context

* deploy: use new context

* describe binding: use new context

* list binding: use new context

* remove binding: use new context

* describe component: use new context

* list component: use new context

* list: use new context

* list services: use new context

* logout: use new context

* logs: use new context

* Remove old context code

* Some refactoring to avoid passing ctx when building it
to avoid complex dependency management during this building

* More doc on context.Get* functions
2022-10-19 05:38:18 -04:00
Philippe Martin
f78096d264 Refactor remotecmd (#6169)
* Remove kclient from interface / signatures

* Create Exec package

* Call ExecuteCommand with client

* Call ExecuteCommand with client from sync package

* Fix order of dependencies
2022-09-27 09:38:54 +02:00
Philippe Martin
32303b164d Add runtime label based on metadata:language/projectType (#6112)
* Add runtime label based on metadata:language/projectType

* Add integration tests for odo dev

* odo deploy integration test

* Reverse priority between pojectType and language
2022-09-14 09:22:45 +02:00
Philippe Martin
9e39df37d3 Use map for runningIn instead of array in JSON output (#6094)
* Use map for runningIn instead of array

* Set false entries in runningIn map

* Rename RunningModeList to RunningModes + fix doc

* Fix integration test
2022-09-06 18:55:19 +02:00
Philippe Martin
3add3939ae Move DetectName to method in alizer package (#6093) 2022-09-06 12:41:03 +02:00
Armel Soro
843717cab3 Make odo work if optional metadata.name field is missing in Devfile (#6015)
* Move 'starter_project.go' from 'pkg/component' to 'pkg/registry'

Functions in this file are only called from the 'registry' package,
so it makes sense for this file to belong to this package.

Furthermore, this paves the way to calling 'alizer.DetectName' from 'component.go',
thus avoiding a cyclic dependency between packages.

* Introduce central logic for determining component names in 'pkg/component/component.go'

This rewrites the 'component#GatherName' function that was already there,
but not used, to meet the expectations, i.e.:

- use 'metadata.name' field (after sanitizing it) if it is defined in the Devfile
- otherwise, use Alizer to detect the name. Under the hood, this leverages the 'alizer#DetectName' introduced in 83ad3ee, which means that:
-- use Alizer to detect the name automatically
-- otherwise, use the name of the Devfile base directory after sanitizing it

* Compute and store the component name in the CLI context, and pass it as needed

As commented out in [1], the context should ideally be built
and passed down to the business clients structs.

[1] https://github.com/redhat-developer/odo/pull/6015#discussion_r957005479

* Enrich relevant integration test cases

For the sake of both performance and readability,
only the tests that break in the absence of a 'metadata.name'
field in their Devfiles have been updated (to test this specific case).

* Add test case for 'odo dev' when a project with no source code is used with no 'metadata.name' in the Devfile

The rationale behind this is to purposely make
the Alizer library unable to detect the project.
Per the requirements, this would force us to use the project
directory name as component name.

This highlights an interesting behavior if the project
directory name is all-numeric (as is the case in our tests);
our sanitization logic automatically prepends an "x" prefix
to the directory name, so it can be used as a valid name
for the component.
2022-08-30 02:54:31 -04:00
Philippe Martin
64ee3db5b3 Implement "odo list" (#6043)
* Move "odo list" to "odo list component"

* Refactor odo list component

* Add --namespace flag to "odo list binding"

* odo list implementation

* Doc

* Apply suggestions from code review

Co-authored-by: Armel Soro <armel@rm3l.org>

Co-authored-by: Armel Soro <armel@rm3l.org>
2022-08-29 12:44:13 -04:00
Philippe Martin
0a83f1d899 Do not use env.yaml file anymore (#6057)
* Remove GetApplication from LocalConfigProvider interface and all related stuff

* Remove GetName from LocalConfigProvider interface and all related stuff

* Remove GetContainers from LocalConfigProvider interface

* Remove Exists method from LocalConfigProvider interface and stop odo dev writing env.yaml file

* Remove GetDebugort method from LocalConfigProvider interface + fix #6056

* Remove unnecessary fields from EnvInfo structure

* Remove all references to env.yaml file

* Review

* Test for #6056
2022-08-29 09:25:09 -04:00
Philippe Martin
644d94cde2 Ignore notfound error on delete (#6055) 2022-08-25 03:02:47 -04:00
Parthvi Vala
0e716239fb odo list: add odo version used to create a component to the output (#6028)
Signed-off-by: Parthvi Vala <pvala@redhat.com>

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2022-08-17 19:21:41 +00:00
Parthvi Vala
b4ee87281f Fix: Non odo components not reported (#6021)
* Fix: Non odo components not reported

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add unit test

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2022-08-17 07:46:42 +00:00
Parthvi Vala
224069cd68 odo dev: Add support for non-exec commands part of a composite run or debug command (#5923)
* Initial commit

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Move ValidateResourceExist(s) from pkg/service to pkg/devfile/adapters/kubernetes/component

* Fix odo dev cleanup

* Fix multiple deployment issue

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* DRY the code

* Fix unit test failure

* Add integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* remove comment

* Add isPartOfComponent to GetLabels, and GetSelector

* Add unit tests for changes in ListResourcesToDeleteFromDevfile

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix unit test failures due to removal of component label

* Enhance integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use a single devfile.yaml

* Fix test failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix rebase conflicts, add new tests for remote Dockerfile URI, and rm3l's review

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Co-authored-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Armel Soro <armel@rm3l.org>
Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Attempt at fixing integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Mockgen

* Changes post rebase

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Attempt at fixing integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix rebase mishap

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Co-authored-by: Armel Soro <armel@rm3l.org>
2022-08-10 10:41:43 +00:00
Philippe Martin
f22c3f854d odo dev: react to changes as soon as possible (#5933)
* Create auxialiary functions to find current deployment and pod name

* Create auxialiary function for pushing Kubernetes components to cluster

* Auxiliary function getPushDevfileCommands and remocve RunModeChanged flag as it is not possible anymore with long running dev command
+ move prelimiray tests at the beginning

* Create auxiliary function updatePVCsOwnerReferences + move isMainStorageEphemeral inside aux. function

* Watch for deployments in addition to watching for files during odo dev

* - Check the Deployment Generation to return earlier when generation changed
- Return earlier when pod is not ready

* Push receives a Status that it can update, to indicate the status of the component when the function returns. This status is passed from Start to Watch

* Use status to decide to sync files

* Simplify getting pod

* Status for PostStartEvents

* - Touch .gitignore earlier so it is not synced
- Add devstate.jso file to .gitignore

* Fix the integration tests.

* Make --no-watch work again

* Get smaller volumes for tests

* Quit when fail to exec port forwarding

* Exponential delay after an error

* Fix: get running pod

* Remove testing odo dev stops when the build command fails. odo dev now gives a change to the user to fix the problem

* Fix order or volumes and volume mounts in pod spec

* Use server side apply for updating PVC when supported

* Watch Devfile separately

* Adapt tests for devfile handled separately

* Update forwarded ports when necessary

* Display kubernetes resources created only when created/updated

* Do not set ResourceVersion when patching

* TEMP: Add more logs on failing integrattests

* Tests: select the *running* pod

* Use forward slashes for .gitignore content, even on Windows

* Rename GetOnePodFromSelector to GetRunningPodFromSelector

* Cleanup logs

* Fix 'odo log' integration test

* Add log "Waiting for Kubernetes resources"

* Fail if service bindings are not injected

* Rename sources related watcher, timer

* Fix delay after error

* Display info about Pod

* Disambiguate error messages

* Display events related to components pod

* Remove now unused functions used to wait for Deployment / Pod

* Typos + function renaming

* Do not watch devfile with --no-watch

* Use type switch for Kubernertes watch event

* Do not fail when watching Events is Forbidden

* Do not fail when servicebinding resources are forbidden

* Exit when build command fails on no-watch mode

* Sync devfile.yaml by default, workaround when commands change on devfile

* Rename to warningsWatcher

* Fix comment
2022-08-08 10:20:55 +00:00
Charlie Drage
83e994582a Dont save name of component to env.yaml (#5852)
<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind feature
/kind cleanup
/kind tests
/kind documentation

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->
/kind bug

**What does this PR do / why we need it:**

By default we should be saving the namespace / project name, not the app name /
component name.

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

Fixes #5780
Fixes #5886

**PR acceptance criteria:**

- [X] Unit test

- [X] Integration test

- [X] Documentation

**How to test changes / Special notes to the reviewer:**

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
2022-07-28 19:31:45 +02:00
Parthvi Vala
62f7c61436 Remove unused ComponentExist, PushedComponent function; Move ListFromCluster to List (#5944)
Signed-off-by: Parthvi Vala <pvala@redhat.com>
2022-07-13 15:48:49 +00:00
Philippe Martin
062160280f Add assertions for types implementing interfaces (#5893) 2022-07-01 08:12:24 +00:00
Parthvi Vala
dce95d62e2 Add preference add and remove commands (#5873)
* Add add, and remove commands

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Remove add and delete files

* Move cli/preference/registry/util.go > registry/utils.go

* Update tests, and documentation

* Move cli/preference/registry/consts/consts.go > segment/segment.go

* Fix test failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Rebase changes

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Remove old references

* Fix docs post-rebase

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix typo
2022-06-28 11:33:47 +00:00
Armel Soro
77ff2b89de Add support for composite run/debug commands (#5841)
* Change integration test expectations regarding composite run commands

* Add integration test supporting composite debug commands

* Rename in-container pid file from '.odo_devfile_cmd_<name>.pid' into '.odo_cmd_<name>.pid'

The implementation in kubeexec.go is indeed able to run any kind of commands,
not only Devfile-related.

* Pave the way to supporting composite run/debug commands

Drop validation rules that prevented from going further
with composite run or debug commands.

* Update logic for determining which containers should have their entrypoint overridden or env vars updated

The previous implementation was limited to Exec commands solely.
This now makes it easier to support other kind of commands.
For example, when handling a composite command, we are now recursively
determining the containers (a.k.a components) that would get used by this composite command.

* Store the process exit code in the pid file handled by kubeexec.go

This allows to more accurately determine how the process could be reported.

* Fix issue with util#DisplayLogs potentially not picking the last element of lines

* Make sure to execute the Build command only once when running a composite command

* Test that the Build command is executed once running a composite command

* Make sure not to retrieve the parent default command uselessly

* Log the command Id when it is about to be restarted

* Redirect build command logs to PID 1 process

This way, users would be able to display them (and follow them) with `odo logs` or `kubectl logs`

* Handle Errored case when logging information about the process that exited

* Make sure to override container entrypoint if needed for Build commands

Build commands (which could also be composite ones)
might be executed in a container different from the run or debug ones.

* Redirect output from commands handled by component.exec_handler to PID 1 process streams

This way, we can also have them displayed with `odo logs` or `kubectl logs`.
This includes Build and Devfile events commands.

* Make remotecmd#ExecuteCommand log stdout or stderr content only if there not empty

This reduces the clutter in case of an error with the command execution.

* Add integration test with more complex Devfile (composite build/run/debug commands running in different containers and with a shared volume)

* Update the 'Executing the application' spinner accordingly when the related command is done
2022-06-24 16:50:56 +00:00
Armel Soro
74516a9f58 Add support for command/args fields in container components (#5768)
* Introduce new 'pkg/remotecmd' package

This package allows to execute commands in remote packages
and exposes an interface for managing processes associated
to given Devfile commands.

* Rely on 'pkg/libdevfile' as much as possible for Devfile command execution

This requires passing a handler at the odo side,
which in turns uses the 'pkg/remotecmd' package to
run commands in remote containers.

* Switch to running without Supervisord as PID 1 in containers

To do this, the idea is to start the container component:
1- using the command/args defined in the Devfile
2- using whatever was defined in the container image
   if there is no command/args defined in the Devfile

Then, once the container is started, we would execute the Devfile
commands directly in the container component, just like a simple
'kubectl exec' command would do.
Since this is a long-running command (and potentially never ending),
we would need to run it in the background, i.e. in a side goroutine.

Point 2) above requires implementing a temporary hack (as discussed in [1]),
without us having to wait for [2] to be merged on the Devfile side.
This temporary hack overrides the container entrypoint with "tail -f /dev/null"
if the component defines no command or args (in which case we should have
used whatever is defined in the image, per the specification).

[1] https://github.com/redhat-developer/odo/pull/5768#issuecomment-1147190409
[2] https://github.com/devfile/registry/pull/102

* Rename K8s adapter struct 'client' field into 'kubeClient', as suggested in review

* Rename sync adapter struct 'client' fields to better distinguish between them

* Make sure messages displayed to users running 'odo dev' are the same

* Update temporary hack log message

Co-authored-by: Philippe Martin <contact@elol.fr>

* Make sure to handle process output line by line, for performance purposes

* Handle remote process output and errors in the Devfile command handler

The implementation in kubeexec.go should remain
as generic as possible

* Keep retrying remote process status until timeout, rather than just waiting for 1 sec

Now that the command is run via a goroutine,
there might be some situations where we were checking
the status just before the goroutine had a chance to start.

* Handle remote process output and errors in the Devfile command handler

The implementation in kubeexec.go should remain
as generic as possible

* Update kubeexec StopProcessForCommand implementation such that it relies on /proc to kill the parent children processes

* Ignore missing children file in getProcessChildren

* Unit-test methods in kubexec.go

* Fix missing logs when build command does not pass when running 'odo dev'

Also add integration test case

* Fix spinner status when commands passed to exec_handler do not pass

* Make sure to check process status right after stopping it

The process just stopped might take longer to exit (it might have caught
the signal and is performing additional cleanup)

* Keep retrying remote process status until timeout, rather than just waiting for 1 sec

Now that the command is run via a goroutine,
there might be some situations where we were checking
the status just before the goroutine had a chance to start.

* Fix potential deadlock when reading output from remotecmd#ExecuteCommandAndGetOutput

Rely on the same logic in ExecuteCommand

* Add more unit tests

* Remove block that used to check debug port from env info

As commented out in [1], we don't store anymore the debug port value in the ENV file.

[1] https://github.com/redhat-developer/odo/pull/5768#discussion_r893163382

* Rename 'getCommandFromFlag' into 'getCommandByName', as suggested in review

* Make remotecmd package more generic

This package no longer depends on Devfile-related packages.

* Fix comments in libdevfile.go

* Move errorIfTimeout struct field as parameter of RetryWithSchedule

This boolean is tied to the given retry schedule,
so it makes sense for it to be passed with the schedule.

* Expose a single ExecuteCommand function that returns both stdout and stderr

Co-authored-by: Philippe Martin <contact@elol.fr>
2022-06-17 10:51:02 +00:00
Dharmit Shah
e3b3b8eb53 Add odo logs (#5760)
* Add odo logs

* Nolint for random number generation

* Changes based on Philippe's PR review

* Add logs for `odo logs`

* Add nolint at the right place to fix unit tests

* Changes based on PR feedback

* Name the key in unstructured.Unstructured

* Name containers with same names as c, c1, c2

* Remove unused struct field

* Modify documentation to follow general pattern

* Undo the changes done in earlier commits

* odo logs help message is accurate

* Update docs/website/versioned_docs/version-3.0.0/command-reference/logs.md

Co-authored-by: Parthvi Vala <pvala@redhat.com>

* Fixes broken link rendering

* Correct the example used in odo logs doc

* Make container name clearer in odo logs output

* Wrap at 120 chars, not 80

* Fixes to the document after rebase mistake

Co-authored-by: Parthvi Vala <pvala@redhat.com>
2022-06-13 00:57:30 -04:00
Philippe Martin
5fef442300 Delete dev resources only when stopping Dev session (#5751)
* Add integration test

* Fix issue

* doc

* Update pkg/component/delete/delete.go

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>

* Review

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>
2022-05-19 10:05:04 -04:00