Skip to content

Commit

Permalink
Merge pull request #1041 from baldey-nz/baldey-nz/notification-change
Browse files Browse the repository at this point in the history
Add cluster name to flagger cmd args for altering
  • Loading branch information
stefanprodan committed Jan 11, 2022
2 parents 96d190a + 8c881ab commit 5776f0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/flagger/main.go
Expand Up @@ -83,6 +83,7 @@ var (
enableConfigTracking bool
ver bool
kubeconfigServiceMesh string
clusterName string
)

func init() {
Expand Down Expand Up @@ -115,6 +116,7 @@ func init() {
flag.BoolVar(&enableConfigTracking, "enable-config-tracking", true, "Enable secrets and configmaps tracking.")
flag.BoolVar(&ver, "version", false, "Print version")
flag.StringVar(&kubeconfigServiceMesh, "kubeconfig-service-mesh", "", "Path to a kubeconfig for the service mesh control plane cluster.")
flag.StringVar(&clusterName, "cluster-name", "", "Cluster name to be included in alert msgs.")
}

func main() {
Expand Down Expand Up @@ -238,6 +240,7 @@ func main() {
meshProvider,
version.VERSION,
fromEnv("EVENT_WEBHOOK_URL", eventWebhook),
clusterName,
)

// leader election context
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/controller.go
Expand Up @@ -66,6 +66,7 @@ type Controller struct {
observerFactory *observers.Factory
meshProvider string
eventWebhook string
clusterName string
}

type Informers struct {
Expand All @@ -87,6 +88,7 @@ func NewController(
meshProvider string,
version string,
eventWebhook string,
clusterName string,
) *Controller {
logger.Debug("Creating event broadcaster")
flaggerscheme.AddToScheme(scheme.Scheme)
Expand Down Expand Up @@ -118,6 +120,7 @@ func NewController(
routerFactory: routerFactory,
meshProvider: meshProvider,
eventWebhook: eventWebhook,
clusterName: clusterName,
}

flaggerInformers.CanaryInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
14 changes: 12 additions & 2 deletions pkg/controller/events.go
Expand Up @@ -74,7 +74,7 @@ func (c *Controller) sendEventToWebhook(r *flaggerv1.Canary, eventType, template
func (c *Controller) alert(canary *flaggerv1.Canary, message string, metadata bool, severity flaggerv1.AlertSeverity) {
var fields []notifier.Field
if metadata {
fields = alertMetadata(canary)
fields = alertMetadata(canary, c.clusterName)
}

// send alert with the global notifier
Expand Down Expand Up @@ -173,8 +173,18 @@ func (c *Controller) alert(canary *flaggerv1.Canary, message string, metadata bo
}
}

func alertMetadata(canary *flaggerv1.Canary) []notifier.Field {
func alertMetadata(canary *flaggerv1.Canary, cluster string) []notifier.Field {
var fields []notifier.Field

if cluster != "" {
fields = append(fields,
notifier.Field{
Name: "Cluster",
Value: cluster,
},
)
}

fields = append(fields,
notifier.Field{
Name: "Target",
Expand Down

0 comments on commit 5776f0b

Please sign in to comment.