Skip to content

Commit

Permalink
delete copyNonStatusFrom function, change test case description
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 authored and k8s-infra-cherrypick-robot committed Sep 9, 2023
1 parent b3c83a2 commit 339df9a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
40 changes: 0 additions & 40 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,46 +950,6 @@ func dryPatch(action testing.PatchActionImpl, tracker testing.ObjectTracker) (ru
return obj, nil
}

//lint:ignore U1000 function is causing errors with status updates
func copyNonStatusFrom(old, new runtime.Object) error {
newClientObject, ok := new.(client.Object)
if !ok {
return fmt.Errorf("%T is not a client.Object", new)
}
// The only thing other than status we have to retain
rv := newClientObject.GetResourceVersion()

oldMapStringAny, err := toMapStringAny(old)
if err != nil {
return fmt.Errorf("failed to convert old to *unstructured.Unstructured: %w", err)
}
newMapStringAny, err := toMapStringAny(new)
if err != nil {
return fmt.Errorf("failed to convert new to *unststructured.Unstructured: %w", err)
}

// delete everything other than status in case it has fields that were not present in
// the old object
for k := range newMapStringAny {
if k != "status" {
delete(newMapStringAny, k)
}
}
// copy everything other than status from the old object
for k := range oldMapStringAny {
if k != "status" {
newMapStringAny[k] = oldMapStringAny[k]
}
}

if err := fromMapStringAny(newMapStringAny, new); err != nil {
return fmt.Errorf("failed to convert back from map[string]any: %w", err)
}
newClientObject.SetResourceVersion(rv)

return nil
}

// copyStatusFrom copies the status from old into new
func copyStatusFrom(old, new runtime.Object) error {
oldMapStringAny, err := toMapStringAny(old)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ var _ = Describe("Fake client", func() {
objOriginal.Status.NodeInfo.MachineID = "machine-id-from-status-update"
Expect(cmp.Diff(objOriginal, actual)).To(BeEmpty())
})
It("should not overwrite status fields of typed objects that have a status subresource on status update", func() {
It("Should only override status fields of typed objects that have a status subresource on status update", func() {
obj := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node",
Expand Down

0 comments on commit 339df9a

Please sign in to comment.