Skip to content

Commit

Permalink
Merge pull request #41 from fluxcd/runtime-ns
Browse files Browse the repository at this point in the history
Watch resources in the runtime namespace only
  • Loading branch information
stefanprodan authored Jun 10, 2020
2 parents 60c30a1 + 1f25b58 commit 8b8c03f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions config/manager/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ spec:
ports:
- containerPort: 8282
name: http-prom
env:
- name: RUNTIME_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
httpGet:
port: http-prom
Expand Down
8 changes: 6 additions & 2 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
return ctrl.Result{RequeueAfter: kustomization.Spec.Interval.Duration}, nil
}

func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager) error {
type KustomizationReconcilerOptions struct {
MaxConcurrentReconciles int
}

func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager, opts KustomizationReconcilerOptions) error {
return ctrl.NewControllerManagedBy(mgr).
For(&kustomizev1.Kustomization{}).
WithEventFilter(KustomizationGarbageCollectPredicate{Log: r.Log}).
WithEventFilter(KustomizationSyncAtPredicate{}).
WithOptions(controller.Options{MaxConcurrentReconciles: 4}).
WithOptions(controller.Options{MaxConcurrentReconciles: opts.MaxConcurrentReconciles}).
Complete(r)
}

Expand Down
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ func init() {
}

func main() {
var metricsAddr string
var enableLeaderElection bool
var logJSON bool
var (
metricsAddr string
enableLeaderElection bool
concurrent int
logJSON bool
)

flag.StringVar(&metricsAddr, "metrics-addr", ":8282", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent kustomize reconciles.")
flag.BoolVar(&logJSON, "log-json", false, "Set logging to JSON format.")
flag.Parse()

Expand All @@ -64,6 +69,7 @@ func main() {
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7593cc5d.fluxcd.io",
Namespace: os.Getenv("RUNTIME_NAMESPACE"),
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand All @@ -82,7 +88,9 @@ func main() {
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Kustomization"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
}).SetupWithManager(mgr, controllers.KustomizationReconcilerOptions{
MaxConcurrentReconciles: concurrent,
}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Kustomization")
os.Exit(1)
}
Expand Down

0 comments on commit 8b8c03f

Please sign in to comment.