Skip to content

Commit

Permalink
fix: Always apply status when merging or replacing
Browse files Browse the repository at this point in the history
The refactor to include `Apply` and `ApplyWithPrune` interface methods
in `Storage` caused a regression where status is not alway applied. This
commit ensures that the status is always applied.
  • Loading branch information
rquitales committed Jun 30, 2022
1 parent c29e1ab commit 24aa255
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/inventory/inventory-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ func (cic *ClusterClient) Merge(localInv Info, objs object.ObjMetadataSet, dryRu
return pruneIds, err
}

// Update not required when all objects in inventory are the same and
// status does not need to be updated. If status is stored, always update the
// inventory to store the latest status.
if objs.Equal(clusterObjs) && cic.statusPolicy == StatusPolicyNone {
return pruneIds, nil
}

if dryRun.ClientOrServerDryRun() {
klog.V(4).Infof("dry-run create inventory object: not created")
return pruneIds, nil
Expand Down Expand Up @@ -176,13 +183,18 @@ func (cic *ClusterClient) Replace(localInv Info, objs object.ObjMetadataSet, sta
return err
}

if !objs.Equal(clusterObjs) {
klog.V(4).Infof("replace cluster inventory: %s/%s", clusterInv.GetNamespace(), clusterInv.GetName())
klog.V(4).Infof("replace cluster inventory %d objects", len(objs))
// Update not required when all objects in inventory are the same and
// status does not need to be updated. If status is stored, always update the
// inventory to store the latest status.
if objs.Equal(clusterObjs) && cic.statusPolicy == StatusPolicyNone {
return nil
}

if err := wrappedInv.ApplyWithPrune(cic.dc, cic.mapper, cic.statusPolicy, objs); err != nil {
return fmt.Errorf("failed to write updated inventory to cluster: %w", err)
}
klog.V(4).Infof("replace cluster inventory: %s/%s", clusterInv.GetNamespace(), clusterInv.GetName())
klog.V(4).Infof("replace cluster inventory %d objects", len(objs))

if err := wrappedInv.ApplyWithPrune(cic.dc, cic.mapper, cic.statusPolicy, objs); err != nil {
return fmt.Errorf("failed to write updated inventory to cluster: %w", err)
}

return nil
Expand Down

0 comments on commit 24aa255

Please sign in to comment.