kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
9.13k stars 2.95k forks source link

Add simple ResourceVersion tracking in fake.Clientset #1385

Open stippi2 opened 1 month ago

stippi2 commented 1 month ago

Currently, the fake.Clientset does not maintain any ResourceVersions on the objects that are added via it's API functions. For example:

client := fake.NewClientset()
namespaces := clientset.CoreV1().Namespaces()

// Create a namespace via the API:
ns := &corev1.Namespace{
    ObjectMeta: metav1.ObjectMeta{
        Name: "test-namespace",
    },
}
_, _ := namespaces.Create(ctx, ns, metav1.CreateOptions{})

// Retrieve the namespace by name
ns, _ = namespaces.Get(context.TODO(), "test-namespace", metav1.GetOptions{})

// ns.ResourceVersion == ""

In the above example, the ResourceVersion of the object is not maintained by the fake client. For some type of tests, it would be a great benefit to update the resource version in the fake client.

We open this issue to get feedback whether this feature is considered valuable. If so, we offer to implement it. We saw there was already an earlier issue that got closed due to lack of activity.

We have successfully implemented the resource version updates by registering a Reactor that watches the Create, Update and Patch actions. But it feels like it would not hurt to have this functionality directly in client-go. What do you think?