Skip to content

Commit

Permalink
Merge pull request #233 from matthchr/matthchr/fix-namespaced-check
Browse files Browse the repository at this point in the history
Fix resource namespaced check
  • Loading branch information
a-hilaly authored Jan 29, 2025
2 parents 0df34f6 + 928f1c2 commit 26fe7c1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/graph/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ func (b *Builder) NewResourceGraphDefinition(originalCR *v1alpha1.ResourceGraphD
// CEL expressions.
// 4. Extract the CEL expressions from the resource + validate them.

namespacedResources := map[k8sschema.GroupVersionKind]bool{}
namespacedResources := map[k8sschema.GroupKind]bool{}
apiResourceList, err := b.discoveryClient.ServerPreferredNamespacedResources()
if err != nil {
return nil, fmt.Errorf("failed to retrieve Kubernetes namespaced resources: %w", err)
}
for _, resourceList := range apiResourceList {
for _, r := range resourceList.APIResources {
gvk := k8sschema.FromAPIVersionAndKind(resourceList.GroupVersion, r.Kind)
namespacedResources[gvk] = r.Namespaced
namespacedResources[gvk.GroupKind()] = r.Namespaced
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func (b *Builder) NewResourceGraphDefinition(originalCR *v1alpha1.ResourceGraphD
// It provides a high-level understanding of the resource, by extracting the
// OpenAPI schema, emualting the resource and extracting the cel expressions
// from the schema.
func (b *Builder) buildRGResource(rgResource *v1alpha1.Resource, namespacedResources map[k8sschema.GroupVersionKind]bool) (*Resource, error) {
func (b *Builder) buildRGResource(rgResource *v1alpha1.Resource, namespacedResources map[k8sschema.GroupKind]bool) (*Resource, error) {
// 1. We need to unmashal the resource into a map[string]interface{} to
// make it easier to work with.
resourceObject := map[string]interface{}{}
Expand Down Expand Up @@ -321,7 +321,7 @@ func (b *Builder) buildRGResource(rgResource *v1alpha1.Resource, namespacedResou
return nil, fmt.Errorf("failed to parse includeWhen expressions: %v", err)
}

_, isNamespaced := namespacedResources[gvk]
_, isNamespaced := namespacedResources[gvk.GroupKind()]

// Note that at this point we don't inject the dependencies into the resource.
return &Resource{
Expand Down

0 comments on commit 26fe7c1

Please sign in to comment.