-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
secretsync.go
68 lines (58 loc) · 1.8 KB
/
secretsync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package gateway_api
import (
"context"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
"github.com/cilium/cilium/operator/pkg/gateway-api/helpers"
"github.com/cilium/cilium/pkg/logging/logfields"
)
func EnqueueTLSSecrets(c client.Client, logger logrus.FieldLogger) handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
scopedLog := logger.WithFields(logrus.Fields{
logfields.Controller: "secrets",
logfields.Resource: obj.GetName(),
})
gw, ok := obj.(*gatewayv1.Gateway)
if !ok {
return nil
}
// Check whether Gateway is managed by Cilium
if !hasMatchingController(ctx, c, controllerName)(gw) {
return nil
}
var reqs []reconcile.Request
for _, l := range gw.Spec.Listeners {
if l.TLS == nil {
continue
}
for _, cert := range l.TLS.CertificateRefs {
if !helpers.IsSecret(cert) {
continue
}
s := types.NamespacedName{
Namespace: helpers.NamespaceDerefOr(cert.Namespace, gw.Namespace),
Name: string(cert.Name),
}
reqs = append(reqs, reconcile.Request{NamespacedName: s})
scopedLog.WithField("secret", s).Debug("Enqueued secret for gateway")
}
}
return reqs
})
}
func IsReferencedByCiliumGateway(ctx context.Context, c client.Client, logger logrus.FieldLogger, obj *corev1.Secret) bool {
gateways := getGatewaysForSecret(ctx, c, obj)
for _, gw := range gateways {
if hasMatchingController(ctx, c, controllerName)(gw) {
return true
}
}
return false
}