Skip to content

Commit 056302c

Browse files
committed
rename mcgobctrigger to objectbucketsource
1 parent 3fc4f5c commit 056302c

21 files changed

Lines changed: 290 additions & 321 deletions

PLAN

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Multicloud Object Gateway Adapter (NooNaa)
22
==========================================
33

44
The adapter will be an HTTP server and/or Kafka consumer running in a pod inside a k8s cluster, configured in noobaa as "bucketNotifications" connection (either as HTTP notifications, or Kafka notifications)
5-
It will distribute the notifications received from NooBaa to individual triggers, according to the configuration specified by MCGOBCTrigger custom resources.
5+
It will distribute the notifications received from NooBaa to individual triggers, according to the configuration specified by OBCSource custom resources.
66
The notifications to individual triggers will be sent as cloudevents via HTTP or Kafka
77
It will be implemented in go, using k8s client libraries, the cloudevents k8s libraries, aws s3 client library, https://github.com/IBM/sarama, and the operator sdk (https://sdk.operatorframework.io)
88

@@ -58,26 +58,23 @@ calls put-bucket-notification for a bucket, it uses these values so that NooBaa
5858
knows where to deliver notifications (HTTP endpoint or Kafka topic, depending on
5959
NOTIFICATIONS_MODE).
6060

61-
Internal MCG/NooBaa trigger CRD
62-
-------------------------------
61+
ObjectBucketSource CRD
62+
----------------------------
6363

64-
an example CR from the MCGOBCTrigger:
64+
an example CR from the ObjectBucketSource:
6565
```
66-
apiVersion: internal.functions.dev/v1alpha1
67-
kind: MCGOBCTrigger
66+
apiVersion: sources.functions.dev/v1alpha1
67+
kind: ObjectBucketSource
6868
metadata:
6969
namespace: foobar
7070
name: foo
7171
spec:
72-
obc:
72+
objectBucketClaim:
7373
name: foo-bucket
7474
events:
7575
- "s3:ObjectCreated:*"
76-
triggers:
77-
- uri: http://foo.foobar.svc.cluster.local
78-
- uri: http://logger.foobar.svc.cluster.local
79-
- kafka:
80-
topic: foo-topic
76+
sink:
77+
uri: http://foo.foobar.svc.cluster.local
8178
status:
8279
conditions:
8380
- type: OBCCredentialsAvailable
@@ -88,7 +85,25 @@ status:
8885
status: "True"
8986
```
9087

91-
Where "obc" is a reference to an ObjectBucketClaim (living in the same namespace as the MCGOBCTrigger), e.g.:
88+
As an alternative, uri can point to a Kafka Topic:
89+
```
90+
apiVersion: sources.functions.dev/v1alpha1
91+
kind: ObjectBucketSource
92+
metadata:
93+
namespace: foobar
94+
name: foo
95+
spec:
96+
objectBucketClaim:
97+
name: foo-bucket
98+
events:
99+
- "s3:ObjectCreated:*"
100+
sink:
101+
uri: kafka:foo-topic
102+
status:
103+
...
104+
```
105+
106+
Where "objectBucketClaim" is a reference to an ObjectBucketClaim (living in the same namespace as the ObjectBucketSource), e.g.:
92107

93108

94109
```
@@ -207,13 +222,13 @@ for each record, the dispatcher will match the bucket name and eventName and fin
207222
(dropping the "s3:" prefix, and matching '*' at the end of the specified event name as meaning any suffix (like in this case, "ObjectCreated:Put" matching the specified "s3:ObjectCreated:*")
208223
To each such trigger, it will send the list of records as a cloudevent (it will keep the same JSON structure of the original, including thje Records list, but will filter out records not matching the rules.)
209224

210-
Multiple MCGOBCTrigger resources for the same bucket
225+
Multiple ObjectBucketSource resources for the same bucket
211226
----------------------------------------------------
212227

213-
When multiple MCGOBCTrigger CRs reference the same OBC (same bucket), the
228+
When multiple ObjectBucketSource CRs reference the same OBC (same bucket), the
214229
operator merges them internally into a single S3 bucket notification
215230
configuration. The merged configuration subscribes to the superset (union) of
216-
all event types requested across all MCGOBCTrigger CRs for that bucket.
231+
all event types requested across all ObjectBucketSource CRs for that bucket.
217232

218233
For example, if trigger A subscribes to "s3:ObjectCreated:*" and trigger B
219234
subscribes to "s3:ObjectRemoved:*", the operator issues a single
@@ -222,28 +237,28 @@ put-bucket-notification call with Events: ["s3:ObjectCreated:*",
222237

223238
When the adapter receives a notification from NooBaa, it filters the event
224239
internally before dispatching: each trigger URI only receives events matching
225-
the event types specified in its own MCGOBCTrigger CR. A trigger that subscribed
240+
the event types specified in its own ObjectBucketSource CR. A trigger that subscribed
226241
only to "s3:ObjectCreated:*" will never receive "s3:ObjectRemoved:*" events,
227242
even though the bucket-level notification is configured for both.
228243

229-
When a MCGOBCTrigger CR is deleted or updated, the operator recomputes the
244+
When a ObjectBucketSource CR is deleted or updated, the operator recomputes the
230245
merged event set for the affected bucket. If the superset shrinks (i.e., no
231246
remaining CR needs a previously included event type), the operator updates the
232-
S3 bucket notification configuration accordingly. If no MCGOBCTrigger CRs
247+
S3 bucket notification configuration accordingly. If no ObjectBucketSource CRs
233248
remain for a bucket, the operator removes the bucket notification entirely
234249

235250

236251
Finalizer and cleanup on deletion
237252
----------------------------------
238253

239-
The operator adds a finalizer (e.g., "internal.functions.dev/mcgobctrigger") to
240-
each MCGOBCTrigger CR on creation. When a MCGOBCTrigger CR is deleted, the
254+
The operator adds a finalizer (e.g., "sources.functions.dev/objectbucketsource") to
255+
each ObjectBucketSource CR on creation. When a ObjectBucketSource CR is deleted, the
241256
finalizer ensures the operator has a chance to clean up before the resource is
242257
removed from the API server. During finalization, the operator recomputes the
243258
merged event set for the affected bucket (excluding the CR being deleted). If
244-
other MCGOBCTrigger CRs still reference the same bucket, the operator updates
259+
other ObjectBucketSource CRs still reference the same bucket, the operator updates
245260
the S3 bucket notification configuration with the reduced event set. If no
246-
MCGOBCTrigger CRs remain for the bucket, the operator removes the bucket
261+
ObjectBucketSource CRs remain for the bucket, the operator removes the bucket
247262
notification from NooBaa entirely. Once cleanup is complete, the operator removes
248263
the finalizer, allowing Kubernetes to garbage-collect the CR.
249264

@@ -255,10 +270,10 @@ The adapter runs under a dedicated ServiceAccount. A ClusterRole grants the
255270
following permissions, bound via a ClusterRoleBinding:
256271

257272
- ConfigMaps and Secrets: cluster-wide read access (get, list, watch). This is
258-
required because MCGOBCTrigger CRs can exist in any namespace and the adapter
273+
required because ObjectBucketSource CRs can exist in any namespace and the adapter
259274
needs to read the OBC-associated ConfigMap and Secret from each CR's namespace.
260275

261-
- MCGOBCTrigger CRs (internal.functions.dev/v1alpha1): full access (get, list,
276+
- ObjectBucketSource CRs (sources.functions.dev/v1alpha1): full access (get, list,
262277
watch, create, update, patch, delete). The operator needs to watch for changes,
263278
update status conditions, and manage finalizers.
264279

PROJECT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ resources:
1616
namespaced: true
1717
controller: true
1818
domain: functions.dev
19-
group: internal
20-
kind: MCGOBCTrigger
19+
group: sources
20+
kind: ObjectBucketSource
2121
path: github.com/functions-dev/mcg-adapter/api/v1alpha1
2222
version: v1alpha1
2323
version: "3"

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
# MCG Adapter
22

3-
A Kubernetes operator that receives S3 bucket notifications from NooBaa (Multicloud Object Gateway) and dispatches them as CloudEvents to configured trigger endpoints.
3+
A Kubernetes operator that receives S3 bucket notifications from NooBaa (Multicloud Object Gateway) and dispatches them as CloudEvents to configured sink endpoints.
44

55
## Description
66

7-
The MCG Adapter runs inside a Kubernetes cluster, registered as a `bucketNotifications` connection in NooBaa. It can receive notifications via HTTP (default) or by consuming from a Kafka topic. It watches `MCGOBCTrigger` custom resources to determine which S3 events from which buckets should be forwarded to which endpoints. When NooBaa delivers a notification, the adapter matches the event against all configured triggers and dispatches CloudEvents via HTTP or Kafka to the matching endpoints.
7+
The MCG Adapter runs inside a Kubernetes cluster, registered as a `bucketNotifications` connection in NooBaa. It can receive notifications via HTTP (default) or by consuming from a Kafka topic. It watches `ObjectBucketSource` custom resources to determine which S3 events from which buckets should be forwarded to which endpoints. When NooBaa delivers a notification, the adapter matches the event against all configured sources and dispatches CloudEvents via HTTP or Kafka to the matching sinks.
88

9-
## Custom Resource: MCGOBCTrigger
9+
## Custom Resource: ObjectBucketSource
1010

1111
```yaml
12-
apiVersion: internal.functions.dev/v1alpha1
13-
kind: MCGOBCTrigger
12+
apiVersion: sources.functions.dev/v1alpha1
13+
kind: ObjectBucketSource
1414
metadata:
1515
namespace: foobar
1616
name: foo
1717
spec:
18-
obc:
18+
objectBucketClaim:
1919
name: foo-bucket # ObjectBucketClaim in the same namespace
2020
events:
2121
- "s3:ObjectCreated:*" # S3 event types to subscribe to
22-
triggers:
23-
- uri: http://foo.foobar.svc.cluster.local
24-
- uri: http://logger.foobar.svc.cluster.local
25-
- kafka:
26-
topic: foo-topic
22+
sink:
23+
uri: http://foo.foobar.svc.cluster.local
2724
```
2825
29-
Triggers can target HTTP endpoints (via `uri`) or Kafka topics (via `kafka.topic`). A single trigger entry can specify either or both. The Kafka broker(s) to connect to are configured globally via the `KAFKA_BROKERS` environment variable.
26+
The sink URI can be an HTTP endpoint or a Kafka topic reference (e.g. `kafka:foo-topic`). The Kafka broker(s) to connect to are configured globally via the `KAFKA_BROKERS` environment variable.
3027

3128
The controller manages three status conditions:
3229

3330
| Condition | Meaning |
3431
|---|---|
35-
| `OBCCredentialsAvailable` | The OBCs ConfigMap and Secret exist with the expected keys |
32+
| `OBCCredentialsAvailable` | The OBC's ConfigMap and Secret exist with the expected keys |
3633
| `BucketNotificationSet` | The S3 bucket notification was configured in NooBaa |
3734
| `TestEventReceived` | The test event sent by NooBaa after notification setup was received |
3835

39-
Multiple `MCGOBCTrigger` resources referencing the same OBC are merged into a single bucket notification configuration (union of event types). Each trigger only receives events matching its own subscription.
36+
Multiple `ObjectBucketSource` resources referencing the same OBC are merged into a single bucket notification configuration (union of event types). Each source only receives events matching its own subscription.
4037

4138
## Getting Started
4239

@@ -57,7 +54,7 @@ The adapter is configured via environment variables:
5754
| `ADAPTER_TOPIC` | `mcg-adapter-connection/connect.json` | NooBaa connection secret reference used as TopicArn in put-bucket-notification calls |
5855
| `ADAPTER_PORT` | `8888` | Port the notification HTTP server listens on (HTTP mode only) |
5956
| `NOTIFICATIONS_MODE` | `http` | `http` or `kafka` — selects how the adapter receives NooBaa notifications |
60-
| `KAFKA_BROKERS` | _(none)_ | Comma-separated list of Kafka broker addresses. Required for Kafka triggers and when `NOTIFICATIONS_MODE=kafka`. |
57+
| `KAFKA_BROKERS` | _(none)_ | Comma-separated list of Kafka broker addresses. Required for Kafka sinks and when `NOTIFICATIONS_MODE=kafka`. |
6158
| `KAFKA_SECRET` | _(none)_ | Name of a Kubernetes Secret (in the adapter's namespace) containing Kafka credentials. See `kafka-secret-format.md`. |
6259
| `KAFKA_NOTIFICATIONS_TOPIC` | _(none)_ | Kafka topic to consume NooBaa notifications from. Required when `NOTIFICATIONS_MODE=kafka`. |
6360
| `KAFKA_NOTIFICATIONS_GROUP_ID` | _(none)_ | Consumer group ID for consuming NooBaa notifications. Required when `NOTIFICATIONS_MODE=kafka`. |
@@ -86,20 +83,20 @@ EOF
8683

8784
```sh
8885
existing_connections=$(oc get noobaa noobaa -n openshift-storage -o json \
89-
| jq -c .spec.bucketNotifications.connections // [])
86+
| jq -c '.spec.bucketNotifications.connections // []')
9087
9188
updated_connections=$(echo "$existing_connections" | jq -c \
9289
--arg name "mcg-adapter-connection" \
93-
[.[] | select(.name != $name)] + [{"name": $name, "namespace": "openshift-storage"}])
90+
'[.[] | select(.name != $name)] + [{"name": $name, "namespace": "openshift-storage"}]')
9491
95-
oc patch noobaa noobaa --type=merge -n openshift-storage -p {
92+
oc patch noobaa noobaa --type='merge' -n openshift-storage -p '{
9693
"spec": {
9794
"bucketNotifications": {
98-
"connections": "${updated_connections}",
95+
"connections": '"${updated_connections}"',
9996
"enabled": true
10097
}
10198
}
102-
}
99+
}'
103100
```
104101

105102
### NooBaa Connection Setup (Kafka mode)
@@ -111,7 +108,7 @@ Summary of the one-time setup:
111108
1. Create a `KafkaTopic` (e.g. `mcg-adapter-notifications`) and `KafkaUser` resources in Strimzi
112109
2. Create a NooBaa connection secret with `notification_protocol: kafka` pointing to the Kafka bootstrap and topic
113110
3. Patch the NooBaa CR to register the Kafka connection
114-
4. Create a Kubernetes Secret in the adapters namespace with the adapters Kafka credentials (see `kafka-secret-format.md`)
111+
4. Create a Kubernetes Secret in the adapter's namespace with the adapter's Kafka credentials (see `kafka-secret-format.md`)
115112

116113
### Deploy
117114

@@ -159,4 +156,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
159156
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160157
See the License for the specific language governing permissions and
161158
limitations under the License.
162-

api/v1alpha1/groupversion_info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha1 contains API Schema definitions for the internal v1alpha1 API group.
17+
// Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group.
1818
// +kubebuilder:object:generate=true
19-
// +groupName=internal.functions.dev
19+
// +groupName=sources.functions.dev
2020
package v1alpha1
2121

2222
import (
@@ -26,7 +26,7 @@ import (
2626

2727
var (
2828
// GroupVersion is group version used to register these objects.
29-
GroupVersion = schema.GroupVersion{Group: "internal.functions.dev", Version: "v1alpha1"}
29+
GroupVersion = schema.GroupVersion{Group: "sources.functions.dev", Version: "v1alpha1"}
3030

3131
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,59 @@ const (
2525
ConditionBucketNotificationSet = "BucketNotificationSet"
2626
ConditionTestEventReceived = "TestEventReceived"
2727

28-
FinalizerName = "internal.functions.dev/mcgobctrigger"
28+
FinalizerName = "sources.functions.dev/objectbucketsource"
2929
)
3030

31-
// MCGOBCTriggerSpec defines the desired state of MCGOBCTrigger.
32-
type MCGOBCTriggerSpec struct {
33-
// OBC is a reference to the ObjectBucketClaim in the same namespace.
34-
OBC OBCReference `json:"obc"`
31+
// ObjectBucketSourceSpec defines the desired state of ObjectBucketSource.
32+
type ObjectBucketSourceSpec struct {
33+
// ObjectBucketClaim is a reference to the ObjectBucketClaim in the same namespace.
34+
ObjectBucketClaim OBCReference `json:"objectBucketClaim"`
3535
// Events is the list of S3 event types to subscribe to (e.g. "s3:ObjectCreated:*").
3636
Events []string `json:"events"`
37-
// Triggers is the list of endpoints to dispatch matching CloudEvents to.
38-
Triggers []TriggerTarget `json:"triggers"`
37+
// Sink is the endpoint to dispatch matching CloudEvents to.
38+
Sink SinkSpec `json:"sink"`
3939
}
4040

4141
type OBCReference struct {
4242
// Name of the ObjectBucketClaim in the same namespace.
4343
Name string `json:"name"`
4444
}
4545

46-
type TriggerTarget struct {
47-
// URI is the absolute URL to send CloudEvents to via HTTP.
48-
URI string `json:"uri,omitempty"`
49-
// Kafka identifies a Kafka topic to send CloudEvents to.
50-
Kafka *KafkaTrigger `json:"kafka,omitempty"`
46+
// SinkSpec defines the destination for CloudEvents. URI can be an HTTP URL
47+
// (e.g. "http://foo.bar.svc.cluster.local") or a Kafka topic reference
48+
// (e.g. "kafka:my-topic").
49+
type SinkSpec struct {
50+
// URI is the destination to send CloudEvents to. Use an HTTP URL for
51+
// HTTP delivery, or "kafka:<topic>" for Kafka delivery.
52+
URI string `json:"uri"`
5153
}
5254

53-
type KafkaTrigger struct {
54-
// Topic is the Kafka topic to produce CloudEvents to.
55-
Topic string `json:"topic"`
56-
}
57-
58-
// MCGOBCTriggerStatus defines the observed state of MCGOBCTrigger.
59-
type MCGOBCTriggerStatus struct {
55+
// ObjectBucketSourceStatus defines the observed state of ObjectBucketSource.
56+
type ObjectBucketSourceStatus struct {
6057
Conditions []metav1.Condition `json:"conditions,omitempty"`
6158
}
6259

6360
// +kubebuilder:object:root=true
6461
// +kubebuilder:subresource:status
6562

66-
// MCGOBCTrigger is the Schema for the mcgobctriggers API.
67-
type MCGOBCTrigger struct {
63+
// ObjectBucketSource is the Schema for the objectbucketsources API.
64+
type ObjectBucketSource struct {
6865
metav1.TypeMeta `json:",inline"`
6966
metav1.ObjectMeta `json:"metadata,omitempty"`
7067

71-
Spec MCGOBCTriggerSpec `json:"spec,omitempty"`
72-
Status MCGOBCTriggerStatus `json:"status,omitempty"`
68+
Spec ObjectBucketSourceSpec `json:"spec,omitempty"`
69+
Status ObjectBucketSourceStatus `json:"status,omitempty"`
7370
}
7471

7572
// +kubebuilder:object:root=true
7673

77-
// MCGOBCTriggerList contains a list of MCGOBCTrigger.
78-
type MCGOBCTriggerList struct {
74+
// ObjectBucketSourceList contains a list of ObjectBucketSource.
75+
type ObjectBucketSourceList struct {
7976
metav1.TypeMeta `json:",inline"`
8077
metav1.ListMeta `json:"metadata,omitempty"`
81-
Items []MCGOBCTrigger `json:"items"`
78+
Items []ObjectBucketSource `json:"items"`
8279
}
8380

8481
func init() {
85-
SchemeBuilder.Register(&MCGOBCTrigger{}, &MCGOBCTriggerList{})
82+
SchemeBuilder.Register(&ObjectBucketSource{}, &ObjectBucketSourceList{})
8683
}

0 commit comments

Comments
 (0)