Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions percona/controller/pgcluster/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ func updateConditions(cr *v2.PerconaPGCluster, status *v1beta1.PostgresClusterSt

syncPgbackrestFromPostgresToPercona(cr, status)

repoCondition := meta.FindStatusCondition(status.Conditions, postgrescluster.ConditionRepoHostReady)
repoCondition := meta.FindStatusCondition(cr.Status.Conditions, postgrescluster.ConditionRepoHostReady)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since status and cr are already synced, does it matter switching to cr.Status from status? Just trying to understand if this change needs to be made after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. After sync they're the same. I'm suggesting cr.Status.Conditions mainly for consistency - setClusterNotReadyCondition uses it, so the checks should too. But it's not critical, we can keep status.Conditions.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

if repoCondition == nil || repoCondition.Status != metav1.ConditionTrue {
setClusterNotReadyCondition(metav1.ConditionFalse, postgrescluster.ConditionRepoHostReady)
return
}

backupCondition := meta.FindStatusCondition(status.Conditions, postgrescluster.ConditionReplicaCreate)
backupCondition := meta.FindStatusCondition(cr.Status.Conditions, postgrescluster.ConditionReplicaCreate)
if backupCondition == nil || backupCondition.Status != metav1.ConditionTrue {
setClusterNotReadyCondition(metav1.ConditionFalse, postgrescluster.ConditionReplicaCreate)
return
Expand All @@ -175,21 +175,14 @@ func updateConditions(cr *v2.PerconaPGCluster, status *v1beta1.PostgresClusterSt

func syncConditionsFromPostgresToPercona(cr *v2.PerconaPGCluster, postgresStatus *v1beta1.PostgresClusterStatus) {
for _, pcCond := range postgresStatus.Conditions {
existing := meta.FindStatusCondition(cr.Status.Conditions, pcCond.Type)
if existing != nil {
continue
}

newCond := metav1.Condition{
_ = meta.SetStatusCondition(&cr.Status.Conditions, metav1.Condition{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this comment here regarding unit testing. Agreeing with @egegunes, IMO we could add comprehensive unit test func TestUpdateConditions(t *testing.T) checking the updateConditions function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateConditions is already covered by integration tests. Should I add unit tests for it as well, or replace the integration tests with unit tests?

Type: pcCond.Type,
Status: pcCond.Status,
Reason: pcCond.Reason,
Message: pcCond.Message,
LastTransitionTime: pcCond.LastTransitionTime,
ObservedGeneration: cr.Generation,
}

cr.Status.Conditions = append(cr.Status.Conditions, newCond)
})
}
}

Expand Down
Loading
Loading