Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Pass config from main to the controller. #202

Merged
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
9 changes: 7 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ import (
"knative.dev/pkg/signals"
)

var (
masterURL = flag.String("master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
)

func main() {
flag.Parse()

cfg, err := sharedmain.GetConfig(*knativeeventing.MasterURL, *knativeeventing.Kubeconfig)
cfg, err := sharedmain.GetConfig(*masterURL, *kubeconfig)
if err != nil {
log.Fatal("Error building kubeconfig", err)
}
sharedmain.MainWithConfig(signals.NewContext(), "eventing-operator", cfg, knativeeventing.NewController)
sharedmain.MainWithConfig(signals.NewContext(), "eventing-operator", cfg, knativeeventing.NewControllerWithConfig(cfg))
}
69 changes: 28 additions & 41 deletions pkg/reconciler/knativeeventing/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package knativeeventing

import (
"context"
"flag"
"os"
"path/filepath"

Expand All @@ -25,66 +24,54 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/cache"

"k8s.io/client-go/rest"
"knative.dev/eventing-operator/pkg/apis/eventing/v1alpha1"
knativeEventinginformer "knative.dev/eventing-operator/pkg/client/injection/informers/eventing/v1alpha1/knativeeventing"
rbase "knative.dev/eventing-operator/pkg/reconciler"
deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection/sharedmain"
)

const (
controllerAgentName = "knativeeventing-controller"
reconcilerName = "KnativeEventing"
)

var (
recursive = flag.Bool("recursive", false, "If filename is a directory, process all manifests recursively")
MasterURL = flag.String("master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
Kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
)

// NewController initializes the controller and is called by the generated code
// NewControllerWithConfig initializes the controller and is called by the generated code
// Registers eventhandlers to enqueue events
func NewController(
ctx context.Context,
cmw configmap.Watcher,
) *controller.Impl {
knativeEventingInformer := knativeEventinginformer.Get(ctx)
deploymentInformer := deploymentinformer.Get(ctx)
func NewControllerWithConfig(cfg *rest.Config) func(context.Context, configmap.Watcher) *controller.Impl {
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
knativeEventingInformer := knativeEventinginformer.Get(ctx)
deploymentInformer := deploymentinformer.Get(ctx)

c := &Reconciler{
Base: rbase.NewBase(ctx, controllerAgentName, cmw),
knativeEventingLister: knativeEventingInformer.Lister(),
eventings: sets.String{},
}
c := &Reconciler{
Base: rbase.NewBase(ctx, controllerAgentName, cmw),
knativeEventingLister: knativeEventingInformer.Lister(),
eventings: sets.String{},
}

koDataDir := os.Getenv("KO_DATA_PATH")
koDataDir := os.Getenv("KO_DATA_PATH")

cfg, err := sharedmain.GetConfig(*MasterURL, *Kubeconfig)
if err != nil {
c.Logger.Error(err, "Error building kubeconfig")
}
config, err := mfc.NewManifest(filepath.Join(koDataDir, "knative-eventing/"), cfg,
mf.UseLogger(zapr.NewLogger(c.Logger.Desugar()).WithName("manifestival")))
if err != nil {
c.Logger.Error(err, "Error creating the Manifest for knative-eventing")
os.Exit(1)
}

config, err := mfc.NewManifest(filepath.Join(koDataDir, "knative-eventing/"), cfg,
mf.UseLogger(zapr.NewLogger(c.Logger.Desugar()).WithName("manifestival")))
if err != nil {
c.Logger.Error(err, "Error creating the Manifest for knative-eventing")
os.Exit(1)
}

c.config = config
impl := controller.NewImpl(c, c.Logger, reconcilerName)
c.config = config
impl := controller.NewImpl(c, c.Logger, reconcilerName)

c.Logger.Info("Setting up event handlers for %s", reconcilerName)
c.Logger.Info("Setting up event handlers for %s", reconcilerName)

knativeEventingInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))
knativeEventingInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))

deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("KnativeEventing")),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.Filter(v1alpha1.SchemeGroupVersion.WithKind("KnativeEventing")),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})

return impl
return impl
}
}