Skip to content

Commit c860a48

Browse files
committed
CopyToNamespace code & unit test changes
Code Changes: • Annotation Consistency: We unconditionally set the non-status-hash annotation on the in-memory CSV object, ensuring that prototype.Annotations["olm.operatorframework.io/nonStatusCopyHash"] always matches the final state—even if the existing CSV already matched. • Multi-step Updates: We now issue a separate “normal” Update call after an UpdateStatus call if the CSV’s status hash differs. This keeps the statusCopyHashAnnotation in sync with the actual .status and avoids stale annotation data. Test Changes: • Expected Actions: Each test case now expects the exact create/update/updateStatus calls (and any subsequent update) that the refactored copyToNamespace emits. This includes: 1. Creating a CSV if none exists, 2. Updating the non-status annotation if it changed, 3. Updating the .status subresource if the status hash changed, and 4. Issuing a follow-up metadata update for the new status-hash annotation. • Fake Lister: • Even though the code already called copiedCSVLister.Namespace(ns), our old tests didn’t exercise or strictly verify that part of the interface. As we expanded and refined the tests — particularly around existing vs. non-existing CSV scenarios — we triggered code paths that call .Namespace(ns).Get(...), exposing the incomplete fake. • Better Coverage: By adding a fully implemented fake lister (including List, Get, and Namespace(...)), the new tests accurately reflect the real OLM flow and properly simulate how the operator queries for existing CSVs in a specific namespace. Signed-off-by: Brett Tofel <[email protected]>
1 parent 67c82b9 commit c860a48

File tree

2 files changed

+184
-111
lines changed

2 files changed

+184
-111
lines changed

pkg/controller/operators/olm/operatorgroup.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,10 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
840840
existingStatus := existing.Annotations[statusCopyHashAnnotation]
841841

842842
var updated *v1alpha1.ClusterServiceVersion
843+
// Always set the in-memory prototype's nonstatus annotation:
844+
prototype.Annotations[nonStatusCopyHashAnnotation] = nonstatus
843845
if existingNonStatus != nonstatus {
844846
// include updates to the non-status hash annotation if there is a mismatch
845-
prototype.Annotations[nonStatusCopyHashAnnotation] = nonstatus
846847
if updated, err = a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).Update(context.TODO(), prototype, metav1.UpdateOptions{}); err != nil {
847848
return nil, fmt.Errorf("failed to update: %w", err)
848849
}
@@ -863,6 +864,10 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
863864
if updated, err = a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).Update(context.TODO(), prototype, metav1.UpdateOptions{}); err != nil {
864865
return nil, fmt.Errorf("failed to update: %w", err)
865866
}
867+
} else {
868+
// Even if they're the same, ensure the returned prototype is annotated.
869+
prototype.Annotations[statusCopyHashAnnotation] = status
870+
updated = prototype
866871
}
867872
return &v1alpha1.ClusterServiceVersion{
868873
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)