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

Change certificate cache key type #393

Merged
merged 1 commit into from
Sep 11, 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: 5 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type LoadBalancerController struct {

// certCacheMu protects certCache from the concurrent read/write.
certCacheMu sync.Mutex
certCache map[string]*certificateCacheEntry
certCache map[types.NamespacedName]*certificateCacheEntry
}

type Config struct {
Expand Down Expand Up @@ -314,7 +314,7 @@ func NewLoadBalancerController(ctx context.Context, clientset clientset.Interfac
eventRecorder: config.EventRecorder,
syncQueue: workqueue.NewTyped[struct{}](),
reloadRateLimiter: flowcontrol.NewTokenBucketRateLimiter(float32(config.ReloadRate), config.ReloadBurst),
certCache: make(map[string]*certificateCacheEntry),
certCache: make(map[types.NamespacedName]*certificateCacheEntry),
}

{
Expand Down Expand Up @@ -1819,15 +1819,15 @@ type certificateCacheEntry struct {
key []byte
}

func (lbc *LoadBalancerController) getCertificateFromCache(key string) (*certificateCacheEntry, bool) {
func (lbc *LoadBalancerController) getCertificateFromCache(key types.NamespacedName) (*certificateCacheEntry, bool) {
lbc.certCacheMu.Lock()
ent, ok := lbc.certCache[key]
lbc.certCacheMu.Unlock()

return ent, ok
}

func (lbc *LoadBalancerController) cacheCertificate(key string, entry *certificateCacheEntry) {
func (lbc *LoadBalancerController) cacheCertificate(key types.NamespacedName, entry *certificateCacheEntry) {
lbc.certCacheMu.Lock()
lbc.certCache[key] = entry
lbc.certCacheMu.Unlock()
Expand All @@ -1844,12 +1844,7 @@ func (lbc *LoadBalancerController) garbageCollectCertificate(ctx context.Context
lbc.certCacheMu.Lock()

for key := range lbc.certCache {
ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
continue
}

if _, err := lbc.secretLister.Secrets(ns).Get(name); err != nil {
if _, err := lbc.secretLister.Secrets(key.Namespace).Get(key.Name); err != nil {
if apierrors.IsNotFound(err) {
delete(lbc.certCache, key)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
listersnetworkingv1 "k8s.io/client-go/listers/networking/v1"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -273,8 +274,8 @@ func ingressPortStatusFromPortStatus(ports []corev1.PortStatus) []networkingv1.I
return ingPorts
}

func createCertCacheKey(s *corev1.Secret) string {
return s.Namespace + "/" + s.Name
func createCertCacheKey(s *corev1.Secret) types.NamespacedName {
return namespacedName(s)
}

func calculateCertificateHash(cert, key []byte) []byte {
Expand Down