-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: qicz <[email protected]>
- Loading branch information
Showing
11 changed files
with
540 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package resource | ||
|
||
var cacheKinds = []string{ | ||
"Gateway", "ReferenceGrant", "Namespace", | ||
"ServiceImport", "EndpointSlice", | ||
"Secret", "ConfigMap", "EnvoyPatchPolicy", | ||
"ClientTrafficPolicy", "BackendTrafficPolicy", "SecurityPolicy", | ||
"BackendTLSPolicy", "EnvoyExtensionPolicy", "HTTPRouteFilter", | ||
} | ||
|
||
// Set holds the resources with the kind. | ||
// +k8s:deepcopy-gen=true | ||
type Set struct { | ||
Values map[string]string `json:"-" yaml:"-"` | ||
} | ||
|
||
func newSet() *Set { | ||
return &Set{ | ||
Values: map[string]string{}, | ||
} | ||
} | ||
|
||
func (s *Set) Has(item string) bool { | ||
_, contained := s.Values[item] | ||
return contained | ||
} | ||
|
||
func (s *Set) Insert(items ...string) { | ||
for _, item := range items { | ||
s.Values[item] = "" | ||
} | ||
} | ||
|
||
// Cache holds some duplicate resources in memory. | ||
// +k8s:deepcopy-gen=true | ||
type Cache struct { | ||
ResourceSet map[string]*Set `json:"-" yaml:"-"` | ||
} | ||
|
||
func (r *Resources) InitCache() { | ||
r.Cache = newCache() | ||
} | ||
|
||
func newCache() *Cache { | ||
resourceSets := make(map[string]*Set, len(cacheKinds)) | ||
for _, kind := range cacheKinds { | ||
resourceSets[kind] = newSet() | ||
} | ||
|
||
return &Cache{ | ||
ResourceSet: resourceSets, | ||
} | ||
} | ||
|
||
func (r *Resources) resourceCache(kind string) *Set { | ||
if rs, ok := r.Cache.ResourceSet[kind]; ok { | ||
return rs | ||
} | ||
|
||
return newSet() | ||
} |
Oops, something went wrong.