12 Commits

Author SHA1 Message Date
Philippe Martin
9624721ed3 odo dev --logs (#6957)
* Move logic to pkg/logs

* Fix Ctrl-c

* odo dev --logs

* Add integration test
2023-07-07 10:58:56 -04:00
Philippe Martin
f276d0d77b Watch for new pods when logs --follow (#6914)
* Watch for new pods when logs --follow

* Fix integration tests

* Implement --follow for podman platform

* Add integration test
2023-06-28 14:21:04 +02: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
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
Dharmit Shah
07b2a01404 Fetch pods first; use channel instead of slice (#5973)
* First grab the pods matching the selector

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use channel instead of slice

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Update pkg/kclient/all.go

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

* Use errgroup instead of WaitGroup

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

An errgroup returns immediately if any of the go routines in the group
return an error. This way, error is propogated sooner rather than later.

* Shadow loop variable for go vet

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Close the channel being looped over

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use `select` instead of ranging the channel

When ranging the channel, it is critical to close it so that the go
routine doesn't hang around infinitely. This caused an issue wherein
`odo delete component` would not be able to show all the resources that
would get deleted because the channel got closed a little too soon.

Using `select` and an explicit error chanel should help mitigate this.

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Close the channels to prevent leaking goroutine

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Goroutine to wait for goroutines

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

Co-authored-by: Parthvi Vala <pvala@redhat.com>
2022-08-05 13:10:29 +00:00
Dharmit Shah
f85f3d555d Use sync/atomic to keep tab on go routines (#5961)
* Use sync/atomic to keep tab on go routines

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

As a result of the code pushed in
https://github.com/redhat-developer/odo/pull/5942, `odo logs --follow`
would hang if user executed it without pushing the component in either
dev or deploy modes. This was not a problem before that PR was merged.

This was caused because below code would not get executed in business
layer if user was using follow mode:

```
if !follow {
    doneChan <- struct{}{}
}
```

The reason we didn't execute it for follow mode was that it prematurely
exited and often didn't print the logs of all the containers.

This PR uses `sync/atomic` to keep a tab on go routines started for `odo
logs --follow` instead of using `sync.WaitGroup`, and checks if no go
routines are running before it exits. This enables us to use `doneChan
<- struct{}{}` in business layer irrespective of user running `odo logs`
with or without follow mode.

Why not use `wg.Wait()` as first statement instead in
`case <-events.Done:`? This is because `wg.Wait()` is a blocking call
and won't be called upon each time a go routine for `odo logs --follow`
is done (`wg.Done()`). This leads to same problem as that fixed by PR
5942, which is that `odo logs --follow` won't exit even if the
underlying odo component was deleted.

* Use a struct instead of int64 for atomic

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

`go vet` complains about direct assignment to an atomic value. Hence, an
anonymous struct to fix the problem.
2022-07-21 15:11:04 +02:00
Dharmit Shah
233491e681 Grab pod logs concurrently (#5942)
* Grab pod logs concurrently

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Rename function to reflect its purpose

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Architect the code better

Return a struct of channels listen on these channels in CLI layer. It
helps remove the need to call business layer method in a go routine.

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Add comments to the struct

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use a struct instead of map string interface

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Put error on appropriate channel

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

This addresses two things:
1. Error if odo fails to grab logs for any container
2. Prevents execution of the next line which tries to put content to
   `events.Logs` in spite of receiving error

* Remove io writer from arguments

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Makes the comment more accurate

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Don't pass io writer as arg at CLI layer

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Exit for loop when done printing logs in follow mode

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

The `for` loop here is an infinite one. It prevents the `odo logs
--follow` command from exiting when for any reason underlying Pod has
been deleted. This could be tested by something as simple as hitting a
Ctrl+C when `odo dev` is running, and `odo logs --follow` is running in
a separate terminal.
2022-07-20 19:49:51 +02:00
Philippe Martin
062160280f Add assertions for types implementing interfaces (#5893) 2022-07-01 08:12:24 +00:00
Dharmit Shah
8c99ce9209 Adds support to follow/tail/stream odo logs (#5846)
* Adds support to follow/tail/stream odo logs

* Address go vet; don't use values outside of go routine

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Add comment about non-blocking channel

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Add --follow in docs

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use go routines only for streaming logs

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use generic container image with command

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Remove mutex

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Show longs since creation of container

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Add new-line after printing the message

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Use mutex to fix colour issues

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Handle mutex unlock and color unset well

* Use anonymous function to print logs
2022-06-24 14:26:12 +00:00
Dharmit Shah
a29db8bc21 Adds odo logs for Deploy mode (#5825)
* Adds odo logs for deploy mode

* Changes based on Philippe's review

* Trim the documentation for odo logs

* Update pkg/logs/interface.go

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

* Simplify code; less is more

@feloy++

* Trim the odo logs doc to bare minimum

Co-authored-by: Philippe Martin <contact@elol.fr>
2022-06-17 12:56:07 +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