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

Chore: remove the uncessary allAssociatedRefGrants from resourceMappings #2843

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@
allAssociatedNamespaces map[string]struct{}
// Map for storing backendRefs' NamespaceNames referred by various Route objects.
allAssociatedBackendRefs map[gwapiv1.BackendObjectReference]struct{}
// Map for storing referenceGrant NamespaceNames for BackendRefs, SecretRefs, ConfigMapRefs.
allAssociatedRefGrants map[types.NamespacedName]*gwapiv1b1.ReferenceGrant
// extensionRefFilters is a map of filters managed by an extension.
// The key is the namespaced name of the filter and the value is the
// unstructured form of the resource.
Expand All @@ -128,7 +126,6 @@
return &resourceMappings{
allAssociatedNamespaces: map[string]struct{}{},
allAssociatedBackendRefs: map[gwapiv1.BackendObjectReference]struct{}{},
allAssociatedRefGrants: map[types.NamespacedName]*gwapiv1b1.ReferenceGrant{},
extensionRefFilters: map[types.NamespacedName]unstructured.Unstructured{},
}
}
Expand Down Expand Up @@ -207,12 +204,6 @@
// BackendRefs are referred by various Route objects and the ExtAuth in SecurityPolicies.
r.processBackendRefs(ctx, gwcResource, resourceMappings)

// Add all ReferenceGrants to the resourceTree
// TODO: zhaohuabing remove allAssociatedRefGrants from resourceMappings and directly add to gwcResource
for _, referenceGrant := range resourceMappings.allAssociatedRefGrants {
gwcResource.ReferenceGrants = append(gwcResource.ReferenceGrants, referenceGrant)
}

// For this particular Gateway, and all associated objects, check whether the
// namespace exists. Add to the resourceTree.
for ns := range resourceMappings.allAssociatedNamespaces {
Expand Down Expand Up @@ -459,7 +450,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 453 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L453

Added line #L453 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -540,7 +531,7 @@
from.kind, from.namespace, to.kind, to.namespace)
default:
// RefGrant found
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 534 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L534

Added line #L534 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -641,7 +632,7 @@
from.kind, from.namespace, to.kind, to.namespace)
default:
// RefGrant found
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 635 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L635

Added line #L635 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/kubernetes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 75 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L75

Added line #L75 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -150,7 +150,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 153 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L153

Added line #L153 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -269,7 +269,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 272 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L272

Added line #L272 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -336,7 +336,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 339 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L339

Added line #L339 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -425,7 +425,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 428 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L428

Added line #L428 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down Expand Up @@ -495,7 +495,7 @@
r.log.Info("no matching ReferenceGrants found", "from", from.kind,
"from namespace", from.namespace, "target", to.kind, "target namespace", to.namespace)
default:
resourceMap.allAssociatedRefGrants[utils.NamespacedName(refGrant)] = refGrant
resourceTree.ReferenceGrants = append(resourceTree.ReferenceGrants, refGrant)

Check warning on line 498 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L498

Added line #L498 was not covered by tests
r.log.Info("added ReferenceGrant to resource map", "namespace", refGrant.Namespace,
"name", refGrant.Name)
}
Expand Down