watcher: Update naming
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a0949b2bde
commit
eeee9a8ab7
|
@ -45,7 +45,7 @@ type WatcherParams struct {
|
||||||
StrictExist bool
|
StrictExist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watcher watches a deployment and tails the logs for its currently active
|
// Watcher watches a resource and tails the logs for its currently active
|
||||||
// pods.
|
// pods.
|
||||||
type Watcher struct {
|
type Watcher struct {
|
||||||
params WatcherParams
|
params WatcherParams
|
||||||
|
@ -79,10 +79,10 @@ func (w *Watcher) Close() {
|
||||||
close(w.closeChan)
|
close(w.closeChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch watches a deployment.
|
// Watch watches a resource.
|
||||||
func (w *Watcher) Watch(ctx context.Context) error {
|
func (w *Watcher) Watch(ctx context.Context) error {
|
||||||
// ensure any actively monitored resource is cleaned up on exit.
|
// ensure any actively monitored resource is cleaned up on exit.
|
||||||
defer w.removeDeployment()
|
defer w.unwatchResource()
|
||||||
|
|
||||||
ns := w.params.Namespace
|
ns := w.params.Namespace
|
||||||
if ns == "" {
|
if ns == "" {
|
||||||
|
@ -131,9 +131,9 @@ func (w *Watcher) Watch(ctx context.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
w.addDeployment(ctx, resource.GetUID(), labels.SelectorFromSet(selectorAsMap))
|
w.watchResource(ctx, resource.GetUID(), labels.SelectorFromSet(selectorAsMap))
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
w.removeDeployment()
|
w.unwatchResource()
|
||||||
}
|
}
|
||||||
// errChan is never closed.
|
// errChan is never closed.
|
||||||
case err := <-w.errChan:
|
case err := <-w.errChan:
|
||||||
|
@ -156,14 +156,14 @@ func (w *Watcher) checkResourceExists(ctx context.Context, namespace string, res
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Watcher) addDeployment(ctx context.Context, resourceUID types.UID, podSelector labels.Selector) {
|
func (w *Watcher) watchResource(ctx context.Context, resourceUID types.UID, podSelector labels.Selector) {
|
||||||
if w.resourceUID == resourceUID {
|
if w.resourceUID == resourceUID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.removeDeployment()
|
w.unwatchResource()
|
||||||
|
|
||||||
w.logger.Println("[DeploymentWatcher] add podWatcher")
|
w.logger.Println("[Watcher] add podWatcher")
|
||||||
|
|
||||||
w.resourceUID = resourceUID
|
w.resourceUID = resourceUID
|
||||||
w.podSelector = podSelector
|
w.podSelector = podSelector
|
||||||
|
@ -183,9 +183,9 @@ func (w *Watcher) addDeployment(ctx context.Context, resourceUID types.UID, podS
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Watcher) removeDeployment() {
|
func (w *Watcher) unwatchResource() {
|
||||||
if w.podWatcher != nil {
|
if w.podWatcher != nil {
|
||||||
w.logger.Println("[DeploymentWatcher] remove podWatcher")
|
w.logger.Println("[Watcher] remove podWatcher")
|
||||||
w.podWatcher.Close()
|
w.podWatcher.Close()
|
||||||
w.podWatcher = nil
|
w.podWatcher = nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue