Skip to content

Commit

Permalink
Merge pull request #482 from raffis/feat-receiver-by-labels
Browse files Browse the repository at this point in the history
feat: support multi receiver by matchLabels
  • Loading branch information
makkes authored Mar 23, 2023
2 parents c32fed1 + ef8c973 commit f8ab99e
Show file tree
Hide file tree
Showing 7 changed files with 508 additions and 48 deletions.
2 changes: 2 additions & 0 deletions api/v1beta2/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CrossNamespaceObjectReference struct {
Kind string `json:"kind,omitempty"`

// Name of the referent.
// If multiple resources are targeted `*` may be set.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=53
// +required
Expand All @@ -44,6 +45,7 @@ type CrossNamespaceObjectReference struct {
// MatchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
// map is equivalent to an element of matchExpressions, whose key field is "key", the
// operator is "In", and the values array contains only "value". The requirements are ANDed.
// MatchLabels requires the name to be set to `*`.
// +optional
MatchLabels map[string]string `json:"matchLabels,omitempty"`
}
5 changes: 3 additions & 2 deletions config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ spec:
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
are ANDed. MatchLabels requires the name to be set to `*`.
type: object
name:
description: Name of the referent.
description: Name of the referent. If multiple resources are
targeted `*` may be set.
maxLength: 53
minLength: 1
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ spec:
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
are ANDed. MatchLabels requires the name to be set to `*`.
type: object
name:
description: Name of the referent.
description: Name of the referent. If multiple resources are
targeted `*` may be set.
maxLength: 53
minLength: 1
type: string
Expand Down
6 changes: 4 additions & 2 deletions docs/api/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ string
</em>
</td>
<td>
<p>Name of the referent.</p>
<p>Name of the referent.
If multiple resources are targeted <code>*</code> may be set.</p>
</td>
</tr>
<tr>
Expand All @@ -767,7 +768,8 @@ map[string]string
<em>(Optional)</em>
<p>MatchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is &ldquo;key&rdquo;, the
operator is &ldquo;In&rdquo;, and the values array contains only &ldquo;value&rdquo;. The requirements are ANDed.</p>
operator is &ldquo;In&rdquo;, and the values array contains only &ldquo;value&rdquo;. The requirements are ANDed.
MatchLabels requires the name to be set to <code>*</code>.</p>
</td>
</tr>
</tbody>
Expand Down
28 changes: 27 additions & 1 deletion docs/spec/v1beta2/receivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,35 @@ A resource entry contains the following fields:
`GitRepository`, `Kustomization`, `HelmRelease`, `HelmChart`,
`HelmRepository`, `ImageRepository`, `ImagePolicy`, `ImageUpdateAutomation`
and `OCIRepository`.
- `name`: The Flux Custom Resource `.metadata.name`.
- `name`: The Flux Custom Resource `.metadata.name` or it can be set to '*' wildcard(when `matchLabels` is specified)
- `namespace` (Optional): The Flux Custom Resource `.metadata.namespace`.
When not specified, the Receiver's `.metadata.namespace` is used instead.
- `matchLabels` (Optional): Annotate Flux Custom Resources with specific labels.
The `name` field must be set to '*' when using `matchLabels`

#### Annotate objects by name

To annotate single Flux object, set the `kind`, `name` and `namespace`:

```yaml
resources:
- apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
name: podinfo
```

#### Annotate objects by label

To annotate Flux objects of a particular kind with specific labels:

```yaml
resources:
- apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
name: "*"
matchLabels:
app: podinfo
```


**Note:** Cross-namespace references [can be disabled for security
Expand Down
Loading

0 comments on commit f8ab99e

Please sign in to comment.