Close events channel on executor level
This will fix a bug, when go routine wasn't finished when program has exited. Results of the bug was that not all defered statemnets were executed, which lead to temp kubeconfig not being cleaned up Relates-To: #541 Closes: #541 Change-Id: If314886d9bed04b2c0f8a5006bc058395f4fdf7a
This commit is contained in:
parent
ab7bbfce89
commit
dbe05585d3
@ -71,7 +71,6 @@ func NewApplier(eventCh chan events.Event, f cmdutil.Factory) *Applier {
|
||||
|
||||
// ApplyBundle apply bundle to kubernetes cluster
|
||||
func (a *Applier) ApplyBundle(bundle document.Bundle, ao ApplyOptions) {
|
||||
defer close(a.eventChannel)
|
||||
log.Debugf("Getting infos for bundle, inventory id is %s", ao.BundleName)
|
||||
objects, err := a.getObjects(ao.BundleName, bundle, ao.DryRunStrategy)
|
||||
if err != nil {
|
||||
|
@ -125,11 +125,18 @@ func TestApplierRun(t *testing.T) {
|
||||
a.Poller = tt.poller
|
||||
}
|
||||
// start writing to channel
|
||||
go a.ApplyBundle(tt.bundle, opts)
|
||||
go func(bundle document.Bundle, applyOpts applier.ApplyOptions) {
|
||||
// since applier doesn't close channel anymore, we need to close it
|
||||
// after it applier is finished
|
||||
defer close(eventChan)
|
||||
a.ApplyBundle(bundle, applyOpts)
|
||||
}(tt.bundle, opts)
|
||||
|
||||
var airEvents []events.Event
|
||||
for e := range eventChan {
|
||||
airEvents = append(airEvents, e)
|
||||
}
|
||||
|
||||
var errs []error
|
||||
for _, e := range airEvents {
|
||||
if e.Type == events.ErrorType {
|
||||
|
@ -75,10 +75,10 @@ func NewKubeApplierExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
||||
|
||||
// Run executor, should be performed in separate go routine
|
||||
func (e *KubeApplierExecutor) Run(ch chan events.Event, runOpts ifc.RunOptions) {
|
||||
defer close(ch)
|
||||
applier, filteredBundle, err := e.prepareApplier(ch)
|
||||
if err != nil {
|
||||
handleError(ch, err)
|
||||
close(ch)
|
||||
return
|
||||
}
|
||||
defer e.cleanup()
|
||||
|
Loading…
Reference in New Issue
Block a user