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

fix: Enable default triggers for argo rollouts #1689

Merged
merged 14 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/antonmedv/expr v1.8.9
github.com/argoproj/notifications-engine v0.2.1-0.20210525191332-e8e293898477
github.com/argoproj/notifications-engine v0.3.0
github.com/argoproj/pkg v0.9.0
github.com/aws/aws-sdk-go-v2/config v1.8.1
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.5.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDw
github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy8kCu4PNA+aP7WUV72eXWJeP9/r3/K9aLE=
github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3stzu0Xys=
github.com/appscode/go v0.0.0-20190808133642-1d4ef1f1c1e0/go.mod h1:iy07dV61Z7QQdCKJCIvUoDL21u6AIceRhZzyleh2ymc=
github.com/argoproj/notifications-engine v0.2.1-0.20210525191332-e8e293898477 h1:mcfUn59PKafSlbkZ39+aQAIzoAsYzjVR61O6Ns/Dfzo=
github.com/argoproj/notifications-engine v0.2.1-0.20210525191332-e8e293898477/go.mod h1:rKhm9LtebGKgLA/UtPtBeRUrrS/CT0U5az1jSfUiipw=
github.com/argoproj/notifications-engine v0.3.0 h1:1KMVYwXlg7SGzX00eg/bU0YupXDVdfpm8FlpNbrkUxM=
github.com/argoproj/notifications-engine v0.3.0/go.mod h1:0TEB4QbOsNN8URcsUJpAFuuG6aw8KS8ZY/YCzsss9JQ=
github.com/argoproj/pkg v0.9.0 h1:PfWWYykfcEQdN0g41XLbVh/aonTjD+dPkvDp3hwpLYM=
github.com/argoproj/pkg v0.9.0/go.mod h1:ra+bQPmbVAoEL+gYSKesuigt4m49i3Qa3mE/xQcjCiA=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down Expand Up @@ -605,6 +605,8 @@ github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.m
github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
github.com/gostaticanalysis/analysisutil v0.1.0/go.mod h1:dMhHRU9KTiDcuLGdy87/2gTR8WruwYZrKdRq9m1O6uw=
github.com/gostaticanalysis/comment v1.3.0/go.mod h1:xMicKDx7XRXYdVwY9f9wQpDJVnqWxw9wCauCMKp+IBI=
github.com/gregdel/pushover v1.1.0 h1:dwHyvrcpZCOS9V1fAnKPaGRRI5OC55cVaKhMybqNsKQ=
github.com/gregdel/pushover v1.1.0/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down
62 changes: 49 additions & 13 deletions utils/record/record.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package record

import (
"context"
"encoding/json"
"github.com/argoproj/notifications-engine/pkg/services"
"k8s.io/client-go/tools/cache"

//"github.com/argoproj/notifications-engine/pkg/triggers"
RaviHari marked this conversation as resolved.
Show resolved Hide resolved
k8sinformers "k8s.io/client-go/informers"
"regexp"
"strings"
"time"

"github.com/argoproj/notifications-engine/pkg/services"

"github.com/argoproj/notifications-engine/pkg/api"
api "github.com/argoproj/notifications-engine/pkg/api"
"github.com/argoproj/notifications-engine/pkg/subscriptions"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -89,6 +94,39 @@ type FakeEventRecorder struct {
Events []string
}

func NewFakeApiFactory() api.Factory {
var (
settings = api.Settings{ConfigMapName: "my-config-map", SecretName: "my-secret", InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) {
RaviHari marked this conversation as resolved.
Show resolved Hide resolved
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
return map[string]interface{}{"obj": obj}
}, nil
}}
)

cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "my-config-map", Namespace: "default"},
Data: map[string]string{
"service.slack": `{"token": "abc"}`,
},
}
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "my-secret", Namespace: "default"},
}

clientset := k8sfake.NewSimpleClientset(cm, secret)
informerFactory := k8sinformers.NewSharedInformerFactory(clientset, time.Minute)

secrets := informerFactory.Core().V1().Secrets().Informer()
configMaps := informerFactory.Core().V1().ConfigMaps().Informer()
apiFactory := api.NewFactory(settings, "default", secrets, configMaps)
go informerFactory.Start(context.Background().Done())
if !cache.WaitForCacheSync(context.Background().Done(), configMaps.HasSynced, secrets.HasSynced) {
log.Info("failed to sync informers")
}

return apiFactory
}

func NewFakeEventRecorder() *FakeEventRecorder {
recorder := NewEventRecorder(
k8sfake.NewSimpleClientset(),
Expand All @@ -98,7 +136,7 @@ func NewFakeEventRecorder() *FakeEventRecorder {
},
[]string{"name", "namespace", "type", "reason"},
),
nil,
NewFakeApiFactory(),
RaviHari marked this conversation as resolved.
Show resolved Hide resolved
).(*EventRecorderAdapter)
recorder.Recorder = record.NewFakeRecorder(1000)
fakeRecorder := &FakeEventRecorder{}
Expand Down Expand Up @@ -167,23 +205,21 @@ func NewAPIFactorySettings() api.Settings {

// Send notifications for triggered event if user is subscribed
func (e *EventRecorderAdapter) sendNotifications(object runtime.Object, opts EventOptions) error {
notificationsAPI, err := e.apiFactory.GetAPI()
if err != nil {
return err
RaviHari marked this conversation as resolved.
Show resolved Hide resolved
}
cfg := notificationsAPI.GetConfig()
logCtx := logutil.WithObject(object)
subsFromAnnotations := subscriptions.Annotations(object.(metav1.Object).GetAnnotations())
destByTrigger := subsFromAnnotations.GetDestinations(nil, map[string][]string{})

destByTrigger := cfg.GetGlobalDestinations(object.(metav1.Object).GetLabels())
destByTrigger.Merge(subscriptions.NewAnnotations(object.(metav1.Object).GetAnnotations()).GetDestinations(cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
trigger := translateReasonToTrigger(opts.EventReason)

destinations := destByTrigger[trigger]
if len(destinations) == 0 {
logCtx.Debugf("No configured destinations for trigger: %s", trigger)
return nil
}

notificationsAPI, err := e.apiFactory.GetAPI()
if err != nil {
return err
}

// Creates config for notifications for built-in triggers
triggerActions, ok := notificationsAPI.GetConfig().Triggers[trigger]
RaviHari marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
Expand Down