k8s-cloud-provider icon indicating copy to clipboard operation
k8s-cloud-provider copied to clipboard

Mock objects do nothing for Update interface

Open yanweiguo opened this issue 4 years ago • 7 comments

For example:

// Update is a mock for the corresponding method.
func (m *MockHealthChecks) Update(ctx context.Context, key *meta.Key, arg0 *ga.HealthCheck) error {
	if m.UpdateHook != nil {
		return m.UpdateHook(ctx, key, arg0, m)
	}
	return nil
}

It does nothing if UpdateHook is nil. I would expect it to override what is stored in m.Objects[*key]. Do I miss something?

yanweiguo avatar Nov 04 '20 07:11 yanweiguo

I believe this is because "Update" is considered an additional method, and not part of the default methods. @bowei Do you remember if this is the case?

spencerhance avatar Nov 04 '20 18:11 spencerhance

Regardless this is something we deal with in ingress-gce with UpdateHooks, so this would be helpful there as well if we are able to fix it.

spencerhance avatar Nov 04 '20 18:11 spencerhance

I believe this is because "Update" is considered an additional method, and not part of the default methods. @bowei Do you remember if this is the case?

Hmm, I think "Update" is used to update a GCE object in the legacy-cloud-provider package. For example: https://github.com/kubernetes/legacy-cloud-providers/blob/master/gce/gce_healthchecks.go#L80

yanweiguo avatar Nov 04 '20 19:11 yanweiguo

@yanweiguo I think there is some confusion here. Update is definitely used to update a GCE object, but not all resources support the Update method. Hence why it is considered an additional method: https://github.com/GoogleCloudPlatform/k8s-cloud-provider/blob/master/pkg/cloud/meta/meta.go#L239

I think is mainly a limitation of the current codebase

spencerhance avatar Nov 04 '20 19:11 spencerhance

@yanweiguo I think there is some confusion here. Update is definitely used to update a GCE object, but not all resources support the Update method. Hence why it is considered an additional method: https://github.com/GoogleCloudPlatform/k8s-cloud-provider/blob/master/pkg/cloud/meta/meta.go#L239

I think is mainly a limitation of the current codebase

Ah thanks for explaining.

yanweiguo avatar Nov 04 '20 19:11 yanweiguo

@yanweiguo That isn't to say that we can't fix it though :)

spencerhance avatar Nov 04 '20 19:11 spencerhance

Can you use the hooks to implement the functionality you need?

bowei avatar May 10 '23 20:05 bowei