Skip to content

Commit

Permalink
Observed generation (#637)
Browse files Browse the repository at this point in the history
* Set status.observedGeneration in RabbitmqCluster
* Add timeout to observedGeneration system test
  • Loading branch information
ChunyiLyu authored Apr 9, 2021
1 parent 86bced0 commit 6dbc83d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/v1beta1/rabbitmqcluster_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type RabbitmqClusterStatus struct {
// RabbitmqCluster. It implements the service binding Provisioned Service
// duck type. See: https://k8s-service-bindings.github.io/spec/#provisioned-service
Binding *corev1.LocalObjectReference `json:"binding,omitempty"`

// observedGeneration is the most recent successful generation observed for this RabbitmqCluster. It corresponds to the
// RabbitmqCluster's generation, which is updated on mutation by the API Server.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// Contains references to resources created with the RabbitmqCluster resource.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,10 @@ spec:
- namespace
type: object
type: object
observedGeneration:
description: observedGeneration is the most recent successful generation observed for this RabbitmqCluster. It corresponds to the RabbitmqCluster's generation, which is updated on mutation by the API Server.
format: int64
type: integer
required:
- conditions
type: object
Expand Down
3 changes: 2 additions & 1 deletion controllers/rabbitmqcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func (r *RabbitmqClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{RequeueAfter: requeueAfter}, err
}

// Set ReconcileSuccess to true after all reconciliation steps have finished with no error
// Set ReconcileSuccess to true and update observedGeneration after all reconciliation steps have finished with no error
rabbitmqCluster.Status.ObservedGeneration = rabbitmqCluster.GetGeneration()
rabbitmqCluster.Status.SetCondition(status.ReconcileSuccess, corev1.ConditionTrue, "Success", "Finish reconciling")
if writerErr := r.Status().Update(ctx, rabbitmqCluster); writerErr != nil {
logger.Error(writerErr, "Failed to Update Custom Resource status")
Expand Down
1 change: 1 addition & 0 deletions docs/api/rabbitmq.com.ref.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ Status presents the observed state of RabbitmqCluster
| *`conditions`* __xref:{anchor_prefix}-github.aaakk.us.kg-rabbitmq-cluster-operator-internal-status-rabbitmqclustercondition[$$RabbitmqClusterCondition$$] array__ | Set of Conditions describing the current state of the RabbitmqCluster
| *`defaultUser`* __xref:{anchor_prefix}-github.aaakk.us.kg-rabbitmq-cluster-operator-api-v1beta1-rabbitmqclusterdefaultuser[$$RabbitmqClusterDefaultUser$$]__ | Identifying information on internal resources
| *`binding`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#localobjectreference-v1-core[$$LocalObjectReference$$]__ | Binding exposes a secret containing the binding information for this RabbitmqCluster. It implements the service binding Provisioned Service duck type. See: https://k8s-service-bindings.github.io/spec/#provisioned-service
| *`observedGeneration`* __integer__ | observedGeneration is the most recent successful generation observed for this RabbitmqCluster. It corresponds to the RabbitmqCluster's generation, which is updated on mutation by the API Server.
|===


Expand Down
9 changes: 9 additions & 0 deletions system_tests/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"encoding/json"
"io/ioutil"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -106,6 +107,14 @@ var _ = Describe("Operator", func() {
}, 30, 2).Should(Equal("'True'"))
})

By("setting observedGeneration", func() {
fetchedRmq := &rabbitmqv1beta1.RabbitmqCluster{}
Eventually(func() bool {
Expect(rmqClusterClient.Get(ctx, types.NamespacedName{Name: cluster.Name, Namespace: cluster.Namespace}, fetchedRmq)).To(Succeed())
return fetchedRmq.Status.ObservedGeneration == fetchedRmq.Generation
}, 30).Should(BeTrue())
})

By("having all feature flags enabled", func() {
Eventually(func() []featureFlag {
output, err := kubectlExec(namespace,
Expand Down

0 comments on commit 6dbc83d

Please sign in to comment.