@@ -21,17 +21,25 @@ import (
21
21
"os"
22
22
23
23
"github.com/spf13/cobra"
24
+ corev1 "k8s.io/api/core/v1"
25
+ "k8s.io/apimachinery/pkg/labels"
24
26
"k8s.io/apimachinery/pkg/runtime"
27
+ "k8s.io/apimachinery/pkg/selection"
25
28
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
29
+ "k8s.io/client-go/rest"
26
30
"k8s.io/klog/v2"
27
31
ctrl "sigs.k8s.io/controller-runtime"
32
+ "sigs.k8s.io/controller-runtime/pkg/cache"
33
+ "sigs.k8s.io/controller-runtime/pkg/client"
28
34
"sigs.k8s.io/controller-runtime/pkg/client/config"
29
35
"sigs.k8s.io/controller-runtime/pkg/log"
30
36
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
31
37
32
38
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
33
39
"github.com/liqotech/liqo/pkg/fabric"
40
+ "github.com/liqotech/liqo/pkg/fabric/sourcedetector"
34
41
"github.com/liqotech/liqo/pkg/firewall"
42
+ "github.com/liqotech/liqo/pkg/gateway"
35
43
"github.com/liqotech/liqo/pkg/route"
36
44
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
37
45
"github.com/liqotech/liqo/pkg/utils/mapper"
45
53
46
54
func init () {
47
55
utilruntime .Must (networkingv1alpha1 .AddToScheme (scheme ))
56
+ utilruntime .Must (corev1 .AddToScheme (scheme ))
48
57
}
49
58
50
59
func main () {
@@ -79,6 +88,14 @@ func run(cmd *cobra.Command, _ []string) error {
79
88
// Get the rest config.
80
89
cfg := config .GetConfigOrDie ()
81
90
91
+ // Create a label selector to filter only the events for gateway pods
92
+ reqGatewayPods , err := labels .NewRequirement (
93
+ gateway .GatewayComponentKey ,
94
+ selection .Equals ,
95
+ []string {gateway .GatewayComponentGateway },
96
+ )
97
+ utilruntime .Must (err )
98
+
82
99
// Create the manager.
83
100
mgr , err := ctrl .NewManager (cfg , ctrl.Options {
84
101
MapperProvider : mapper .LiqoMapperProvider (scheme ),
@@ -88,11 +105,33 @@ func run(cmd *cobra.Command, _ []string) error {
88
105
},
89
106
HealthProbeBindAddress : options .ProbeAddr ,
90
107
LeaderElection : false ,
108
+ NewCache : func (config * rest.Config , opts cache.Options ) (cache.Cache , error ) {
109
+ opts .ByObject = map [client.Object ]cache.ByObject {
110
+ & corev1.Pod {}: {
111
+ Label : labels .NewSelector ().Add (* reqGatewayPods ),
112
+ },
113
+ }
114
+ return cache .New (config , opts )
115
+ },
91
116
})
92
117
if err != nil {
93
118
return fmt .Errorf ("unable to create manager: %w" , err )
94
119
}
95
120
121
+ gwr , err := sourcedetector .NewGatewayReconciler (
122
+ mgr .GetClient (),
123
+ mgr .GetScheme (),
124
+ mgr .GetEventRecorderFor ("gateway-controller" ),
125
+ options ,
126
+ )
127
+ if err != nil {
128
+ return fmt .Errorf ("unable to create gateway reconciler: %w" , err )
129
+ }
130
+
131
+ if err := gwr .SetupWithManager (mgr ); err != nil {
132
+ return fmt .Errorf ("unable to setup gateway reconciler: %w" , err )
133
+ }
134
+
96
135
// Setup the firewall configuration controller.
97
136
fwcr , err := firewall .NewFirewallConfigurationReconcilerWithFinalizer (
98
137
mgr .GetClient (),
0 commit comments