Closed
Description
Recently, we have updated controller-runtime
from v0.14.6
to the latest
version, and found a behavior change of DynamicRESTMapper
.
This is the sample code, it uses latest
version and v0.14.6
to call KindFor
:
package main
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)
func main() {
kubeconfigPath := "./kubeconfig.yaml"
kubeconfig, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
fmt.Println(err)
return
}
// latest version
// httpClient, err := rest.HTTPClientFor(kubeconfig)
// if err != nil {
// fmt.Println(err, "Unable to create http client.")
// return
// }
// restMapper, err := apiutil.NewDynamicRESTMapper(kubeconfig, httpClient)
// if err != nil {
// fmt.Println(err, "Unable to create restmapper.")
// return
// }
// v0.14.6
restMapper, err := apiutil.NewDynamicRESTMapper(kubeconfig, apiutil.WithLazyDiscovery)
if err != nil {
fmt.Println(err, "Unable to create restmapper.")
return
}
// Call restMapper on resource "deployment"
gvk, err := restMapper.KindFor(schema.GroupVersionResource{
Resource: "deployments",
})
if err != nil {
fmt.Println(err, "Unable to get gvk.")
return
}
fmt.Println(gvk)
}
With v0.14.6
, it returns no error.
But with the latest
code, it will return the error:
no matches for /, Resource=deployments
Is there any workaround for this? Do we consider this as a compatibility issue?