Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

[Feature] Using K8s Discovery mechanism to get resource from GVK #202

Closed
wonderflow opened this issue Sep 8, 2020 · 0 comments · Fixed by #261
Closed

[Feature] Using K8s Discovery mechanism to get resource from GVK #202

wonderflow opened this issue Sep 8, 2020 · 0 comments · Fixed by #261
Labels
bug Something isn't working

Comments

@wonderflow
Copy link
Member

// GetCRDName return the CRD name of any resources
// the format of the CRD of a resource is <kind purals>.<group>
func GetCRDName(u *unstructured.Unstructured) string {
	group, _ := APIVersion2GroupVersion(u.GetAPIVersion())
	resources := []string{Kind2Resource(u.GetKind())}
	if group != "" {
		resources = append(resources, group)
	}
	return strings.Join(resources, ".")
}
// Kind2Resource convert Kind to Resources
func Kind2Resource(str string) string {
	return plur.NewClient().Plural(strings.ToLower(str))
}

Now we convert GVK to CRD Name by using plural of kind.

We should get the resource by using discovery client.

The ServerResourcesForGroupVersion can get resourceList from groupVersion(apiVersion) and we can get the real resource from the list.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant