func (lock *Lock) watch(object runtime.Object) (watch.Interface, error) {
	var listOptions metav1.ListOptions
	if accessor, err := meta.Accessor(object); err != nil {
		panic(err)
	} else {
		listOptions.FieldSelector = fields.OneTermEqualSelector("metadata.name", accessor.GetName()).String()
		listOptions.ResourceVersion = accessor.GetResourceVersion()
	}
	log.Printf("kube/lock %v: watch %#v", lock, listOptions)
	if watcher, err := lock.client.DaemonSets(lock.namespace).Watch(listOptions); err != nil {
		return nil, fmt.Errorf("Watch: %v", err)
	} else {
		return watcher, nil
	}
}
watch lock object
package kube
import (
	"context"
	"fmt"
	"log"
	"time"
	appsv1 "k8s.io/api/apps/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/api/meta"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/fields"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/apimachinery/pkg/watch"
	appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
	"k8s.io/client-go/rest"
)
type Lock struct {
	client     appsv1client.AppsV1Interface
	namespace  string
	name       string
	annotation string
	value      string
}
func (lock *Lock) String() string {
	return fmt.Sprintf("%v/daemonsets/%v", lock.namespace, lock.name)
}
func (lock *Lock) connect(config *rest.Config) error {
	if client, err := appsv1client.NewForConfig(config); err != nil {
		return err
	} else {
		lock.client = client
	}
	return nil
}
func (lock *Lock) test(object runtime.Object) (value string, available bool, acquired bool) {
	if accessor, err := meta.Accessor(object); err != nil {
		panic(err)
	} else if value := accessor.GetAnnotations()[lock.annotation]; value == "" {
		log.Printf("kube/lock %v: test %v=%v: free", lock, lock.annotation, value)
		return value, true, false
	} else if value == lock.value {
		log.Printf("kube/lock %v: test %v=%v: acquired", lock, lock.annotation, value)
		return value, true, true
	} else {
		log.Printf("kube/lock %v: test %v=%v: locked", lock, lock.annotation, value)
		return value, false, false
	}
}
func (lock *Lock) set(object *runtime.Object) error {
	if accessor, err := meta.Accessor(*object); err != nil {
		panic(err)
	} else if value := accessor.GetAnnotations()[lock.annotation]; value != "" && value != lock.value {
		return fmt.Errorf("Busy lock: %v=%v", lock.annotation, value)
	} else {
		log.Printf("kube/lock %v: set %v=%v", lock, lock.annotation, lock.value)
		accessor.GetAnnotations()[lock.annotation] = lock.value
	}
	return nil
}
func (lock *Lock) clear(object *runtime.Object) error {
	if accessor, err := meta.Accessor(*object); err != nil {
		panic(err)
	} else if value := accessor.GetAnnotations()[lock.annotation]; value != lock.value {
		return fmt.Errorf("Broken lock: %v=%v, expected %v", lock.annotation, value, lock.value)
	} else {
		log.Printf("kube/lock %v: clear %v=%v", lock, lock.annotation, value)
		delete(accessor.GetAnnotations(), lock.annotation)
	}
	return nil
}
func (lock *Lock) get() (runtime.Object, error) {
	log.Printf("kube/lock %v: get", lock)
	if obj, err := lock.client.DaemonSets(lock.namespace).Get(lock.name, metav1.GetOptions{}); err != nil {
		return nil, fmt.Errorf("Get: %v", err)
	} else {
		return obj, nil
	}
}
func (lock *Lock) Test() (value string, acquired bool, err error) {
	if object, err := lock.get(); err != nil {
		return "", false, err
	} else {
		value, _, acquired := lock.test(object)
		return value, acquired, nil
	}
}