Skip to content

Commit 4dd01e9

Browse files
authored
Merge pull request #593 from rquitales/custom-storage
fix: Always apply status when merging or replacing
2 parents 60bfe71 + 24aa255 commit 4dd01e9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

pkg/inventory/inventory-client.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ func (cic *ClusterClient) Merge(localInv Info, objs object.ObjMetadataSet, dryRu
144144
return pruneIds, err
145145
}
146146

147+
// Update not required when all objects in inventory are the same and
148+
// status does not need to be updated. If status is stored, always update the
149+
// inventory to store the latest status.
150+
if objs.Equal(clusterObjs) && cic.statusPolicy == StatusPolicyNone {
151+
return pruneIds, nil
152+
}
153+
147154
if dryRun.ClientOrServerDryRun() {
148155
klog.V(4).Infof("dry-run create inventory object: not created")
149156
return pruneIds, nil
@@ -176,13 +183,18 @@ func (cic *ClusterClient) Replace(localInv Info, objs object.ObjMetadataSet, sta
176183
return err
177184
}
178185

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

183-
if err := wrappedInv.ApplyWithPrune(cic.dc, cic.mapper, cic.statusPolicy, objs); err != nil {
184-
return fmt.Errorf("failed to write updated inventory to cluster: %w", err)
185-
}
193+
klog.V(4).Infof("replace cluster inventory: %s/%s", clusterInv.GetNamespace(), clusterInv.GetName())
194+
klog.V(4).Infof("replace cluster inventory %d objects", len(objs))
195+
196+
if err := wrappedInv.ApplyWithPrune(cic.dc, cic.mapper, cic.statusPolicy, objs); err != nil {
197+
return fmt.Errorf("failed to write updated inventory to cluster: %w", err)
186198
}
187199

188200
return nil

0 commit comments

Comments
 (0)