func (s *DeploymentScanner) Watch(_stop chan bool) (chan Event, error) {
	return watcher(_stop, s.getWatcher, s.unmarshall)
}
Watch will return a channel on which Event objects will be published that
describe change events in the cluster.
package scanner
import (
	"fmt"
	"github.com/golang/glog"
	v1 "k8s.io/api/apps/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/watch"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/rest"
	_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
)
type DeploymentScanner struct {
	config     Config
	kubernetes *rest.Config
}
func init() {
	RegisterModule("deployment", NewDeploymentScanner)
}
func NewDeploymentScanner() (Scanner, error) {
	kubernetes, err := getKubernetes()
	if err != nil {
		return nil, fmt.Errorf("failed instantiating k8s client: %s", err)
	}
	return &DeploymentScanner{
		kubernetes: kubernetes,
	}, nil
}
func (s *DeploymentScanner) SetConfig(cfg Config) {
	s.config = cfg
}
func (s *DeploymentScanner) GetConfig() Config {
	return s.config
}
func (s *DeploymentScanner) GetObjects() ([]*Object, error) {
	rcs, err := s.getDeployments()
	if err != nil {
		return nil, err
	}
	return s.getObjects(rcs)
}
func (s *DeploymentScanner) Scale(obj *Object, state *int, replicas int) error {
	glog.Infof("Scaling %s/%s to %d replicas", obj.Namespace, obj.Name, replicas)
	apps, err := kubernetes.NewForConfig(s.kubernetes)
	if err != nil {
		return err
	}
	dp, err := apps.AppsV1().Deployments(obj.Namespace).Get(obj.Name, metav1.GetOptions{})
	if err != nil {
		return fmt.Errorf("GetScale failed with: %s", err)
	}
	repl := int32(replicas)
	dp.Spec.Replicas = &repl
	if state != nil {
		dp.ObjectMeta = updateState(dp.ObjectMeta, *state)
	}
	_, err = apps.AppsV1().Deployments(obj.Namespace).Update(dp)
	return err
}
func (s *DeploymentScanner) GetState(obj *Object) (int, error) {
	dc, err := s.getDeployment(obj)
	if err != nil {
		return 0, err
	}
	repl := int(*dc.Spec.Replicas)
	return repl, err
}
func (s *DeploymentScanner) getDeployment(obj *Object) (*v1.Deployment, error) {
	apps, err := kubernetes.NewForConfig(s.kubernetes)
	if err != nil {
		return nil, err
	}
	return apps.AppsV1().Deployments(obj.Namespace).Get(obj.Name, metav1.GetOptions{})
}
func (s *DeploymentScanner) getDeployments() (*v1.DeploymentList, error) {
	apps, err := kubernetes.NewForConfig(s.kubernetes)
	if err != nil {
		return nil, err
	}
	return apps.AppsV1().Deployments(s.config.Namespace).List(metav1.ListOptions{
		LabelSelector: s.config.Label,
	})
}
func (s *DeploymentScanner) getObjects(rcs *v1.DeploymentList) ([]*Object, error) {
	objs := []*Object{}
	for _, rc := range rcs.Items {
		obj, err := s.unmarshall(&rc)
		if err != nil {
			return nil, err
		}
		if obj.Schedule != nil {
			objs = append(objs, obj)
		}
	}
	return objs, nil
}