61 Commits

Author SHA1 Message Date
Philippe Martin
b93a75c11a Move UI out of experimental mode (#7012)
* Make UI not experimental

* Display API and UI URLs

* Remove link to old sources

* Fix integration tests

* Add UI to Usage Data

* Add a "Using the GUI to edit the Devfile" page to doc

* Add link to odo.dev specific page

* Apply suggestions from code review

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

* Change favicon with odo logo

* Display web console URL as part of the Dev status

* Update UI static files

* Document that Comments not supported

* Add UI screenshots

---------

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-08-04 13:02:34 +02: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
Armel Soro
147542db69 Do not necessarily error out if odo dev is stopped via Ctrl+C (#6917)
* Add test highlighting the expectations

* Propagate errors and call os.Exit only in 'main' functions

See ExitInMain[1] and ExitInMain_ExitOnce[2] coding convention guidelines.

[1] https://github.com/redhat-developer/odo/wiki/Dev:-Coding-Conventions#exit-in-main
[2] https://github.com/redhat-developer/odo/wiki/Dev:-Coding-Conventions#exit-once

* Handle errors returned by Cleanuper#Cleanup

This makes sure the exit code of the command
is mapped onto any error returned by Cleanup

* Do not return an error when the watch loop in 'odo dev' is interrupted

* Test that the exit code of 'odo dev' matches the error returned by the cleanup logic
2023-06-22 13:14:07 +02:00
Armel Soro
28ed064133 Do not return an error in odo analyze if current directory contains an invalid Devfile (#6905)
* Add unit test highliging the issue

* Fix 'delete' unit tests

* Pass the filesystem object where it is relevant

* Add a way for CLI commands to indicate whether of not they require a valid Devfile

For the 'analyze' command, this is not required,
so Devfile parsing will be ignored completely.

* Make the fake filesystem return an absolute current dir

Otherwise, some code will assume it is relative,
and try to prepend the current physical directory
2023-06-22 10:06:18 +02: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
191ee6f45f Wait when Build command fails (#6771)
* Same signature for reconcile in kubedev/podmandev

* Do not call initial reconcile

* Do not retry + filter deployment events

* Integration tests

* Move logs back to level 4

* Remove unnecessary files

* Log state + Set state to ready when build fails
2023-05-02 04:39:58 -04:00
Philippe Martin
e9c5f86563 Simplify devfile Kubernetes adapter (#6762)
* Get values from context

* Move Devfile param to WatchParams and biuld adapter only once

* Move pkg/devfile/adapters/kubernetes/* into pkg/dev/kubedev

* Rename Push to reconcile and split in 2 parts: components and innreloop

* Pass out ans errout as startOptions

* Embed StartOptions into PushParameters

* Embed StartOptions into WatchParameters

* Fix passing startoptions

* Deduplicate options (out, ...)

* Revert adding unwanted files

* Fix wait app ready
2023-04-25 05:13:19 -04:00
Parthvi Vala
c82583bdc3 Allow users to define custom port-mappings for port forwarding [Kubernetes] (#6704)
* Allow users to define custom port-mappings for port forwarding: add methods to parse and validate  the flag

* Add methods to kube port-forwarding to obtain custom port pairs

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

* Pass custom port-mappings from CLI to Business layer

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

* Add integration test

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

* Add integration test for debug

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

* Add check for using --random-ports and --port-forward together

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

* Return all validation errors for --port-forward flag at once

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

* Use random local ports for integration testing

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

* Fix ci failures

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

* Print invalids of --port-forward to stderr so that they are printed when debugging

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

* Attempt at fixing the test failure on windows

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

Remove the use of seed for randomzing

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

* Use global counters for generate port number

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

* Apply changes from code review

Co-authored-by: Armel Soro <asoro@redhat.com>

---------

Signed-off-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Armel Soro <asoro@redhat.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>
2023-04-06 15:37:36 -04:00
Armel Soro
cc2e8def81 Support autoBuild and deployByDefault on Image and Kubernetes/OpenShift components (#6654)
* Add sample Devfile with multiple autoBuild/deployByDefault combinations

It will be used for integration tests.

* Add helper function to update a given Devfile Command Group

This will allow supporting cases where we need to run a custom command,
but this is not implemented yet on odo (cases with 'odo dev --debug'
and 'odo deploy').
In this case, this helper will allow updating the Devfile for example to
unmark the current default command as non-default, and mark the custom
one as default.

* Add test cases for 'odo dev'

* Add test cases for 'odo deploy'

* Add test cases for 'odo build-images'

'odo build-images' should build all images regardless of the 'autoBuild' property.

* Display the spinner when creating or updating Kubernetes resources

This helps understand what resources are being patched.

* Handle deployByDefault on K8s and OpenShift components

* Add 'devfile.GetImageComponentsToPush' functions that returns the list of image components to auto-create

See https://github.com/devfile/api/issues/852#issuecomment-1211928487 for more context.

* Handle automatic image component creation for 'odo dev' on Kubernetes

* Handle automatic image component creation for 'odo dev' on Podman

* Handle automatic image and K8s/OpenShift component creation for 'odo deploy'

* Bump Devfile library to the latest commit at this time (c1b23d2)

This includes the fix for [1], which provides a way not to set default values automatically

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

* Do not set default values when parsing a Devfile

See [1] for the rationale

[1] https://github.com/redhat-developer/odo/issues/5694\#issuecomment-1465778398

* Add documentation in the Devfile reference page

* Revert "Display the spinner when creating or updating Kubernetes resources"

This reverts commit 6ad073e63cb0e685f165eed767619a90997393a3.

* Avoid re-applying Image components multiple times

'adapter#Push' might get called several times when there are
state transitions (either on the Deployment in the cluster,
or from 'odo').
It might be confusing to apply Image components over and over again
(and also it can be slower if we need to push images to remote registries).

* Move GetK8sAndOcComponentsToPush and GetImageComponentsToPush to libdevfile package

As suggested in review, this should be the responsibility of the devfile library

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

* fixup! Handle automatic image and K8s/OpenShift component creation for 'odo deploy'

* fixup! Handle automatic image component creation for 'odo dev' on Podman

* fixup! Avoid re-applying Image components multiple times

* Apply suggestions from code review

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

* fixup! Do not set default values when parsing a Devfile

* Fix devfile-deploy-functional-pods.yaml (used in 'odo logs' tests)

Set deployByDefault to false on innerloop-pod component.
Otherwise, since it is not referenced by any apply command,
it will be automatically created by *both* 'odo dev' and 'odo deploy'.

---------

Co-authored-by: Philippe Martin <phmartin@redhat.com>
Co-authored-by: Parthvi Vala <pvala@redhat.com>
2023-04-05 01:30:30 -04:00
Armel Soro
29b5a38f88 Make port-forwarding work on Podman with apps listening on the loopback interface, via a new --forward-localhost flag (#6629)
* Embed platform.Client interface in platform-specific interfaces

This avoids repeating the same methods in both interfaces,
and makes the intent clearer.

* Verify interface compliance of PodmanCli at compile time

This is recommended in the Coding Conventions guidelines [1].
Specifically, what's important here is checking that it meets the 'platform.Client' contract.

[1] https://github.com/redhat-developer/odo/wiki/Dev:-Coding-Conventions#verify-interface-compliance

* Move K8s-specific implementation of port-forwarding to a dedicated package

This paves the way to providing a different implementation for Podman

* Remove GetPortsToForward method from the portForward.Client interface

Current implementation relies on the Devfile object,
so it makes more sense to be in the libdevfile package.

* Monitor and send appropriate status events after starting a remote command process

This allows callers to get more meaningful events about the process.

* Implement port-forwarding logic on Podman

As explained in [1], this makes use of a helper sidecar container
(aptly named "odo-helper-port-forwarding") to be added to the Pod Spec created by odo.
In this scope, port-forwarding will be equivalent of executing a socat command in this
helper container, like so:

socat -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858

In the command above, this will open up port 20001 on the helper container,
and forwarding requests to localhost:5858
(which would be in the application container, part of the same Pod)

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

* Update portForward.Client interface methods

Specifically, the 'StartPortForwarding' method
can now accept an explicit list of ports that needs to
be forwarded, if the caller can compute provide such information.

This is currently useful on Podman where the ports
(even the random ones) are known in advance.

* Add helper sidecar container to the Pod Spec generated on Podman

As explained in [1], this helper sidecar container (aptly named "odo-helper-port-forwarding")
will hold the actual container/host ports mapping in the spec
(to overcome the limitation of using hostPort against a container app listening on the loopback interface);
this running container will be used to execute the actual port-forwarding commands (based on socat), e.g:

```
apiVersion: v1
kind: Pod
metadata:
  name: my-component-app
  labels:
    app: my-component-app
spec:
  containers:
  - name: runtime
    command: [ 'tail', '-f', '/dev/null']
    # Omitted for brevity, but imagine an application being executed by odo
    # and listening on both 0.0.0.0:3000 and 127.0.0.1:5858

  - name: odo-helper-port-forwarding
    image: quay.io/devfile/base-developer-image:ubi8-latest
    command: [ 'tail', '-f', '/dev/null']
    ports:
    - containerPort: 20001
      # A command will be executed by odo, e.g.: 'socat -d -d tcp-listen:20001,reuseaddr,fork tcp:localhost:3000'
      hostPort: 20001
    - containerPort: 20002
      # A command will be executed by odo, e.g.: 'socat -d -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858'
      hostPort: 20002

# ... Omitted for brevity
```

In this scope, port-forwarding from 20002 to 5858 for example will be equivalent of executing
a socat command in this helper container, like so:

socat -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858

In the command above, this will open up port 20001 on the helper container,
and forwarding requests to localhost:5858
(which would be in the 'runtime' container, part of the same Pod)

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

* Inject the right portForward client depending on the platform

* Delegate port-forwarding on Podman to the appropriate client

* Implement --forward-localhost on Podman

* Add unit and integration test cases

* Cover more debug-related test cases on Podman

* Expose the endpoint protocol so as to instruct socat to listen and forward the right protocol

* Fix sub-deps of EXEC and PORT_FORWARD, as suggested in review
2023-03-06 08:12:22 +01:00
Armel Soro
3adf8e5243 On Podman, detect if application is listening on the loopback interface, and either error out or not depending on --ignore-localhost (#6620)
* Add functions allowing to detect ports opened in a given container

Specifically, this will be useful in Podman to detect
applications that are bound to the loopback interface

* Make `odo dev` fail on Podman if we detect that the application is bound to the loopback interface (on any ports supposed to be forwarded)

Next step will be to provide an option for end-users
to override this behavior, by either:
- ignoring this error (--ignore-localhost);
- or explicitly adding a redirect via a side container (--forward-localhost)

More context in https://github.com/redhat-developer/odo/issues/6510#issuecomment-1439986558

* Add '--ignore-localhost' flag to 'odo dev' on Podman

Currently, `odo dev` on Podman will error out
if it detects that the application is listening on the container loopback interface.
Instead of erroring out, this flag allows users to ignore such failure; a warning will be displayed anyway if
the application is listening on the container loopback interface, but odo will not error out.
Ports will be marked as forwarded, but Podman might fail to redirect traffic to the application
if it is bound to this loopback interface.

* Add test cases

* Fix existing integration tests by passing --ignore-localhost on Podman

- odo describe component
- odo dev --debug

Some projects used there are listening to the loopback interface,
so they won't work on Podman unless --ignore-localhost is passed.

Next, we'll pass --forward-localhost when it is implemented,
so we can have a fully working project with port-forwarding.

* Extract logic for handling loopback ports in a separate method

Requested in review
2023-03-01 17:16:57 +01:00
Armel Soro
9a39462615 Show information about forwarded debug ports in odo describe component (#6537)
* Refactor 'libdevfile#GetContainerEndpointMapping' so it returns the whole Endpoint struct

It will help extract useful information like the port name and exposure.

* Fix typo in parameter name (in portForward#Client interface)

* Display the port names in the output of 'odo describe component'

* Display the port exposures in the output of 'odo describe component'

* Tell whether the port is a debug one or not in the output of 'odo describe component'

* Add integration tests meeting the expectations

* Update documentation
2023-01-27 12:02:57 -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
6d9bb37acb hotReloadCapable recognized on podman (#6509)
* Fix

* Add integration tests
2023-01-19 11:24:42 -05:00
Philippe Martin
f079c3cd7a Sync files on Podman (#6348)
* Call WatchAndPush

* NoOpWatcher for Kube-related watchers + Move cleanup to dedicated method

* Set component state

* Call reconcile again when files changed

* Fix prompt message

* Integration test for podman/sync file

* More integration tests

* Move display of forwarded ports after application started
2022-11-30 11:43:07 -05:00
Philippe Martin
20ea3a2043 Podman dev (#6183)
* Add runOn flag

* Instantiate Kube/Podman DevClient instance according to runOn flag

* Start and stop Podman Pod

* Unit tests for createPodFromComponent

* podman mode runs without Kube config

* Fix tests + rebase

* Add sync and exec clients to podman dev

* tbc: call sync

* Remove unnecessary kclient dependency from exec client

* Inject podman client

* Implement ExecCMDInContainer for podman client

* Move [gG]etFirstContainerWithSourceVolume to dev/common package and use it for Podman

* TBC: execute build/run commands

* Fix rebase

* Fix unit test

* Comments for refacto

* Prepare implementation of Platform

* Use ExecuteRunCommand for run handler

* Do not pass parameters present in context

* Move back instanciation of devclient to clientset package

* Move CleanupDevResources method from Watch to Dev package

* CleanupResources: Do not pass parameters present in context

* Fix deleting volumes at exit time

* Check volumes do not exist

* Add support for postStart event

* Make odo dev work when no cluster is configured

* Review

* Add more TODOs

* User interface

* More info on ExitError errors

* Display forwarded ports in output and devstate file

* Add tests for forwarded ports

* Create .odo when necessary

* Add keyboard commands message

* Add doc on podman platform
2022-11-21 08:56:44 -05:00
Philippe Martin
712254ae66 Centralize environment configuration (#6293)
* Define central config

* Use envConfig in GenericRun for segment parameters

* Pass the env config into the context passed to CLI methods

* Use PodmanCmd and DockerCmd from context

* Remove tests now that ODO_DISABLE_TELEMETRY is checked for a bool value

* deploy.Deploy: Use values from ctx instead of parameters + use FS from DI

* dev.Start: Use values from ctx instead of parameters

* image.Build*: Use values from ctx instead of parameters

* Use telemetry file from context

* Pass ctx to segment.getTelemetryForDevfileRegistry

* Use ctx in getTelemetryForDevfileRegistry

* Call IsTelemetryEnabled once and use scontext.GetTelemetryStatus after

* Fix unit tests

* Use envConfig in segment.IsTelemetryEnabled

* Define TelemetryCaller constant in test helper

* IsTrackingConsentEnabled: get value from envconfig instead of env

* Use ctx instead of GLOBALODOCONFIG

* Place ODO_EXPERIMENTAL_MODE in configuration

* Use maintained envconfig package

* Define default values when exist

* Document accepted boolean values
2022-11-17 17:57:34 +00:00
Philippe Martin
67272fd81d Remove localconfigLocalConfigProvider abstraction (#6285)
* Remove localconfigLocalConfigProvider abstraction

* Remove LocalConfigProvider interface

* Move LocalStorage to pkg/storage (with ListStorage)
2022-11-16 12:33:29 +00: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
2c0b2ee2a6 Refacto sync pkg (#6163)
* Rename interface to SyncExtracter

* Inline PushParameters fields into SyncParameters

* Move SyncParameters to sync package

* Move ComponentName as parameter to SyncFiles

* Move SyncAdapter as handler

* Build syncclient with dependency injection system

* Move ForcePush logic outside of sync package + remove unused ForceBuild option
2022-09-23 16:30:55 +02:00
Philippe Martin
1d78b85093 Try to reload config when disconnected from the cluster (#6130)
* Try to reload config when disconnected from the cluster

* Fix integration test

* Message also when isForbidden
2022-09-20 08:55:40 +02:00
Philippe Martin
8b5986fa50 Do not display message when using no-watch flag (#6116) 2022-09-13 11:31:56 +02:00
Philippe Martin
59f4f8348a Manual sync of files pressing p (#6089)
* Set character mode for input stream

* Move watchers in receiver + sync when p pressed

* Integration tests manual sync

* Add a console to DevSession

* Vendor

* Skip pressKey tests on Windows

* Add interactive test for p press

* Add info about pressing p key

* Doc

* Review

* Rephrase Manul sync

* Fix HotReloadCapable

* Document timers

* Document enableCharInput

* Document geyKey and getKeyWatcher functions

* Avoid to Kill in AfterEach after running Kill before
2022-09-09 18:54:54 +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
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
04dec8529e Watch for devfile dependencies (#6020)
* GetReferencedLocalFiles

* Watch for all devfile dependencies

* Integration test
2022-08-17 12:03:54 +00:00
Philippe Martin
60c9a78b22 odo dev: Cleanup after displaying the error (#6024)
* odo dev: Cleanup after displaying the error

* Fix integration test
2022-08-17 10:23:21 +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
Philippe Martin
1b303ebfa3 Cleanup Adapter structure to not be used to pass parameters (#5918)
* Do not use receiver to pass DevfileCommands parameters

* Do not use receiver to pass DebugPort parameter

* Do not use receiver to pass deployment parameter

* Do not use receiver to pass pod parameter

* Move randomPorts and errOut as PushParameters
2022-07-06 12:42:49 +00:00
Philippe Martin
a0b0d0f3c1 Simplify pkg/devfile/adapters/... packages (#5914)
* Remove dependency on common.AdapterContext for sync.Adapter

* Simplify adapters.NewComponentAdapter

* NewComponentAdapter accepts kubernetes.KubernetesContext instead of interface{}

* Replace KubernetesContext with its only field Namespace

* Move the Push Interface and  builders to the kubernetes.component  package

* Move AdapterContext to kubernetes.component package

* Embeds component.New into NewKubernetesAdapter

* Move GetCommandsMap where it is used

* Move GetSyncFilesFromAttributes  where it is used

* Move constants where they are used

* Move types to adapters package

* Update pkg/devfile/adapters/kubernetes/component/adapter.go

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

Co-authored-by: Armel Soro <armel@rm3l.org>
2022-07-06 07:35:42 +00:00
Philippe Martin
062160280f Add assertions for types implementing interfaces (#5893) 2022-07-01 08:12:24 +00:00
Philippe Martin
8cdc9348d7 Substituting variables into the devfile from the CLI (#5749)
* Define var and and-file flags

* vars package

* Vars for deploy

* Add integration tests for dev

* Update dev mock

* New devfile library version

* Add doc

* Fix validate

* Review

* Apply suggestions from code review

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

* review

Co-authored-by: Parthvi Vala <pvala@redhat.com>
2022-06-13 05:03:22 -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
Philippe Martin
bd8e78a05e odo dev store information about currently forwarded ports (#5703)
* Save state (forwarded ports + PID + timestamp) to local file and cleanup

* Integration tests

* Documentation

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

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

* Fail when an error happens writing state file
In case of error during initialization, odo dev cleanup the resources

* Fix typo

* Test localPort matches a number

* Remove PID and timestamp from state + rename to devstate.json

* Run IBM cloud tests as non root

* Fix doc

* Review

* Remove reference to PID/timestamp from doc

Co-authored-by: Armel Soro <armel@rm3l.org>
2022-05-05 04:12:25 -04:00
Philippe Martin
3354b21a87 odo dev --debug (#5690)
* odo dev --debug

* Integration tests

* validate commands

* Fix rebase

* Review: Add integration test

* Modify error message when run/debug commands are not found in devfile
2022-04-27 04:40:04 -04:00
Philippe Martin
e42d6575e5 Fix ignores files during sync (#5689)
* fix ignore files

* Add tests for synced files

* Use go-gitignore library

* rename topPath
2022-04-26 15:12:36 -04:00
Dharmit Shah
58a0481b5e Adds odo dev --no-watch (#5675)
* Adds `odo dev --no-watch`

* Remove select for a single case

More details on - https://github.com/dominikh/go-tools/issues/503#issuecomment-497020529

* Update mocks

* Update tests/integration/devfile/cmd_dev_test.go

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

* Rename CleanupFunc to Cleanup

* Add usage doc for --no-watch

* Remove infinite for loop

Co-authored-by: Armel Soro <armel@rm3l.org>
2022-04-22 02:16:32 -04:00
Philippe Martin
904dfa5a42 Wait deletion (#5604)
* odo delete component --wait flag

* Wait non blocking resources

* refactoring

* Add integration tests

* review

* Fix rebase: wait deletion when quitting odo dev

* Wait after Ctrl-C
2022-04-04 17:14:43 -04:00
Dharmit Shah
44c7e773cb Adds/updates code comments and removes unused client (#5619)
* Adds/updates comments

* Removes k8s client dependency from subdep
2022-04-04 07:58:01 -04:00
Dharmit Shah
c73f177cb6 Cleans up innerloop resources upon Ctrl+c (#5596)
* Cleans up innerloop resources upon Ctrl+c

* Remove cleanup method from dev interface

* Self review

* Remove ImagePullPolicy change

* Print message about resource deletion

* Fixes issue of multiple push for single event

Fixes #5532

Takes idea from https://github.com/fsnotify/fsnotify/issues/122#issuecomment-1065925569

* Self review and trim WatchParameters

* Rollback parameters useful for unit tests, and changes to unit tests

* Define context early in dev

* Use delete client to delete resources from cluster

* Update pkg/odo/cli/dev/dev.go

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

* Update pkg/odo/cli/dev/dev.go

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

* Update pkg/watch/watch.go

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

* Update pkg/watch/watch.go

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

* Removed unnecessary return statement

* Don't error in Telemetry for every Ctrl+c

* Refactors watch and push logic

* Run mockgen.sh script

* Fixes message on stdout

* Removes function re-added due to rebase mistake

* PR review and unit tests failure

* Unit tests & integration tests

* Use constants defined in the file

* More refactoring of watch package, and unit tests

* PR review and change tests to suit changed behaviour

* Prints appropriate message upon user interrupt

* Add comment for evaluateChangesFunc, remove irrelevant comments from
watch_test.go

Co-authored-by: Philippe Martin <contact@elol.fr>
2022-04-04 04:59:43 -04:00
Dharmit Shah
0396b435c3 Implements port forwarding for odo dev (#5526)
* First pass of port-forward for odo dev

* Supports forwarding multiple ports/endpoints

* Change message wording

* Port forwarding happens port 40001 onward

* Organize the code

* Integration tests

* Update the CLI help message

* Catch and check err

* Changes for failing unit tests

* Fix test and add newline to a message

* Remote label and use for loop

* Adds TODO to cleanup when port-forwarding fails

* Change messaging printed on the CLI

* Break Start method into multiple methods

* Set debug port while creating push parameters in dev

* Test after making a change to a file in pwd

* Refactoring to put things where they should be

* Notify user to run odo dev again if endpoints change

* Unit tests and rebase mistakes

* Add newline character for clear formatting

* Create business logic for reuse to find endpoints

* Fix unit and integration test failures

* Self review

* Changes based on Philippe's review

* Two more changes based on Philippe's review

* More changes based on PR review

* Changes based on PR feedback and more

- Renames all receivers in kclient package to `c`
- Adds mocks

* Removes unnecessary function

* Make function more generic for reuse

* Rename Options to DevOptions

* Address review comments by Tomas

* Fix failing unit test

* Modify message to restart odo dev

* Use helper.RunDevMode in odo dev tests

* Remove doubly imported log package

* Modifies clientset at CLI and business layer

- No need of KUBERNETES client for `odo dev` business layer.
- Added KUBERNETES client for `odo dev` CLI layer.

* Remove hardcoding of URL in tests

- It uses @feloy's work in PR #5570.

* Uses regexp to find strings.

* Makes FindAllMatchingStrings more generally usable

* Adds constant for localhost regex

* Replace matches with urls and remove unnecessary Sprintf

* Documents what urls is in RunDevMode function.

* Update tests/helper/helper_dev.go

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

* Update tests/helper/helper_dev.go

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

* Update tests/helper/helper_dev.go

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

* Update tests/helper/helper_dev.go

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

Co-authored-by: Philippe Martin <contact@elol.fr>
2022-03-25 15:14:13 +01:00
Charlie Drage
7618e8f3e4 Improve UX/UI of odo deploy and dev (#5539) 2022-03-22 19:58:38 +01:00
Philippe Martin
24fd02673d Remove github.com/pkg/errors dependency (#5557)
* Change errors.Wrapf

* Replace errors.Wrap

* Dont use pkg/errors (except error.Cause)

* Fix errors on Windows (do not test system underlying message)

* Replace errors.Cause

* Review
2022-03-21 11:32:42 +01:00
Parthvi Vala
64f334fa7b Remove information about resource cleanup from odo dev exit message (#5543) 2022-03-12 00:24:12 -05:00
Dharmit Shah
f80207b029 Implements odo dev (#5441)
* Skeleton for odo dev and a unit test

* Update go mod for fsnotify

* Start method Pushes and then Watches

* More understandable code comments

* Client and interface for watch package

* Mocks for watch package

* Add CLI layer

* Fix infinite watch & push trigger

* Remove context flag from odo dev

* Add integration tests for odo dev

* Add klog to dev.go

* Replace errors.Wrap with fmt.Errorf

* Self review

* Removes `odo watch` command, but the business logic exists as it's
  used by odo dev
* Removes integration tests for `odo watch`
* Removes errors.go and types.go from pkg/dev/ since they are empty

* Check if error is not nil

* Use real client in watch unit tests

* Uncomment AfterEach from tests

* Modify the logs printed to stdout

* Changes based on Philippe's review

* Remove unused clients

* Parthvi's PR review and unit test fixes

* Fix gofmt message, remove message to not expect

* Fix lint complains, add mistakenly deleted URL creation logic

* Remove or modify tests that rely on odo push output

* Remove unused variables based on golangci-lint

* Fixes based on Philippe's review

* Initialize first index after first run of odo dev

* Modify odo dev test, and uncomment a mistake
2022-03-03 04:15:37 -05:00
Philippe Martin
21ea375695 Use functions from devfile library (#5457)
* Remove duplicated functions from pkg/util

* Use generator.GetVolumeMountPath from devfile library
2022-02-14 00:40:37 -05:00
Philippe Martin
e2f8b131cc Refactor occlient (#5271)
* Remove unused code / files

* Move RunLogout to kclient

* Move project to kclient

* Move Routes to kclient

* Cleanup occlient package

* Review
2021-12-09 18:21:19 +00:00
Tomas Kral
5f79c542a8 openshift/odo -> redhat-developer/odo (#5268)
* openshift/odo -> redhat-developer/odo

* update more links to redhat-developer
2021-12-01 16:38:34 +01:00
Tomasz Janiszewski
0512d3a2cf Fix shadow (#5172)
* Configure golint

* auth/login.go

* catalog/catalog.go

* component/component.go

* component/component_full_description.go

* config/config.go

* component/adapter.go

* component/podwatcher_test.go

* envinfo/envinfo.go

* envinfo/storage.go

* envinfo/url.go

* kclient/deployments.go

* occlient/occlient.go

* describe/component.go

* component/create.go

* component/delete.go

* component/list.go

* component/push.go

* config/set.go

* config/unset.go

* service/operator_backend.go

* genericclioptions/context.go

* preference/preference_test.go

* project/project.go

* service/link.go

* service/service.go

* storage/storage.go

* sync/adapter.go

* sync/adapter_test.go

* sync/sync.go

* url/kubernetes.go

* util/file_indexer.go

* util/util.go

* util/util_test.go

* watch/watch.go

* watch/watch_test.go

* helper/helper_filesystem.go

* devfile/cmd_devfile_push_test.go

* devfile/cmd_devfile_url_test.go

* devfile/cmd_devfile_watch_test.go

* operatorhub/cmd_service_test.go

* gofmt

* Enable gofmt in golangci

* Return context not nil

* reanme context

* Remove unused value in watch

* Fix pkg/catalog/catalog.go
2021-10-27 18:02:17 +00:00