Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cluster name to flagger cmd args for altering #1041

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/flagger/main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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