Skip to content

Commit

Permalink
Fix resource namespaced check
Browse files Browse the repository at this point in the history
This check did not function properly for resources with multiple
versions. Rather than depending on the GVK, we use just the GK, as
a GK is either namespaced or not, it can't change between versions.
  • Loading branch information
matthchr committed Jan 29, 2025
1 parent 5a244f2 commit 928f1c2
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 928f1c2

Please sign in to comment.