harvester / pcidevices

Manage PCI Devices and PCI Device Claims for PCI Passthrough in Harvester

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about reconcilePCIDeviceClaims

w13915984028 opened this issue · comments

Question about reconcilePCIDeviceClaims:

  1. The following Update operations, do not use a copied object, but the local queried one
				_, err = h.pdcClient.Update(&pdc)
				if err != nil {
					return err
				}
				_, err = h.pdcClient.UpdateStatus(&pdc)
				if err != nil {
					return err
				}
  1. The pdc spec seems not changed in reconcilePCIDeviceClaims, but here it calls Update and UpdateStatus, is one time of Update* is enough?

  2. Should if pdc.DeletionTimestamp != nil be checked before if !pdc.Status.PassthroughEnabled ?

  3. Those change of pdc.Status.PassthroughEnabled but return err, may cause (k8s) controller local cached data is not consistant with apiserver.

						if err != nil {
							pdc.Status.PassthroughEnabled = false
							return err
						}

For 1, there is no deepCopy on the pdc runtime.Object, can you clarify?
For 4, I'm not sure I understand, is the problem that a status change without a call to UpdateStatus will cause cache invalidation? If so I can fix that.

For 3, I pushed that correction, we should be checking the deletion time, nice catch.

For 2, I remember when I was first developing this, the call to Update alone was not enough. There's no metadata change so I will see if just removing the call to Update and keeping UpdateStatus works.

To answer 2, I removed the call to Update before UpdateStatus, and the PCI Devices were all created and maintained correctly. Here is the commit: 41ca67a

An example about how to update k8s object:

It is always necessary to deep copy an object out, and set the desired value, then check reflect.DeepEqual, finally call client.Update

harvester/pkg/controller/backup/backup_status.go

func (h *Handler) updateConditions(vmBackup *harvesterv1.VirtualMachineBackup) error {
	var vmBackupCpy = vmBackup.DeepCopy()
	....
	vmBackupCpy.Status.ReadyToUse = pointer.BoolPtr(ready)

	if !reflect.DeepEqual(vmBackup.Status, vmBackupCpy.Status) {
		if _, err := h.vmBackups.Update(vmBackupCpy); err != nil {
			return err
		}
	}
	return nil
}	

Do NOT use the queried object (e.g. List()) to do local change and client.Update() directly.

I see, I'll make that change, thank you.