diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index f63bcf636..1ce0f9f66 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -49,6 +49,19 @@ jobs: KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin - name: Load test image run: kind load docker-image test/notification-controller:latest + - name: Install CRDs + run: make install + - name: Run default status test + run: | + kubectl apply -f config/testdata/status-defaults + for crd in alert provider receiver ; do + RESULT=$(kubectl get ${crd} status-defaults -o go-template={{.status}}) + EXPECTED='map[observedGeneration:-1]' + if [ "${RESULT}" != "${EXPECTED}" ] ; then + echo -e "${RESULT}\n\ndoes not equal\n\n${EXPECTED} for CRD ${crd}" + exit 1 + fi + done - name: Deploy controller run: | make dev-deploy IMG=test/notification-controller:latest diff --git a/api/v1beta1/alert_types.go b/api/v1beta1/alert_types.go index 9d80802ce..0e8c30f04 100644 --- a/api/v1beta1/alert_types.go +++ b/api/v1beta1/alert_types.go @@ -79,7 +79,8 @@ type Alert struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec AlertSpec `json:"spec,omitempty"` + Spec AlertSpec `json:"spec,omitempty"` + // +kubebuilder:default:={"observedGeneration":-1} Status AlertStatus `json:"status,omitempty"` } diff --git a/api/v1beta1/provider_types.go b/api/v1beta1/provider_types.go index 57a976baa..b5eb1ddd1 100644 --- a/api/v1beta1/provider_types.go +++ b/api/v1beta1/provider_types.go @@ -84,6 +84,9 @@ const ( // ProviderStatus defines the observed state of Provider type ProviderStatus struct { + // ObservedGeneration is the last reconciled generation. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` // +optional Conditions []metav1.Condition `json:"conditions,omitempty"` } @@ -101,7 +104,8 @@ type Provider struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ProviderSpec `json:"spec,omitempty"` + Spec ProviderSpec `json:"spec,omitempty"` + // +kubebuilder:default:={"observedGeneration":-1} Status ProviderStatus `json:"status,omitempty"` } diff --git a/api/v1beta1/receiver_types.go b/api/v1beta1/receiver_types.go index 07f3438bf..a87b23bdb 100644 --- a/api/v1beta1/receiver_types.go +++ b/api/v1beta1/receiver_types.go @@ -109,7 +109,8 @@ type Receiver struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ReceiverSpec `json:"spec,omitempty"` + Spec ReceiverSpec `json:"spec,omitempty"` + // +kubebuilder:default:={"observedGeneration":-1} Status ReceiverStatus `json:"status,omitempty"` } diff --git a/config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml b/config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml index a5e214826..f944b0762 100644 --- a/config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml +++ b/config/crd/bases/notification.toolkit.fluxcd.io_alerts.yaml @@ -109,6 +109,8 @@ spec: - providerRef type: object status: + default: + observedGeneration: -1 description: AlertStatus defines the observed state of Alert properties: conditions: diff --git a/config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml b/config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml index 0904d7cbf..091f1d5e8 100644 --- a/config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml +++ b/config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml @@ -98,6 +98,8 @@ spec: - type type: object status: + default: + observedGeneration: -1 description: ProviderStatus defines the observed state of Provider properties: conditions: @@ -143,6 +145,10 @@ spec: - type type: object type: array + observedGeneration: + description: ObservedGeneration is the last reconciled generation. + format: int64 + type: integer type: object type: object served: true diff --git a/config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml b/config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml index e1e8b4b66..9d530579d 100644 --- a/config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml +++ b/config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml @@ -114,6 +114,8 @@ spec: - type type: object status: + default: + observedGeneration: -1 description: ReceiverStatus defines the observed state of Receiver properties: conditions: diff --git a/config/testdata/provider.yaml b/config/testdata/provider.yaml new file mode 100644 index 000000000..476d97c93 --- /dev/null +++ b/config/testdata/provider.yaml @@ -0,0 +1,8 @@ +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta1 +kind: Provider +metadata: + name: status-defaults +spec: + type: generic + diff --git a/config/testdata/status-defaults/alert.yaml b/config/testdata/status-defaults/alert.yaml new file mode 100644 index 000000000..40bec30ad --- /dev/null +++ b/config/testdata/status-defaults/alert.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta1 +kind: Alert +metadata: + name: status-defaults diff --git a/config/testdata/status-defaults/provider.yaml b/config/testdata/status-defaults/provider.yaml new file mode 100644 index 000000000..27e8372fe --- /dev/null +++ b/config/testdata/status-defaults/provider.yaml @@ -0,0 +1,4 @@ +apiVersion: notification.toolkit.fluxcd.io/v1beta1 +kind: Provider +metadata: + name: status-defaults diff --git a/config/testdata/status-defaults/receiver.yaml b/config/testdata/status-defaults/receiver.yaml new file mode 100644 index 000000000..254f51afb --- /dev/null +++ b/config/testdata/status-defaults/receiver.yaml @@ -0,0 +1,4 @@ +apiVersion: notification.toolkit.fluxcd.io/v1beta1 +kind: Receiver +metadata: + name: status-defaults diff --git a/docs/api/notification.md b/docs/api/notification.md index d2489a23c..9932d4775 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -814,6 +814,18 @@ a PEM-encoded CA certificate (caFile)

+observedGeneration
+ +int64 + + + +(Optional) +

ObservedGeneration is the last reconciled generation.

+ + + + conditions