You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That can be used to either delete CRDs or core resources like Jobs. When migrating some tests over from using envtest to using the fake client we ran into this issue:
"error": "Object 'apiVersion' is missing in 'unstructured object has no version'"
Reproduced with the following code fails:
// You can edit this code!
// Click here and start typing.
package main
import (
"context"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
func main() {
fakeK8sClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithStatusSubresource().Build()
job := &batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
},
}
err := fakeK8sClient.Create(context.TODO(), job)
if err != nil {
panic(err)
}
resourceList := &unstructured.UnstructuredList{}
resourceList.SetGroupVersionKind(schema.GroupVersionKind{
Group: batchv1.SchemeGroupVersion.Group,
Version: batchv1.SchemeGroupVersion.Version,
Kind: "Job",
})
err = fakeK8sClient.List(context.TODO(), resourceList)
if err != nil {
panic(err)
}
for _, resource := range resourceList.Items {
err := fakeK8sClient.Delete(context.TODO(), &resource)
if err != nil {
//fails here
panic(err)
}
}
}
go run main.go
panic: Object 'apiVersion' is missing in 'unstructured object has no version'
goroutine 1 [running]:
main.main()
/Users/jake/workspace/foo/main.go:48 +0x288
exit status 2
I thought #1662 would of resolved this, but it appears not. Any help would be great, thanks!
The text was updated successfully, but these errors were encountered:
Context
In our code we use a generic function for deletion:
That can be used to either delete CRDs or core resources like Jobs. When migrating some tests over from using envtest to using the fake client we ran into this issue:
Reproduced with the following code fails:
I thought #1662 would of resolved this, but it appears not. Any help would be great, thanks!
The text was updated successfully, but these errors were encountered: