* 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>
* 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
* 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>
* 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.
* 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.
* 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
* 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>
* 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>