Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit d497549

Browse files
author
odacremolbap
committed
minimum set of features, not tested
1 parent 3e328e2 commit d497549

File tree

5 files changed

+233
-207
lines changed

5 files changed

+233
-207
lines changed

cmd/triggermesh-hook/start/start.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
commoncmd "github.com/triggermesh/scoby-hook-triggermesh/pkg/common/cmd"
88
"github.com/triggermesh/scoby-hook-triggermesh/pkg/handler"
99
"github.com/triggermesh/scoby-hook-triggermesh/pkg/handler/kuards"
10-
"github.com/triggermesh/scoby-hook-triggermesh/pkg/handler/sources/awss3"
10+
"github.com/triggermesh/scoby-hook-triggermesh/pkg/sources/client/s3"
11+
"github.com/triggermesh/scoby-hook-triggermesh/pkg/sources/reconciler/awss3source"
1112

1213
"github.com/triggermesh/scoby-hook-triggermesh/pkg/server"
1314
)
@@ -23,7 +24,7 @@ func (c *Cmd) Run(g *commoncmd.Globals) error {
2324
r := handler.NewRegistry([]handler.Handler{
2425
// Kuards is a temporary playground
2526
kuards.New(),
26-
awss3.New(),
27+
awss3source.New(s3.NewClientGetter(g.KubeClient.CoreV1().Secrets), g.Logger),
2728
})
2829

2930
s := server.New(c.Path, c.Address, r, g.DynClient, g.Logger)

pkg/handler/sources/awss3source/handler.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

pkg/handler/sources/awss3source/bucket.go renamed to pkg/sources/reconciler/awss3source/bucket.go

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,108 +23,74 @@ import (
2323
"net/http"
2424
"sort"
2525

26-
corev1 "k8s.io/api/core/v1"
2726
apierrors "k8s.io/apimachinery/pkg/api/errors"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928

30-
"knative.dev/pkg/controller"
31-
"knative.dev/pkg/reconciler"
32-
3329
"github.com/aws/aws-sdk-go/aws"
3430
"github.com/aws/aws-sdk-go/aws/awserr"
3531
"github.com/aws/aws-sdk-go/aws/credentials"
3632
"github.com/aws/aws-sdk-go/service/s3"
3733
"github.com/aws/aws-sdk-go/service/s3/s3iface"
3834
"github.com/aws/aws-sdk-go/service/sqs"
3935

40-
commonv1alpha1 "github.com/triggermesh/triggermesh/pkg/apis/common/v1alpha1"
41-
"github.com/triggermesh/triggermesh/pkg/apis/sources/v1alpha1"
42-
"github.com/triggermesh/triggermesh/pkg/reconciler/event"
36+
"github.com/triggermesh/scoby-hook-triggermesh/pkg/apis/sources/v1alpha1"
4337
)
4438

4539
// EnsureNotificationsEnabled ensures that event notifications are enabled in
4640
// the S3 bucket.
47-
func EnsureNotificationsEnabled(ctx context.Context, cli s3iface.S3API, queueARN string) error {
48-
src := commonv1alpha1.ReconcilableFromContext(ctx)
49-
typedSrc := src.(*v1alpha1.AWSS3Source)
50-
51-
status := &typedSrc.Status
52-
53-
bucketARN := typedSrc.Spec.ARN
41+
func EnsureNotificationsEnabled(ctx context.Context, src *v1alpha1.AWSS3Source, cli s3iface.S3API, queueARN string) error {
42+
bucketARN := src.Spec.ARN
5443

5544
notifCfg, err := getNotificationsConfig(ctx, cli, bucketARN.Resource)
5645
switch {
5746
case isNotFound(err):
58-
status.MarkNotSubscribed(v1alpha1.AWSS3ReasonNoBucket, "Bucket does not exist")
59-
return controller.NewPermanentError(reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedSubscribe,
60-
"The bucket does not exist: %s", toErrMsg(err)))
47+
return fmt.Errorf("The bucket does not exist: %v", toErrMsg(err))
6148
case isAWSError(err):
6249
// All documented API errors require some user intervention and
6350
// are not to be retried.
6451
// https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
65-
status.MarkNotSubscribed(v1alpha1.AWSS3ReasonAPIError, "Request to S3 API got rejected")
66-
return controller.NewPermanentError(reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedSubscribe,
67-
"Failed to synchronize bucket configuration: %s", toErrMsg(err)))
52+
return fmt.Errorf("Failed to synchronize bucket configuration: %v", toErrMsg(err))
6853
case err != nil:
69-
status.MarkNotSubscribed(v1alpha1.AWSS3ReasonAPIError, "Cannot obtain current bucket configuration")
70-
// wrap any other error to fail the reconciliation
71-
return fmt.Errorf("%w", reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedSubscribe,
72-
"Error reading current event notifications configuration: %s", toErrMsg(err)))
54+
return fmt.Errorf("Cannot obtain current bucket configuration: %v", toErrMsg(err))
7355
}
7456

