Skip to content
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

使用search查询资源失败(资源存在) #2226

Open
first-sight12 opened this issue Jul 20, 2022 · 13 comments
Open

使用search查询资源失败(资源存在) #2226

first-sight12 opened this issue Jul 20, 2022 · 13 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@first-sight12
Copy link

first-sight12 commented Jul 20, 2022

What happened:
转发到单个集群(member1)能够查到资源,结果如下:
image

使用search查询为空(有时能查到结果 有时查询为空),结果如下:
image

karmada-search 日志如下:
image

What you expected to happen:
期望search查询结果与单集群转发结果一致

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Karmada version:
  • kubectl-karmada or karmadactl version (the result of kubectl-karmada version or karmadactl version):
  • Others:
@first-sight12 first-sight12 added the kind/bug Categorizes issue or PR as related to a bug. label Jul 20, 2022
@chaunceyjiang
Copy link
Member

有时能查到结果 有时查询为空

like this issue #1946

@first-sight12
Copy link
Author

有时能查到结果 有时查询为空

like this issue #1940

使用的是push模式不是pull模式

[root@node1 ~]# kubectl get cluster
NAME      VERSION   MODE   READY   AGE
master    v1.21.5   Push   True    27h
member1   v1.21.5   Push   True    9d
member2   v1.21.5   Push   True    5d2h

@fly2F
Copy link
Member

fly2F commented Jul 20, 2022

@first-sight12

  • Please provide the ResourceRegistry, e.g kubectl get ResourceRegistry xxx -o yaml
  • Please provide more karmada-search logs

@first-sight12
Copy link
Author

@first-sight12

  • Please provide the ResourceRegistry, e.g kubectl get ResourceRegistry xxx -o yaml
  • Please provide more karmada-search logs

yaml文件如下:

apiVersion: search.karmada.io/v1alpha1
kind: ResourceRegistry
metadata:
  name: test
spec:
  targetCluster:
    exclude:
      - master
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
    - apiVersion: v1
      kind: Service
    - apiVersion: v1
      kind: Namespace
    - apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRole
    - apiVersion: v1
      kind: ResourceQuota
    - apiVersion: quota.kubesphere.io/v1alpha2
      kind: ResourceQuota

如下资源非kubernetes原生为自定义crd资源

- apiVersion: quota.kubesphere.io/v1alpha2
      kind: ResourceQuota :

日志如下:
image

image

@fly2F
Copy link
Member

fly2F commented Jul 21, 2022

The fail is controller.go:431] failed to get gvr: no matches for kind "Resourcequota" in version "quota.kubesphere.io/vialpha2"

I used dynamic RESTMapper to dynamically discover resource types at runtime, this seems to be the problem with usage, I try to fix it

@XiShanYongYe-Chang
Copy link
Member

Hi @first-sight12, have you installed this crd quota.kubesphere.io/v1alpha2 ResourceQuota on the karmada control-plane?

@luoMonkeyKing
Copy link
Contributor

Hi @first-sight12, have you installed this crd quota.kubesphere.io/v1alpha2 ResourceQuota on the karmada control-plane?

No,On the k8s host

@fly2F
Copy link
Member

fly2F commented Aug 11, 2022

@first-sight12 @luoMonkeyKing
We will make a constraint that crd resources need to be installed on the karmada control-plane.
Please refer to #2361

@ikaven1024
Copy link
Member

now restMapper discovers resource type only from controller panel. So only resources installed in karmada apiserver can be searched. I think we shall discover it from all the member clusters.

@ikaven1024
Copy link
Member

How about it. Guess the kind when NoMatchError occur. It's a quick fix, but not eventually.

diff --git a/pkg/search/controller.go b/pkg/search/controller.go
index edb6fddd..3b1b950f 100644
--- a/pkg/search/controller.go
+++ b/pkg/search/controller.go
@@ -427,8 +427,13 @@ func (c *Controller) getResources(selectors []searchv1alpha1.ResourceSelector) [
                        c.restMapper, schema.FromAPIVersionAndKind(rs.APIVersion, rs.Kind),
                )
                if err != nil {
-                       klog.Errorf("failed to get gvr: %v", err)
-                       continue
+                       if !meta.IsNoMatchError(err) {
+                               klog.Errorf("failed to get gvr: %v", err)
+                               continue
+                       }
+                       gvk := schema.FromAPIVersionAndKind(rs.APIVersion, rs.Kind)
+                       gvr, _ = meta.UnsafeGuessKindToResource(gvk)
+                       klog.Warningf("guess kind of %v as %v", gvk.String(), gvr.String())
                }
                resources = append(resources, gvr)
        }

@XiShanYongYe-Chang
Copy link
Member

Hi @ikaven1024, I discussed this with @liys87x earlier: #2361 (comment)

How can we ensure correct resource gvr?

@ikaven1024
Copy link
Member

How can we ensure correct resource gvr?

Yes, it's unsafe, but solving most cases. It's a temporary solution before finding a perfect one.

@XiShanYongYe-Chang
Copy link
Member

The prerequisite for guessing resource names using this UnsafeGuessKindToResource method is that the user adheres to specific CRD naming conventions, which we may still need to explain in the documentation(or quote k8s instructions, but I can't find a clear rule description yet). My concern is that the current interim solution may become the final solution because no final solution can be found.

Maybe we can ask for some other comments. @liys87x @RainbowMango @huntsman-li

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants