watcher: Update naming
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-06-14 17:54:10 +02:00
parent a0949b2bde
commit eeee9a8ab7
1 changed files with 10 additions and 10 deletions

View File

@ -45,7 +45,7 @@ type WatcherParams struct {
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.
type Watcher struct {
params WatcherParams
@ -79,10 +79,10 @@ func (w *Watcher) Close() {
close(w.closeChan)
}
// Watch watches a deployment.
// Watch watches a resource.
func (w *Watcher) Watch(ctx context.Context) error {
// ensure any actively monitored resource is cleaned up on exit.
defer w.removeDeployment()
defer w.unwatchResource()
ns := w.params.Namespace
if ns == "" {
@ -131,9 +131,9 @@ func (w *Watcher) Watch(ctx context.Context) error {
continue
}
w.addDeployment(ctx, resource.GetUID(), labels.SelectorFromSet(selectorAsMap))
w.watchResource(ctx, resource.GetUID(), labels.SelectorFromSet(selectorAsMap))
case watch.Deleted:
w.removeDeployment()
w.unwatchResource()
}
// errChan is never closed.
case err := <-w.errChan:
@ -156,14 +156,14 @@ func (w *Watcher) checkResourceExists(ctx context.Context, namespace string, res
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 {
return
}
w.removeDeployment()
w.unwatchResource()
w.logger.Println("[DeploymentWatcher] add podWatcher")
w.logger.Println("[Watcher] add podWatcher")
w.resourceUID = resourceUID
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 {
w.logger.Println("[DeploymentWatcher] remove podWatcher")
w.logger.Println("[Watcher] remove podWatcher")
w.podWatcher.Close()
w.podWatcher = nil
}