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

Somethingwrong with clusterCache.EnsureSynced() #408

Open
biubiudu opened this issue May 7, 2022 · 0 comments
Open

Somethingwrong with clusterCache.EnsureSynced() #408

biubiudu opened this issue May 7, 2022 · 0 comments

Comments

@biubiudu
Copy link

biubiudu commented May 7, 2022

config := &rest.Config{}  
clusterCache := cache.NewClusterCache(config,
		// cache default namespace only
		cache.SetNamespaces([]string{"default", "kube-system"}),
		// configure custom logic to cache resources manifest and additional metadata
		cache.SetPopulateResourceInfoHandler(func(un *unstructured.Unstructured, isRoot bool) (info interface{}, cacheManifest bool) {
			// if resource belongs to 'extensions' group then mark if with 'deprecated' label
			if un.GroupVersionKind().Group == "extensions" {
				info = []string{"deprecated"}
			}
			_, ok := un.GetLabels()["acme.io/my-label"]
			// cache whole manifest if resource has label
			cacheManifest = ok
			return
		}),
	)
	// Ensure cluster is synced before using it
	if err := clusterCache.EnsureSynced(); err != nil {
		panic(err)
	}
	// Iterate default namespace resources tree
	for _, root := range clusterCache.FindResources("default", cache.TopLevelResource) {
		clusterCache.IterateHierarchy(root.ResourceKey(), func(resource *cache.Resource, _ map[kube.ResourceKey]*cache.Resource) bool {
			fmt.Printf("name:%s, resource: %s, \n\n", resource.Ref.Name, resource.Ref.String())
			return true
		})
	} 

**When i use the example code, it will report an error**

I0507 17:59:03.375877   49921 cluster.go:688]  "msg"="Start syncing cluster"  
panic: SchemaError(dev.oam.core.v1beta1.ApplicationRevision.spec.referredObjects): array should have exactly one sub-item 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant