-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeMeta is empty when using client.Get() #1517
Comments
This is an upstream error, do we need to do a temporary fix? |
Fixes kubernetes-sigs#1517 Signed-off-by: cndoit18 <cndoit18@outlook.com>
@alvaroaleman |
/assign @cndoit18 |
tbh I'd prefer to not woraround this downstream and wait for someone to do it properly in upstream. The issue is IMHO not severe enough to warrant yet another downstream workaround, you can get the type info from the scheme. WDYT @vincepri ? |
I agree with this decision. thank you |
You can add GVK in this way package main
import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func main() {
cli, err := client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme.Scheme})
if err != nil {
panic(err)
}
ns := &corev1.Namespace{}
if err := cli.Get(context.Background(), client.ObjectKey{Name: "default"}, ns); err != nil {
panic(err)
}
gvks, unversioned, err := cli.Scheme().ObjectKinds(ns)
if err != nil {
panic(err)
}
if !unversioned && len(gvks) == 1 {
ns.SetGroupVersionKind(gvks[0])
}
fmt.Printf("TypeMeta: %+v\n", ns.TypeMeta)
}
// output:
// TypeMeta: {Kind:Namespace APIVersion:v1} |
This issue seems to be closed, WDYT @alvaroaleman |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
Agree |
Description of changes: Some version of K8s do not reliably return `TypeMeta` information when you call `apiReader.Get()` (see kubernetes/kubernetes#3030 and kubernetes/kubernetes#80609). This is a [known bug](kubernetes-sigs/controller-runtime#1517) in `controller-runtime` that they don't plan on fixing. Parts of the code, namely around setting up the user agent, currently rely on these fields - and they are currently being given an empty struct (with empty strings for all values). To work around this bug, this PR has introduced a new `GroupVersionKind()` getter in the `ResourceDescriptor` (replacing the existing `GroupKind`), which returns a static description of the GVK. Then, rather than referencing the `RuntimeObject` `TypeMeta` properties, we can reference this new GVK getter anywhere in the runtime. It also replaces any existing use of `GroupKind` to now use `GroupVersionKind`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Upgraded to latest hive api from mce-2.7 branch - Upgraded to go 1.22 - Changed code due to changes in the behaviour of runtime-controller library - remove unncessary dependencies from go.mod See related issues on changes for runtime-controller that needed to be addressed: - kubernetes-sigs/controller-runtime#2788 - kubernetes-sigs/controller-runtime#1517
- Upgraded to latest hive api from mce-2.7 branch - Upgraded to go 1.22 - Changed code due to changes in the behaviour of runtime-controller library - remove unncessary dependencies from go.mod See related issues on changes for runtime-controller that needed to be addressed: - kubernetes-sigs/controller-runtime#2788 - kubernetes-sigs/controller-runtime#1517
- Upgraded to latest hive api from mce-2.7 branch - Upgraded to go 1.22 - Changed code due to changes in the behaviour of runtime-controller library - remove unncessary dependencies from go.mod See related issues on changes for runtime-controller that needed to be addressed: - kubernetes-sigs/controller-runtime#2788 - kubernetes-sigs/controller-runtime#1517 Signed-off-by: David Huynh <dhuynh@redhat.com>
- Upgraded to latest hive api from mce-2.7 branch - Upgraded to go 1.22 - Changed code due to changes in the behaviour of runtime-controller library - remove unncessary dependencies from go.mod See related issues on changes for runtime-controller that needed to be addressed: - kubernetes-sigs/controller-runtime#2788 - kubernetes-sigs/controller-runtime#1517 Signed-off-by: David Huynh <dhuynh@redhat.com>
I use
client.New()
to build aClient
and call itsGet()
method to get some object. But the returned object has an empty TypeMeta.Expected output:
Actual output:
The text was updated successfully, but these errors were encountered: