@@ -28,11 +28,13 @@ import (
28
28
flag "github.com/spf13/pflag"
29
29
"helm.sh/helm/v3/pkg/getter"
30
30
corev1 "k8s.io/api/core/v1"
31
+ "k8s.io/apimachinery/pkg/labels"
31
32
"k8s.io/apimachinery/pkg/runtime"
32
33
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33
34
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
34
35
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
35
36
ctrl "sigs.k8s.io/controller-runtime"
37
+ ctrlcache "sigs.k8s.io/controller-runtime/pkg/cache"
36
38
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
37
39
38
40
"github.com/fluxcd/pkg/git"
@@ -45,16 +47,16 @@ import (
45
47
"github.com/fluxcd/pkg/runtime/pprof"
46
48
"github.com/fluxcd/pkg/runtime/probes"
47
49
48
- "github.com/fluxcd/source-controller/internal/digest "
49
- "github.com/fluxcd/source-controller/internal/features "
50
- "github.com/fluxcd/source-controller/internal/helm/registry"
50
+ "github.com/fluxcd/source-controller/api/v1 "
51
+ "github.com/fluxcd/source-controller/api/v1beta2 "
52
+ // +kubebuilder:scaffold:imports
51
53
52
- v1 "github.com/fluxcd/source-controller/api/v1"
53
- v1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
54
54
"github.com/fluxcd/source-controller/controllers"
55
55
"github.com/fluxcd/source-controller/internal/cache"
56
+ "github.com/fluxcd/source-controller/internal/digest"
57
+ "github.com/fluxcd/source-controller/internal/features"
56
58
"github.com/fluxcd/source-controller/internal/helm"
57
- // +kubebuilder:scaffold:imports
59
+ "github.com/fluxcd/source-controller/internal/helm/registry"
58
60
)
59
61
60
62
const controllerName = "source-controller"
@@ -92,7 +94,6 @@ func main() {
92
94
storageAdvAddr string
93
95
concurrent int
94
96
requeueDependency time.Duration
95
- watchAllNamespaces bool
96
97
helmIndexLimit int64
97
98
helmChartLimit int64
98
99
helmChartFileLimit int64
@@ -101,6 +102,7 @@ func main() {
101
102
leaderElectionOptions leaderelection.Options
102
103
rateLimiterOptions helper.RateLimiterOptions
103
104
featureGates feathelper.FeatureGates
105
+ watchOptions helper.WatchOptions
104
106
helmCacheMaxSize int
105
107
helmCacheTTL string
106
108
helmCachePurgeInterval string
@@ -121,8 +123,6 @@ func main() {
121
123
flag .StringVar (& storageAdvAddr , "storage-adv-addr" , envOrDefault ("STORAGE_ADV_ADDR" , "" ),
122
124
"The advertised address of the static file server." )
123
125
flag .IntVar (& concurrent , "concurrent" , 2 , "The number of concurrent reconciles per controller." )
124
- flag .BoolVar (& watchAllNamespaces , "watch-all-namespaces" , true ,
125
- "Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace." )
126
126
flag .Int64Var (& helmIndexLimit , "helm-index-max-size" , helm .MaxIndexSize ,
127
127
"The max allowed size in bytes of a Helm repository index file." )
128
128
flag .Int64Var (& helmChartLimit , "helm-chart-max-size" , helm .MaxChartSize ,
@@ -153,6 +153,7 @@ func main() {
153
153
leaderElectionOptions .BindFlags (flag .CommandLine )
154
154
rateLimiterOptions .BindFlags (flag .CommandLine )
155
155
featureGates .BindFlags (flag .CommandLine )
156
+ watchOptions .BindFlags (flag .CommandLine )
156
157
157
158
flag .Parse ()
158
159
@@ -180,10 +181,28 @@ func main() {
180
181
helm .MaxChartFileSize = helmChartFileLimit
181
182
182
183
watchNamespace := ""
183
- if ! watchAllNamespaces {
184
+ if ! watchOptions . AllNamespaces {
184
185
watchNamespace = os .Getenv ("RUNTIME_NAMESPACE" )
185
186
}
186
187
188
+ var newSelectingCache ctrlcache.NewCacheFunc
189
+ watchSelector , err := helper .GetWatchSelector (watchOptions )
190
+ if err != nil {
191
+ setupLog .Error (err , "unable to configure watch label selector" )
192
+ os .Exit (1 )
193
+ }
194
+ if watchSelector != labels .Everything () {
195
+ newSelectingCache = ctrlcache .BuilderWithOptions (ctrlcache.Options {
196
+ SelectorsByObject : ctrlcache.SelectorsByObject {
197
+ & v1.GitRepository {}: {Label : watchSelector },
198
+ & v1beta2.HelmRepository {}: {Label : watchSelector },
199
+ & v1beta2.HelmChart {}: {Label : watchSelector },
200
+ & v1beta2.Bucket {}: {Label : watchSelector },
201
+ & v1beta2.OCIRepository {}: {Label : watchSelector },
202
+ },
203
+ })
204
+ }
205
+
187
206
var disableCacheFor []ctrlclient.Object
188
207
shouldCache , err := features .Enabled (features .CacheSecretsAndConfigMaps )
189
208
if err != nil {
@@ -209,6 +228,7 @@ func main() {
209
228
Namespace : watchNamespace ,
210
229
Logger : ctrl .Log ,
211
230
ClientDisableCacheFor : disableCacheFor ,
231
+ NewCache : newSelectingCache ,
212
232
})
213
233
if err != nil {
214
234
setupLog .Error (err , "unable to start manager" )
0 commit comments