Skip to content
Draft
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
18 changes: 13 additions & 5 deletions docs/spec/v1beta3/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ The following is an example of an event sent by kustomize-controller to report a
"namespace": "apps",
"uid": "7d0cdc51-ddcf-4743-b223-83ca5c699632"
},
"relatedObject": {
"apiVersion": "source.toolkit.fluxcd.io/v1",
"kind": "GitRepository",
"name": "webapp",
"namespace": "apps"
},
"metadata": {
"kustomize.toolkit.fluxcd.io/revision": "main/731f7eaddfb6af01cb2173e18f0f75b0ba780ef1"
},
"severity":"error",
"severity": "error",
"reason": "ValidationFailed",
"message":"service/apps/webapp validation error: spec.type: Unsupported value: Ingress",
"reportingController":"kustomize-controller",
"timestamp":"2022-10-28T07:26:19Z"
"action": "Reconciling",
"message": "service/apps/webapp validation error: spec.type: Unsupported value: Ingress",
"reportingController": "kustomize-controller",
"timestamp": "2022-10-28T07:26:19Z"
}
```

In the above example:

- An event is issued by kustomize-controller for a specific object, indicated in the
`involvedObject` field.
- `relatedObject` field optionally references a secondary object involved in the action (correlates to the source).
- The notification-controller receives the event and finds the [alerts](alerts.md)
that match the `involvedObject` and `severity` values.
- For all matching alerts, the controller posts the `message` and the source revision
Expand All @@ -43,7 +51,7 @@ In the above example:
## Event structure

The Go type that defines the event structure can be found in the
[fluxcd/pkg/apis/event/v1beta1](https://github.com/fluxcd/pkg/blob/main/apis/event/v1beta1/event.go)
[fluxcd/pkg/apis/event/v1](https://github.com/fluxcd/pkg/blob/main/apis/event/v1/event.go)
package.

## Rate limiting
Expand Down
7 changes: 4 additions & 3 deletions internal/controller/alert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"context"

corev1 "k8s.io/api/core/v1"
kuberecorder "k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

apiv1 "github.com/fluxcd/notification-controller/api/v1"
apiv1beta3 "github.com/fluxcd/notification-controller/api/v1beta3"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/runtime/events"
"github.com/fluxcd/pkg/runtime/patch"
)

Expand All @@ -37,7 +38,7 @@ import (
// AlertReconciler reconciles an Alert object to migrate it to static Alert.
type AlertReconciler struct {
client.Client
kuberecorder.EventRecorder
events.EventRecorder

ControllerName string
}
Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
controllerutil.RemoveFinalizer(obj, apiv1.NotificationFinalizer)

log.Info("removed finalizer from Alert to migrate to static Alert")
r.Event(obj, corev1.EventTypeNormal, "Migration", "removed finalizer from Alert to migrate to static Alert")
r.Eventf(obj, nil, corev1.EventTypeNormal, "Migration", eventv1.ActionReconciled, "%s", "removed finalizer from Alert to migrate to static Alert")

return
}
4 changes: 2 additions & 2 deletions internal/controller/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controller
import (
"context"

kuberecorder "k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -28,6 +27,7 @@ import (
apiv1 "github.com/fluxcd/notification-controller/api/v1"
apiv1beta3 "github.com/fluxcd/notification-controller/api/v1beta3"
"github.com/fluxcd/pkg/cache"
"github.com/fluxcd/pkg/runtime/events"
"github.com/fluxcd/pkg/runtime/patch"

"github.com/fluxcd/notification-controller/internal/notifier"
Expand All @@ -42,7 +42,7 @@ import (
// Provider.
type ProviderReconciler struct {
client.Client
kuberecorder.EventRecorder
events.EventRecorder

TokenCache *cache.TokenCache
}
Expand Down
11 changes: 6 additions & 5 deletions internal/controller/receiver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
kerrors "k8s.io/apimachinery/pkg/util/errors"
kuberecorder "k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand All @@ -37,9 +36,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/conditions"
helper "github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/events"
"github.com/fluxcd/pkg/runtime/patch"
"github.com/fluxcd/pkg/runtime/predicates"

Expand All @@ -51,7 +52,7 @@ import (
type ReceiverReconciler struct {
client.Client
helper.Metrics
kuberecorder.EventRecorder
events.EventRecorder

ControllerName string
}
Expand Down Expand Up @@ -170,14 +171,14 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r

// Emit warning event if the reconciliation failed.
if retErr != nil {
r.Event(obj, corev1.EventTypeWarning, meta.FailedReason, retErr.Error())
r.Eventf(obj, nil, corev1.EventTypeWarning, meta.FailedReason, eventv1.ActionReconciling, "%s", retErr.Error())
}

// Log and emit success event.
if retErr == nil && conditions.IsReady(obj) {
msg := fmt.Sprintf("Reconciliation finished, next run in %s", obj.GetInterval().String())
log.Info(msg)
r.Event(obj, corev1.EventTypeNormal, meta.SucceededReason, msg)
r.Eventf(obj, nil, corev1.EventTypeNormal, meta.SucceededReason, eventv1.ActionReconciled, "%s", msg)
}
}()

Expand Down Expand Up @@ -353,7 +354,7 @@ func (r *ReceiverReconciler) markTerminal(obj *apiv1.Receiver, log logr.Logger,
conditions.MarkStalled(obj, reason, "%s", errMsg)
obj.Status.ObservedGeneration = obj.Generation
log.Error(err, prefix)
r.Event(obj, corev1.EventTypeWarning, reason, errMsg)
r.Eventf(obj, nil, corev1.EventTypeWarning, reason, eventv1.ActionFailed, "%s", errMsg)
}

// token extract the token value from the secret object
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/receiver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestReceiverReconciler_deleteBeforeFinalizer(t *testing.T) {

r := &ReceiverReconciler{
Client: k8sClient,
EventRecorder: record.NewFakeRecorder(32),
EventRecorder: events.NewFakeRecorder(32),
}
// NOTE: Only a real API server responds with an error in this scenario.
_, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKeyFromObject(receiver)})
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ func TestMain(m *testing.M) {
if err := (&AlertReconciler{
Client: testEnv,
ControllerName: controllerName,
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
EventRecorder: testEnv.GetEventRecorder(controllerName),
}).SetupWithManager(testEnv); err != nil {
panic(fmt.Sprintf("Failed to start AlertReconciler: %v", err))
}

if err := (&ProviderReconciler{
Client: testEnv,
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
EventRecorder: testEnv.GetEventRecorder(controllerName),
}).SetupWithManager(testEnv); err != nil {
panic(fmt.Sprintf("Failed to start ProviderReconciler: %v", err))
}
Expand All @@ -93,7 +93,7 @@ func TestMain(m *testing.M) {
Client: testEnv,
Metrics: testMetricsH,
ControllerName: controllerName,
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
EventRecorder: testEnv.GetEventRecorder(controllerName),
}).SetupWithManager(testEnv, ReceiverReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"golang.org/x/text/cases"
"golang.org/x/text/language"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

type Alertmanager struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/alertmanager_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

func Fuzz_AlertManager(f *testing.F) {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/azure_devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/microsoft/azure-devops-go-api/azuredevops/v6/git"
"sigs.k8s.io/controller-runtime/pkg/client"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/auth/azure"
"github.com/fluxcd/pkg/cache"
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/azure_devops_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

const apiLocations = `{"count":0,"value":[{"area":"","id":"428dd4fb-fda5-4722-af02-9313b80305da","routeTemplate":"","resourceName":"","maxVersion":"6.0","minVersion":"5.0","releasedVersion":"6.0"}]}`
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/azure_devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/microsoft/azure-devops-go-api/azuredevops/v6/git"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/azure_eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/auth/azure"
"github.com/fluxcd/pkg/cache"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/ktrysmt/go-bitbucket"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/apis/meta"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/bitbucket_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

func Fuzz_Bitbucket(f *testing.F) {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"strings"
"time"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/apis/meta"
"github.com/hashicorp/go-retryablehttp"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/bitbucketserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"net/http"
"net/http/httptest"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"testing"
"time"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/hashicorp/go-retryablehttp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

type DataDog struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/datadog_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"path"
"strings"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

// Discord holds the hook URL
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/discord_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

func Fuzz_Discord(f *testing.F) {
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"fmt"
"net/url"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"

"github.com/hashicorp/go-retryablehttp"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/forwarder_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

func Fuzz_Forwarder(f *testing.F) {
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

func TestForwarder_New(t *testing.T) {
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestForwarder_Post(t *testing.T) {
{
name: "non-empty HMAC key adds signature header",
hmacKey: []byte("7152fed34dd6149a7c75a276c510da27cb6f82b0"),
hmacHeader: "sha256=65b018549b1254e7226d1c08f9567ee45bc9de0fc4e7b1a40253f9a018b08be7",
hmacHeader: "sha256=2662a6dd1a887c05183aa5b9787d5ed92116199f09c7b3c7908ee3bd20bc60d9",
xSigHeader: "should be overwritten with actual signature",
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/git_change_request_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package notifier
import (
"fmt"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

// changeRequestComment contains shared logic for change request comment providers
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"

"code.gitea.io/sdk/gitea"
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
"github.com/fluxcd/pkg/apis/meta"
ctrl "sigs.k8s.io/controller-runtime"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/notifier/gitea_pull_request_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"code.gitea.io/sdk/gitea"

eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
)

type GiteaPullRequestComment struct {
Expand Down
Loading