Skip to content

Commit 2d55e60

Browse files
author
Max Jonas Werner
committed
feat: set default observedGeneration to -1 on CRDs
This sets the `status.observedGeneration` field to -1 by default. This is a follow-up to fluxcd/helm-controller#294, porting the same code to the notification-controller so that all Flux 2 controllers work the same way in this regard. Signed-off-by: Max Jonas Werner <mail@makk.es>
1 parent e6ae24e commit 2d55e60

12 files changed

+65
-3
lines changed

.github/workflows/e2e.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ jobs:
4949
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
5050
- name: Load test image
5151
run: kind load docker-image test/notification-controller:latest
52+
- name: Install CRDs
53+
run: make install
54+
- name: Run default status test
55+
run: |
56+
kubectl apply -f config/testdata/status-defaults
57+
for crd in alert provider receiver ; do
58+
RESULT=$(kubectl get ${crd} status-defaults -o go-template={{.status}})
59+
EXPECTED='map[observedGeneration:-1]'
60+
if [ "${RESULT}" != "${EXPECTED}" ] ; then
61+
echo -e "${RESULT}\n\ndoes not equal\n\n${EXPECTED} for CRD ${crd}"
62+
exit 1
63+
fi
64+
done
5265
- name: Deploy controller
5366
run: |
5467
make dev-deploy IMG=test/notification-controller:latest

api/v1beta1/alert_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ type Alert struct {
7979
metav1.TypeMeta `json:",inline"`
8080
metav1.ObjectMeta `json:"metadata,omitempty"`
8181

82-
Spec AlertSpec `json:"spec,omitempty"`
82+
Spec AlertSpec `json:"spec,omitempty"`
83+
// +kubebuilder:default:={"observedGeneration":-1}
8384
Status AlertStatus `json:"status,omitempty"`
8485
}
8586

api/v1beta1/provider_types.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484

8585
// ProviderStatus defines the observed state of Provider
8686
type ProviderStatus struct {
87+
// ObservedGeneration is the last reconciled generation.
88+
// +optional
89+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
8790
// +optional
8891
Conditions []metav1.Condition `json:"conditions,omitempty"`
8992
}
@@ -101,7 +104,8 @@ type Provider struct {
101104
metav1.TypeMeta `json:",inline"`
102105
metav1.ObjectMeta `json:"metadata,omitempty"`
103106

104-
Spec ProviderSpec `json:"spec,omitempty"`
107+
Spec ProviderSpec `json:"spec,omitempty"`
108+
// +kubebuilder:default:={"observedGeneration":-1}
105109
Status ProviderStatus `json:"status,omitempty"`
106110
}
107111

api/v1beta1/receiver_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ type Receiver struct {
109109
metav1.TypeMeta `json:",inline"`
110110
metav1.ObjectMeta `json:"metadata,omitempty"`
111111

112-
Spec ReceiverSpec `json:"spec,omitempty"`
112+
Spec ReceiverSpec `json:"spec,omitempty"`
113+
// +kubebuilder:default:={"observedGeneration":-1}
113114
Status ReceiverStatus `json:"status,omitempty"`
114115
}
115116

config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ spec:
109109
- providerRef
110110
type: object
111111
status:
112+
default:
113+
observedGeneration: -1
112114
description: AlertStatus defines the observed state of Alert
113115
properties:
114116
conditions:

config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ spec:
9898
- type
9999
type: object
100100
status:
101+
default:
102+
observedGeneration: -1
101103
description: ProviderStatus defines the observed state of Provider
102104
properties:
103105
conditions:
@@ -143,6 +145,10 @@ spec:
143145
- type
144146
type: object
145147
type: array
148+
observedGeneration:
149+
description: ObservedGeneration is the last reconciled generation.
150+
format: int64
151+
type: integer
146152
type: object
147153
type: object
148154
served: true

config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ spec:
114114
- type
115115
type: object
116116
status:
117+
default:
118+
observedGeneration: -1
117119
description: ReceiverStatus defines the observed state of Receiver
118120
properties:
119121
conditions:

config/testdata/provider.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: notification.toolkit.fluxcd.io/v1beta1
3+
kind: Provider
4+
metadata:
5+
name: status-defaults
6+
spec:
7+
type: generic
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
apiVersion: notification.toolkit.fluxcd.io/v1beta1
3+
kind: Alert
4+
metadata:
5+
name: status-defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: notification.toolkit.fluxcd.io/v1beta1
2+
kind: Provider
3+
metadata:
4+
name: status-defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: notification.toolkit.fluxcd.io/v1beta1
2+
kind: Receiver
3+
metadata:
4+
name: status-defaults

docs/api/notification.md

+12
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,18 @@ a PEM-encoded CA certificate (<code>caFile</code>)</p>
814814
<tbody>
815815
<tr>
816816
<td>
817+
<code>observedGeneration</code><br>
818+
<em>
819+
int64
820+
</em>
821+
</td>
822+
<td>
823+
<em>(Optional)</em>
824+
<p>ObservedGeneration is the last reconciled generation.</p>
825+
</td>
826+
</tr>
827+
<tr>
828+
<td>
817829
<code>conditions</code><br>
818830
<em>
819831
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#condition-v1-meta">

0 commit comments

Comments
 (0)