75-
desiredQueueCfg := makeQueueConfiguration(typedSrc, queueARN)
57+
desiredQueueCfg := makeQueueConfiguration(src, queueARN)
7658

7759
notifCfg, hasUpdates := setQueueConfiguration(notifCfg, desiredQueueCfg)
7860

7961
if hasUpdates {
8062
if err := configureNotifications(ctx, cli, bucketARN.Resource, notifCfg); err != nil {
81-
status.MarkNotSubscribed(v1alpha1.AWSS3ReasonAPIError, "Cannot configure event notifications")
82-
return fmt.Errorf("%w", reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedSubscribe,
83-
"Error configuring event notifications: %s", toErrMsg(err)))
63+
return fmt.Errorf("Cannot configure event notifications: %v", toErrMsg(err))
8464
}
8565
}
8666

87-
if !status.GetCondition(v1alpha1.AWSS3ConditionSubscribed).IsTrue() {
88-
event.Normal(ctx, ReasonSubscribed, "Configured event notifications for S3 bucket %q", bucketARN)
89-
}
90-
status.MarkSubscribed()
91-
9267
return nil
9368
}
9469

9570
// EnsureNotificationsDisabled ensures that event notifications are disabled in
9671
// the S3 bucket.
97-
func EnsureNotificationsDisabled(ctx context.Context, cli s3iface.S3API) error {
98-
src := commonv1alpha1.ReconcilableFromContext(ctx)
99-
typedSrc := src.(*v1alpha1.AWSS3Source)
100-
101-
bucketARN := typedSrc.Spec.ARN
72+
func EnsureNotificationsDisabled(ctx context.Context, src *v1alpha1.AWSS3Source, cli s3iface.S3API) error {
73+
bucketARN := src.Spec.ARN
10274

10375
notifCfg, err := getNotificationsConfig(ctx, cli, bucketARN.Resource)
10476
switch {
10577
case isNotFound(err):
106-
return reconciler.NewEvent(corev1.EventTypeNormal, ReasonUnsubscribed,
107-
"Bucket not found, skipping finalization")
78+
return fmt.Errorf("Bucket not found: %v", toErrMsg(err))
10879
case isDenied(err):
10980
// it is unlikely that we recover from auth errors in the
11081
// finalizer, so we simply record a warning event and return
111-
event.Warn(ctx, ReasonFailedUnsubscribe,
112-
"Authorization error getting bucket configuration. Ignoring: %s", toErrMsg(err))
113-
return nil
82+
return fmt.Errorf("Authorization error getting bucket configuration: %v", toErrMsg(err))
11483
case err != nil:
115-
return reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedUnsubscribe,
116-
"Error reading current event notifications configuration: %s", toErrMsg(err))
84+
return fmt.Errorf("Error reading current event notifications configuration: %v", toErrMsg(err))
11785
}
11886

11987
notifCfg = removeQueueConfiguration(notifCfg, sourceID(src))
12088

12189
if err := configureNotifications(ctx, cli, bucketARN.Resource, notifCfg); err != nil {
122-
return fmt.Errorf("%w", reconciler.NewEvent(corev1.EventTypeWarning, ReasonFailedUnsubscribe,
123-
"Error configuring event notifications: %s", toErrMsg(err)))
90+
return fmt.Errorf("Error configuring event notifications: %v", toErrMsg(err))
12491
}
12592

126-
return reconciler.NewEvent(corev1.EventTypeNormal, ReasonUnsubscribed,
127-
"Disabled event notifications for S3 bucket %q", bucketARN)
93+
return nil
12894
}
12995

13096
// getNotificationsConfig reads the current event notifications configuration

0 commit comments

Comments
 (0)