Skip to content

Commit

Permalink
remove all references to v1beta2.CrossNamespaceObjectReference
Browse files Browse the repository at this point in the history
This change also requires a change in how the API docs are generated to avoid
the following warning to be emitted by `gen-crd-api-reference-docs`:

```
W0330 10:52:35.052255   76278 main.go:442] not found external link source for type github.com/fluxcd/notification-controller/api/v1.CrossNamespaceObjectReference
```

Now, references to `v1.CrossNamespaceObjectReference` are linked to pkg.go.dev.

Signed-off-by: Max Jonas Werner <mail@makk.es>
  • Loading branch information
Max Jonas Werner committed Mar 30, 2023
1 parent d1a673f commit af686a3
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 86 deletions.
4 changes: 3 additions & 1 deletion api/v1beta2/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1beta2
import (
"github.com/fluxcd/pkg/apis/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/notification-controller/api/v1"
)

const (
Expand All @@ -41,7 +43,7 @@ type AlertSpec struct {
// EventSources specifies how to filter events based
// on the involved object kind, name and namespace.
// +required
EventSources []CrossNamespaceObjectReference `json:"eventSources"`
EventSources []v1.CrossNamespaceObjectReference `json:"eventSources"`

// ExclusionList specifies a list of Golang regular expressions
// to be used for excluding messages.
Expand Down
4 changes: 3 additions & 1 deletion api/v1beta2/receiver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"

v1 "github.com/fluxcd/notification-controller/api/v1"
)

const (
Expand Down Expand Up @@ -63,7 +65,7 @@ type ReceiverSpec struct {

// A list of resources to be notified about changes.
// +required
Resources []CrossNamespaceObjectReference `json:"resources"`
Resources []v1.CrossNamespaceObjectReference `json:"resources"`

// SecretRef specifies the Secret containing the token used
// to validate the payload authenticity.
Expand Down
19 changes: 10 additions & 9 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ spec:
to let you locate the typed referenced object at cluster level
properties:
apiVersion:
description: API version of the referent.
description: API version of the referent
type: string
kind:
description: Kind of the referent.
description: Kind of the referent
enum:
- Bucket
- GitRepository
Expand All @@ -279,19 +279,21 @@ 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
namespace:
description: Namespace of the referent.
description: Namespace of the referent
maxLength: 53
minLength: 1
type: string
required:
- kind
- name
type: object
type: array
Expand Down
12 changes: 7 additions & 5 deletions config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ spec:
to let you locate the typed referenced object at cluster level
properties:
apiVersion:
description: API version of the referent.
description: API version of the referent
type: string
kind:
description: Kind of the referent.
description: Kind of the referent
enum:
- Bucket
- GitRepository
Expand All @@ -516,19 +516,21 @@ 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
namespace:
description: Namespace of the referent.
description: Namespace of the referent
maxLength: 53
minLength: 1
type: string
required:
- kind
- name
type: object
type: array
Expand Down
29 changes: 15 additions & 14 deletions controllers/alert_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,37 @@ import (
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/conditions"

apiv1 "github.com/fluxcd/notification-controller/api/v1beta2"
apiv1beta2 "github.com/fluxcd/notification-controller/api/v1beta2"
apiv1 "github.com/fluxcd/notification-controller/api/v1"
"github.com/fluxcd/notification-controller/internal/server"
)

func TestAlertReconciler_Reconcile(t *testing.T) {
g := NewWithT(t)
timeout := 5 * time.Second
resultA := &apiv1.Alert{}
resultA := &apiv1beta2.Alert{}
namespaceName := "alert-" + randStringRunes(5)
providerName := "provider-" + randStringRunes(5)

g.Expect(createNamespace(namespaceName)).NotTo(HaveOccurred(), "failed to create test namespace")

provider := &apiv1.Provider{
provider := &apiv1beta2.Provider{
ObjectMeta: metav1.ObjectMeta{
Name: providerName,
Namespace: namespaceName,
},
Spec: apiv1.ProviderSpec{
Spec: apiv1beta2.ProviderSpec{
Type: "generic",
Address: "https://webhook.internal",
},
}

alert := &apiv1.Alert{
alert := &apiv1beta2.Alert{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("alert-%s", randStringRunes(5)),
Namespace: namespaceName,
},
Spec: apiv1.AlertSpec{
Spec: apiv1beta2.AlertSpec{
ProviderRef: meta.LocalObjectReference{
Name: providerName,
},
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestAlertReconciler_Reconcile(t *testing.T) {
g.Expect(conditions.Has(resultA, meta.ReconcilingCondition)).To(BeTrue())
g.Expect(conditions.GetReason(resultA, meta.ReconcilingCondition)).To(BeIdenticalTo(meta.ProgressingWithRetryReason))
g.Expect(conditions.GetObservedGeneration(resultA, meta.ReconcilingCondition)).To(BeIdenticalTo(resultA.Generation))
g.Expect(controllerutil.ContainsFinalizer(resultA, apiv1.NotificationFinalizer)).To(BeTrue())
g.Expect(controllerutil.ContainsFinalizer(resultA, apiv1beta2.NotificationFinalizer)).To(BeTrue())
})

t.Run("recovers when provider exists", func(t *testing.T) {
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestAlertReconciler_EventHandler(t *testing.T) {
var (
namespace = "events-" + randStringRunes(5)
req *http.Request
provider *apiv1.Provider
provider *apiv1beta2.Provider
)
g.Expect(createNamespace(namespace)).NotTo(HaveOccurred(), "failed to create test namespace")

Expand Down Expand Up @@ -196,19 +197,19 @@ func TestAlertReconciler_EventHandler(t *testing.T) {
Name: fmt.Sprintf("provider-%s", randStringRunes(5)),
Namespace: namespace,
}
provider = &apiv1.Provider{
provider = &apiv1beta2.Provider{
ObjectMeta: metav1.ObjectMeta{
Name: providerKey.Name,
Namespace: providerKey.Namespace,
},
Spec: apiv1.ProviderSpec{
Spec: apiv1beta2.ProviderSpec{
Type: "generic",
Address: rcvServer.URL,
},
}
g.Expect(k8sClient.Create(context.Background(), provider)).To(Succeed())
g.Eventually(func() bool {
var obj apiv1.Provider
var obj apiv1beta2.Provider
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(provider), &obj))
return conditions.IsReady(&obj)
}, 30*time.Second, time.Second).Should(BeTrue())
Expand All @@ -234,12 +235,12 @@ func TestAlertReconciler_EventHandler(t *testing.T) {
Namespace: namespace,
}

alert := &apiv1.Alert{
alert := &apiv1beta2.Alert{
ObjectMeta: metav1.ObjectMeta{
Name: alertKey.Name,
Namespace: alertKey.Namespace,
},
Spec: apiv1.AlertSpec{
Spec: apiv1beta2.AlertSpec{
ProviderRef: meta.LocalObjectReference{
Name: providerKey.Name,
},
Expand Down Expand Up @@ -278,7 +279,7 @@ func TestAlertReconciler_EventHandler(t *testing.T) {

// wait for controller to mark the alert as ready
g.Eventually(func() bool {
var obj apiv1.Alert
var obj apiv1beta2.Alert
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(alert), &obj))
return conditions.IsReady(&obj)
}, 30*time.Second, time.Second).Should(BeTrue())
Expand Down
10 changes: 5 additions & 5 deletions docs/api/v1/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ the validation procedure and payload deserialization.</p>
<td>
<code>interval</code><br>
<em>
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
<a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
Kubernetes meta/v1.Duration
</a>
</em>
Expand Down Expand Up @@ -124,7 +124,7 @@ e.g. &lsquo;push&rsquo; for GitHub or &lsquo;Push Hook&rsquo; for GitLab.</p>
<td>
<code>secretRef</code><br>
<em>
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
<a href="https://pkg.go.dev/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
github.com/fluxcd/pkg/apis/meta.LocalObjectReference
</a>
</em>
Expand Down Expand Up @@ -283,7 +283,7 @@ the validation procedure and payload deserialization.</p>
<td>
<code>interval</code><br>
<em>
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
<a href="https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
Kubernetes meta/v1.Duration
</a>
</em>
Expand Down Expand Up @@ -323,7 +323,7 @@ e.g. &lsquo;push&rsquo; for GitHub or &lsquo;Push Hook&rsquo; for GitLab.</p>
<td>
<code>secretRef</code><br>
<em>
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
<a href="https://pkg.go.dev/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
github.com/fluxcd/pkg/apis/meta.LocalObjectReference
</a>
</em>
Expand Down Expand Up @@ -371,7 +371,7 @@ events handling for this receiver.</p>
<td>
<code>ReconcileRequestStatus</code><br>
<em>
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/meta#ReconcileRequestStatus">
<a href="https://pkg.go.dev/github.com/fluxcd/pkg/apis/meta#ReconcileRequestStatus">
github.com/fluxcd/pkg/apis/meta.ReconcileRequestStatus
</a>
</em>
Expand Down
Loading

0 comments on commit af686a3

Please sign in to comment.