func OnDeploymentChanged(deployment *appsv1.Deployment, event config.Event) {
	cfg := config.GetInstance()
	dd := datadog.GetInstance()
	kubeClient := kube.GetInstance()
	overrides := parseOverrides(deployment)
	switch strings.ToLower(event.EventType) {
	case "delete":
		if cfg.DryRun == false {
			log.Debug("Deleting resource monitors.")
			metrics.ChangeCounter.WithLabelValues("deployments", "delete").Inc()
			dd.DeleteMonitors([]string{cfg.OwnerTag, fmt.Sprintf("astro:object_type:%s", event.ResourceType), fmt.Sprintf("astro:resource:%s", event.Key)})
		}
	case "create", "update":
		var record []string
		var monitors []ddapi.Monitor
		ns, err := kubeClient.Client.CoreV1().Namespaces().Get(context.TODO(), event.Namespace, metav1.GetOptions{})
		if err != nil {
			log.Errorf("Error getting namespace %s: %+v", event.Namespace, err)
			return
		}
		monitors = append(*cfg.GetMatchingMonitors(deployment.Annotations, event.ResourceType, overrides), *cfg.GetBoundMonitors(ns.Annotations, event.ResourceType, overrides)...)
		for _, monitor := range monitors {
			err = applyTemplate(deployment, &monitor, &event)
			if err != nil {
				metrics.TemplateErrorCounter.Inc()
				log.Errorf("Error applying template for monitor %s: %v", *monitor.Name, err)
				return
			}
			log.Debugf("Reconcile monitor %s", *monitor.Name)
			if cfg.DryRun == false {
				_, err := dd.AddOrUpdate(&monitor)
				metrics.ChangeCounter.WithLabelValues("deployments", "create_update").Inc()
				record = append(record, *monitor.Name)
				if err != nil {
					metrics.ErrorCounter.Inc()
					log.Errorf("Error adding/updating monitor")
				}
			} else {
				log.Info("Running as DryRun, skipping DataDog update")
			}
		}
		if strings.ToLower(event.EventType) == "update" && !cfg.DryRun {
			datadog.DeleteExtinctMonitors(record, []string{cfg.OwnerTag, fmt.Sprintf("astro:object_type:%s", event.ResourceType), fmt.Sprintf("astro:resource:%s", event.Key)})
		}
	default:
		log.Warnf("Update type %s is not valid, skipping.", event.EventType)
	}
}
OnDeploymentChanged is a handler that should be called when a deployment changes.
package handler
import (
	"context"
	"fmt"
	"strings"
	log "github.com/sirupsen/logrus"
	ddapi "github.com/zorkian/go-datadog-api"
	appsv1 "k8s.io/api/apps/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"github.com/fairwindsops/astro/pkg/config"
	"github.com/fairwindsops/astro/pkg/datadog"
	"github.com/fairwindsops/astro/pkg/kube"
	"github.com/fairwindsops/astro/pkg/metrics"
)