Skip to content

Commit

Permalink
Add observedGeneration to OperatorPolicy status
Browse files Browse the repository at this point in the history
This can be useful to know if the controller has updated the status
based on any updates tothe policy yet. It matches a common field used in
core kubernetes objects.

Refs:
 - https://issues.redhat.com/browse/ACM-12804

Signed-off-by: Justin Kulikauskas <[email protected]>
  • Loading branch information
JustinKuli authored and openshift-merge-bot[bot] committed Jul 30, 2024
1 parent db2022d commit 44c8723
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/operatorpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ type OperatorPolicyStatus struct {
// ComplianceState reports the most recent compliance state of the operator policy.
ComplianceState policyv1.ComplianceState `json:"compliant,omitempty"`

// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Conditions includes historic details on the condition of the operator policy.
//
//+listType=map
Expand Down
9 changes: 7 additions & 2 deletions controllers/operatorpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func updateStatus(
if condChanged {
updatedComplianceCondition := calculateComplianceCondition(policy)

compCondIdx, _ := policy.Status.GetCondition(updatedComplianceCondition.Type)
compCondIdx, _ := policy.Status.GetCondition(compliantConditionType)
if compCondIdx == -1 {
policy.Status.Conditions = append(policy.Status.Conditions, updatedComplianceCondition)
} else {
Expand Down Expand Up @@ -148,7 +148,12 @@ func updateStatus(
}
}

return condChanged || relObjsChanged
genUpdated := policy.ObjectMeta.Generation != policy.Status.ObservedGeneration
if genUpdated {
policy.Status.ObservedGeneration = policy.ObjectMeta.Generation
}

return condChanged || relObjsChanged || genUpdated
}

func conditionChanged(updatedCondition, existingCondition metav1.Condition) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
observedGeneration:
description: ObservedGeneration is the latest generation observed
by the controller.
format: int64
type: integer
overlappingPolicies:
description: |-
The list of overlapping OperatorPolicies (as name.namespace) which all manage the same
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
observedGeneration:
description: ObservedGeneration is the latest generation observed
by the controller.
format: int64
type: integer
overlappingPolicies:
description: |-
The list of overlapping OperatorPolicies (as name.namespace) which all manage the same
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/case38_install_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ var _ = Describe("Testing OperatorPolicy", Ordered, Label("supports-hosted"), fu
err = json.Unmarshal(policyJSON, &policy)
g.Expect(err).NotTo(HaveOccurred())

g.Expect(policy.Status.ObservedGeneration).To(Equal(unstructPolicy.GetGeneration()))

if wantNonCompliant {
g.Expect(policy.Status.ComplianceState).To(Equal(policyv1.NonCompliant))
}
Expand Down

0 comments on commit 44c8723

Please sign in to comment.