diff --git a/cmd/commands/sensorcontroller.go b/cmd/commands/controller.go similarity index 70% rename from cmd/commands/sensorcontroller.go rename to cmd/commands/controller.go index 06aaefc8f2..422672cdf6 100644 --- a/cmd/commands/sensorcontroller.go +++ b/cmd/commands/controller.go @@ -3,21 +3,21 @@ package commands import ( "github.com/spf13/cobra" - sensorcmd "github.com/argoproj/argo-events/controllers/sensor/cmd" + controllercmd "github.com/argoproj/argo-events/controllers/cmd" envpkg "github.com/argoproj/pkg/env" ) -func NewSensorControllerCommand() *cobra.Command { +func NewControllerCommand() *cobra.Command { var ( namespaced bool managedNamespace string ) command := &cobra.Command{ - Use: "sensor-controller", - Short: "Start a Sensor controller", + Use: "controller", + Short: "Start the controller", Run: func(cmd *cobra.Command, args []string) { - sensorcmd.Start(namespaced, managedNamespace) + controllercmd.Start(namespaced, managedNamespace) }, } command.Flags().BoolVar(&namespaced, "namespaced", false, "Whether to run in namespaced scope, defaults to false.") diff --git a/cmd/commands/eventbuscontroller.go b/cmd/commands/eventbuscontroller.go deleted file mode 100644 index f0b9405795..0000000000 --- a/cmd/commands/eventbuscontroller.go +++ /dev/null @@ -1,26 +0,0 @@ -package commands - -import ( - "github.com/spf13/cobra" - - eventbuscmd "github.com/argoproj/argo-events/controllers/eventbus/cmd" - envpkg "github.com/argoproj/pkg/env" -) - -func NewEventBusControllerCommand() *cobra.Command { - var ( - namespaced bool - managedNamespace string - ) - - command := &cobra.Command{ - Use: "eventbus-controller", - Short: "Start an EventBus controller", - Run: func(cmd *cobra.Command, args []string) { - eventbuscmd.Start(namespaced, managedNamespace) - }, - } - command.Flags().BoolVar(&namespaced, "namespaced", false, "Whether to run in namespaced scope, defaults to false.") - command.Flags().StringVar(&managedNamespace, "managed-namespace", envpkg.LookupEnvStringOr("NAMESPACE", "argo-events"), "The namespace that the controller watches when \"--namespaced\" is \"true\".") - return command -} diff --git a/cmd/commands/eventsourcecontroller.go b/cmd/commands/eventsourcecontroller.go deleted file mode 100644 index af128684c1..0000000000 --- a/cmd/commands/eventsourcecontroller.go +++ /dev/null @@ -1,26 +0,0 @@ -package commands - -import ( - "github.com/spf13/cobra" - - eventsourcecmd "github.com/argoproj/argo-events/controllers/eventsource/cmd" - envpkg "github.com/argoproj/pkg/env" -) - -func NewEventSourceControllerCommand() *cobra.Command { - var ( - namespaced bool - managedNamespace string - ) - - command := &cobra.Command{ - Use: "eventsource-controller", - Short: "Start an EventSource controller", - Run: func(cmd *cobra.Command, args []string) { - eventsourcecmd.Start(namespaced, managedNamespace) - }, - } - command.Flags().BoolVar(&namespaced, "namespaced", false, "Whether to run in namespaced scope, defaults to false.") - command.Flags().StringVar(&managedNamespace, "managed-namespace", envpkg.LookupEnvStringOr("NAMESPACE", "argo-events"), "The namespace that the controller watches when \"--namespaced\" is \"true\".") - return command -} diff --git a/cmd/commands/root.go b/cmd/commands/root.go index 109dbfa7a8..a2d41b1aab 100644 --- a/cmd/commands/root.go +++ b/cmd/commands/root.go @@ -23,9 +23,7 @@ func Execute() { } func init() { - rootCmd.AddCommand(NewEventBusControllerCommand()) - rootCmd.AddCommand(NewEventSourceControllerCommand()) - rootCmd.AddCommand(NewSensorControllerCommand()) + rootCmd.AddCommand(NewControllerCommand()) rootCmd.AddCommand(NewEventSourceCommand()) rootCmd.AddCommand(NewSensorCommand()) rootCmd.AddCommand(NewWebhookCommand()) diff --git a/controllers/cmd/start.go b/controllers/cmd/start.go new file mode 100644 index 0000000000..9f6a68edab --- /dev/null +++ b/controllers/cmd/start.go @@ -0,0 +1,170 @@ +package cmd + +import ( + "fmt" + "os" + + "go.uber.org/zap" + appv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/healthz" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" + "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/source" + + argoevents "github.com/argoproj/argo-events" + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/common/logging" + "github.com/argoproj/argo-events/controllers" + "github.com/argoproj/argo-events/controllers/eventbus" + "github.com/argoproj/argo-events/controllers/eventsource" + "github.com/argoproj/argo-events/controllers/sensor" + eventbusv1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" + eventsourcev1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" + sensorv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" +) + +const ( + imageEnvVar = "ARGO_EVENTS_IMAGE" +) + +func Start(namespaced bool, managedNamespace string) { + logger := logging.NewArgoEventsLogger().Named(eventbus.ControllerName) + config, err := controllers.LoadConfig(func(err error) { + logger.Errorf("Failed to reload global configuration file", zap.Error(err)) + }) + if err != nil { + logger.Fatalw("Failed to load global configuration file", zap.Error(err)) + } + imageName, defined := os.LookupEnv(imageEnvVar) + if !defined { + logger.Fatalf("required environment variable '%s' not defined", imageEnvVar) + } + opts := ctrl.Options{ + MetricsBindAddress: fmt.Sprintf(":%d", common.ControllerMetricsPort), + HealthProbeBindAddress: ":8081", + } + if namespaced { + opts.Namespace = managedNamespace + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) + if err != nil { + logger.Fatalw("unable to get a controller-runtime manager", zap.Error(err)) + } + + // Readyness probe + if err := mgr.AddReadyzCheck("readiness", healthz.Ping); err != nil { + logger.Fatalw("unable add a readiness check", zap.Error(err)) + } + + // Liveness probe + if err := mgr.AddHealthzCheck("liveness", healthz.Ping); err != nil { + logger.Fatalw("unable add a health check", zap.Error(err)) + } + + if err := eventbusv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { + logger.Fatalw("unable to add scheme", zap.Error(err)) + } + + if err := eventsourcev1alpha1.AddToScheme(mgr.GetScheme()); err != nil { + logger.Fatalw("unable to add EventSource scheme", zap.Error(err)) + } + + if err := sensorv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { + logger.Fatalw("unable to add Sensor scheme", zap.Error(err)) + } + + // EventBus controller + eventBusController, err := controller.New(eventbus.ControllerName, mgr, controller.Options{ + Reconciler: eventbus.NewReconciler(mgr.GetClient(), mgr.GetScheme(), config, logger), + }) + if err != nil { + logger.Fatalw("unable to set up EventBus controller", zap.Error(err)) + } + + // Watch EventBus and enqueue EventBus object key + if err := eventBusController.Watch(&source.Kind{Type: &eventbusv1alpha1.EventBus{}}, &handler.EnqueueRequestForObject{}, + predicate.Or( + predicate.GenerationChangedPredicate{}, + predicate.LabelChangedPredicate{}, + )); err != nil { + logger.Fatalw("unable to watch EventBus", zap.Error(err)) + } + + // Watch ConfigMaps and enqueue owning EventBus key + if err := eventBusController.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch ConfigMaps", zap.Error(err)) + } + + // Watch Secrets and enqueue owning EventBus key + if err := eventBusController.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch Secrets", zap.Error(err)) + } + + // Watch StatefulSets and enqueue owning EventBus key + if err := eventBusController.Watch(&source.Kind{Type: &appv1.StatefulSet{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch StatefulSets", zap.Error(err)) + } + + // Watch Services and enqueue owning EventBus key + if err := eventBusController.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch Services", zap.Error(err)) + } + + // EventSource controller + eventSourceController, err := controller.New(eventsource.ControllerName, mgr, controller.Options{ + Reconciler: eventsource.NewReconciler(mgr.GetClient(), mgr.GetScheme(), imageName, logger), + }) + if err != nil { + logger.Fatalw("unable to set up EventSource controller", zap.Error(err)) + } + + // Watch EventSource and enqueue EventSource object key + if err := eventSourceController.Watch(&source.Kind{Type: &eventsourcev1alpha1.EventSource{}}, &handler.EnqueueRequestForObject{}, + predicate.Or( + predicate.GenerationChangedPredicate{}, + predicate.LabelChangedPredicate{}, + )); err != nil { + logger.Fatalw("unable to watch EventSources", zap.Error(err)) + } + + // Watch Deployments and enqueue owning EventSource key + if err := eventSourceController.Watch(&source.Kind{Type: &appv1.Deployment{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventsourcev1alpha1.EventSource{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch Deployments", zap.Error(err)) + } + + // Watch Services and enqueue owning EventSource key + if err := eventSourceController.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventsourcev1alpha1.EventSource{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch Services", zap.Error(err)) + } + + // Sensor controller + sensorController, err := controller.New(sensor.ControllerName, mgr, controller.Options{ + Reconciler: sensor.NewReconciler(mgr.GetClient(), mgr.GetScheme(), imageName, logger), + }) + if err != nil { + logger.Fatalw("unable to set up Sensor controller", zap.Error(err)) + } + + // Watch Sensor and enqueue Sensor object key + if err := sensorController.Watch(&source.Kind{Type: &sensorv1alpha1.Sensor{}}, &handler.EnqueueRequestForObject{}, + predicate.Or( + predicate.GenerationChangedPredicate{}, + predicate.LabelChangedPredicate{}, + )); err != nil { + logger.Fatalw("unable to watch Sensors", zap.Error(err)) + } + + // Watch Deployments and enqueue owning Sensor key + if err := sensorController.Watch(&source.Kind{Type: &appv1.Deployment{}}, &handler.EnqueueRequestForOwner{OwnerType: &sensorv1alpha1.Sensor{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { + logger.Fatalw("unable to watch Deployments", zap.Error(err)) + } + + logger.Infow("starting controller manager", "version", argoevents.GetVersion()) + if err := mgr.Start(signals.SetupSignalHandler()); err != nil { + logger.Fatalw("unable to run eventbus controller", zap.Error(err)) + } +} diff --git a/controllers/eventbus/cmd/start.go b/controllers/eventbus/cmd/start.go deleted file mode 100644 index 8ae19a9a56..0000000000 --- a/controllers/eventbus/cmd/start.go +++ /dev/null @@ -1,110 +0,0 @@ -package cmd - -import ( - "fmt" - - "go.uber.org/zap" - appv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/healthz" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - argoevents "github.com/argoproj/argo-events" - "github.com/argoproj/argo-events/common" - "github.com/argoproj/argo-events/common/logging" - "github.com/argoproj/argo-events/controllers" - "github.com/argoproj/argo-events/controllers/eventbus" - eventbusv1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" - eventsourcev1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" - sensorv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" -) - -func Start(namespaced bool, managedNamespace string) { - logger := logging.NewArgoEventsLogger().Named(eventbus.ControllerName) - config, err := controllers.LoadConfig(func(err error) { - logger.Errorf("Failed to reload global configuration file", zap.Error(err)) - }) - if err != nil { - logger.Fatalw("Failed to load global configuration file", zap.Error(err)) - } - opts := ctrl.Options{ - MetricsBindAddress: fmt.Sprintf(":%d", common.ControllerMetricsPort), - HealthProbeBindAddress: ":8081", - } - if namespaced { - opts.Namespace = managedNamespace - } - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) - if err != nil { - logger.Fatalw("unable to get a controller-runtime manager", zap.Error(err)) - } - - // Readyness probe - if err := mgr.AddReadyzCheck("readiness", healthz.Ping); err != nil { - logger.Fatalw("unable add a readiness check", zap.Error(err)) - } - - // Liveness probe - if err := mgr.AddHealthzCheck("liveness", healthz.Ping); err != nil { - logger.Fatalw("unable add a health check", zap.Error(err)) - } - - if err := eventbusv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add scheme", zap.Error(err)) - } - - if err := eventsourcev1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add EventSource scheme", zap.Error(err)) - } - - if err := sensorv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add Sensor scheme", zap.Error(err)) - } - - // A controller with DefaultControllerRateLimiter - c, err := controller.New(eventbus.ControllerName, mgr, controller.Options{ - Reconciler: eventbus.NewReconciler(mgr.GetClient(), mgr.GetScheme(), config, logger), - }) - if err != nil { - logger.Fatalw("unable to set up individual controller", zap.Error(err)) - } - - // Watch EventBus and enqueue EventBus object key - if err := c.Watch(&source.Kind{Type: &eventbusv1alpha1.EventBus{}}, &handler.EnqueueRequestForObject{}, - predicate.Or( - predicate.GenerationChangedPredicate{}, - predicate.LabelChangedPredicate{}, - )); err != nil { - logger.Fatalw("unable to watch EventBus", zap.Error(err)) - } - - // Watch ConfigMaps and enqueue owning EventBus key - if err := c.Watch(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch ConfigMaps", zap.Error(err)) - } - - // Watch Secrets and enqueue owning EventBus key - if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch Secrets", zap.Error(err)) - } - - // Watch StatefulSets and enqueue owning EventBus key - if err := c.Watch(&source.Kind{Type: &appv1.StatefulSet{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch StatefulSets", zap.Error(err)) - } - - // Watch Services and enqueue owning EventBus key - if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventbusv1alpha1.EventBus{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch Services", zap.Error(err)) - } - - logger.Infow("starting eventbus controller", "version", argoevents.GetVersion()) - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - logger.Fatalw("unable to run eventbus controller", zap.Error(err)) - } -} diff --git a/controllers/eventsource/cmd/start.go b/controllers/eventsource/cmd/start.go deleted file mode 100644 index 3f95ac528e..0000000000 --- a/controllers/eventsource/cmd/start.go +++ /dev/null @@ -1,97 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - - "go.uber.org/zap" - appv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/healthz" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - argoevents "github.com/argoproj/argo-events" - "github.com/argoproj/argo-events/common" - "github.com/argoproj/argo-events/common/logging" - "github.com/argoproj/argo-events/controllers/eventsource" - eventbusv1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" - eventsourcev1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" -) - -const ( - eventSourceImageEnvVar = "EVENTSOURCE_IMAGE" -) - -func Start(namespaced bool, managedNamespace string) { - logger := logging.NewArgoEventsLogger().Named(eventsource.ControllerName) - eventSourceImage, defined := os.LookupEnv(eventSourceImageEnvVar) - if !defined { - logger.Fatalf("required environment variable '%s' not defined", eventSourceImageEnvVar) - } - opts := ctrl.Options{ - MetricsBindAddress: fmt.Sprintf(":%d", common.ControllerMetricsPort), - HealthProbeBindAddress: ":8081", - } - if namespaced { - opts.Namespace = managedNamespace - } - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) - if err != nil { - logger.Fatalw("unable to get a controller-runtime manager", zap.Error(err)) - } - - // Readyness probe - if err := mgr.AddReadyzCheck("readiness", healthz.Ping); err != nil { - logger.Fatalw("unable add a readiness check", zap.Error(err)) - } - - // Liveness probe - if err := mgr.AddHealthzCheck("liveness", healthz.Ping); err != nil { - logger.Fatalw("unable add a health check", zap.Error(err)) - } - - if err := eventsourcev1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add EventSource scheme", zap.Error(err)) - } - - if err := eventbusv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add EventBus scheme", zap.Error(err)) - } - - // A controller with DefaultControllerRateLimiter - c, err := controller.New(eventsource.ControllerName, mgr, controller.Options{ - Reconciler: eventsource.NewReconciler(mgr.GetClient(), mgr.GetScheme(), eventSourceImage, logger), - }) - if err != nil { - logger.Fatalw("unable to set up individual controller", zap.Error(err)) - } - - // Watch EventSource and enqueue EventSource object key - if err := c.Watch(&source.Kind{Type: &eventsourcev1alpha1.EventSource{}}, &handler.EnqueueRequestForObject{}, - predicate.Or( - predicate.GenerationChangedPredicate{}, - predicate.LabelChangedPredicate{}, - )); err != nil { - logger.Fatalw("unable to watch EventSources", zap.Error(err)) - } - - // Watch Deployments and enqueue owning EventSource key - if err := c.Watch(&source.Kind{Type: &appv1.Deployment{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventsourcev1alpha1.EventSource{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch Deployments", zap.Error(err)) - } - - // Watch Services and enqueue owning EventSource key - if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{OwnerType: &eventsourcev1alpha1.EventSource{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch Services", zap.Error(err)) - } - - logger.Infow("starting eventsource controller", "version", argoevents.GetVersion()) - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - logger.Fatalw("unable to run eventsource controller", zap.Error(err)) - } -} diff --git a/controllers/sensor/cmd/start.go b/controllers/sensor/cmd/start.go deleted file mode 100644 index 4695a20a6b..0000000000 --- a/controllers/sensor/cmd/start.go +++ /dev/null @@ -1,91 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - - "go.uber.org/zap" - appv1 "k8s.io/api/apps/v1" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/healthz" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - argoevents "github.com/argoproj/argo-events" - "github.com/argoproj/argo-events/common" - "github.com/argoproj/argo-events/common/logging" - "github.com/argoproj/argo-events/controllers/sensor" - eventbusv1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" - sensorv1alpha1 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" -) - -const ( - sensorImageEnvVar = "SENSOR_IMAGE" -) - -func Start(namespaced bool, managedNamespace string) { - logger := logging.NewArgoEventsLogger().Named(sensor.ControllerName) - sensorImage, defined := os.LookupEnv(sensorImageEnvVar) - if !defined { - logger.Fatalf("required environment variable '%s' not defined", sensorImageEnvVar) - } - opts := ctrl.Options{ - MetricsBindAddress: fmt.Sprintf(":%d", common.ControllerMetricsPort), - HealthProbeBindAddress: ":8081", - } - if namespaced { - opts.Namespace = managedNamespace - } - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), opts) - if err != nil { - logger.Fatalw("unable to get a controller-runtime manager", zap.Error(err)) - } - - // Readyness probe - if err := mgr.AddReadyzCheck("readiness", healthz.Ping); err != nil { - logger.Fatalw("unable add a readiness check", zap.Error(err)) - } - - // Liveness probe - if err := mgr.AddHealthzCheck("liveness", healthz.Ping); err != nil { - logger.Fatalw("unable add a health check", zap.Error(err)) - } - - if err := sensorv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("unable to add Sensor scheme", zap.Error(err)) - } - - if err := eventbusv1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - logger.Fatalw("uunable to add EventBus scheme", zap.Error(err)) - } - - // A controller with DefaultControllerRateLimiter - c, err := controller.New(sensor.ControllerName, mgr, controller.Options{ - Reconciler: sensor.NewReconciler(mgr.GetClient(), mgr.GetScheme(), sensorImage, logger), - }) - if err != nil { - logger.Fatalw("unable to set up individual controller", zap.Error(err)) - } - - // Watch Sensor and enqueue Sensor object key - if err := c.Watch(&source.Kind{Type: &sensorv1alpha1.Sensor{}}, &handler.EnqueueRequestForObject{}, - predicate.Or( - predicate.GenerationChangedPredicate{}, - predicate.LabelChangedPredicate{}, - )); err != nil { - logger.Fatalw("unable to watch Sensors", zap.Error(err)) - } - - // Watch Deployments and enqueue owning Sensor key - if err := c.Watch(&source.Kind{Type: &appv1.Deployment{}}, &handler.EnqueueRequestForOwner{OwnerType: &sensorv1alpha1.Sensor{}, IsController: true}, predicate.GenerationChangedPredicate{}); err != nil { - logger.Fatalw("unable to watch Deployments", zap.Error(err)) - } - - logger.Infow("starting sensor controller", "version", argoevents.GetVersion()) - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - logger.Fatalw("unable to run sensor controller", zap.Error(err)) - } -} diff --git a/manifests/base/eventbus-controller/controller-config.yaml b/manifests/base/controller-manager/controller-config.yaml similarity index 100% rename from manifests/base/eventbus-controller/controller-config.yaml rename to manifests/base/controller-manager/controller-config.yaml diff --git a/manifests/base/eventbus-controller/eventbus-controller-deployment.yaml b/manifests/base/controller-manager/controller-manager-deployment.yaml similarity index 81% rename from manifests/base/eventbus-controller/eventbus-controller-deployment.yaml rename to manifests/base/controller-manager/controller-manager-deployment.yaml index 0f77e046b4..82dcfd5e4f 100644 --- a/manifests/base/eventbus-controller/eventbus-controller-deployment.yaml +++ b/manifests/base/controller-manager/controller-manager-deployment.yaml @@ -1,32 +1,34 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: eventbus-controller + name: controller-manager spec: replicas: 1 selector: matchLabels: - app: eventbus-controller + app: controller-manager template: metadata: labels: - app: eventbus-controller + app: controller-manager spec: serviceAccountName: argo-events-sa securityContext: runAsNonRoot: true runAsUser: 9731 containers: - - name: eventbus-controller + - name: controller-manager image: quay.io/argoproj/argo-events:latest imagePullPolicy: Always args: - - eventbus-controller + - controller env: - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace + - name: ARGO_EVENTS_IMAGE + value: quay.io/argoproj/argo-events:latest volumeMounts: - mountPath: /etc/argo-events name: controller-config-volume diff --git a/manifests/base/eventbus-controller/kustomization.yaml b/manifests/base/controller-manager/kustomization.yaml similarity index 72% rename from manifests/base/eventbus-controller/kustomization.yaml rename to manifests/base/controller-manager/kustomization.yaml index 837cfd25a4..4e14874a9c 100644 --- a/manifests/base/eventbus-controller/kustomization.yaml +++ b/manifests/base/controller-manager/kustomization.yaml @@ -3,4 +3,4 @@ kind: Kustomization resources: - controller-config.yaml - - eventbus-controller-deployment.yaml + - controller-manager-deployment.yaml diff --git a/manifests/base/eventsource-controller/eventsource-controller-deployment.yaml b/manifests/base/eventsource-controller/eventsource-controller-deployment.yaml deleted file mode 100644 index f7a91e790b..0000000000 --- a/manifests/base/eventsource-controller/eventsource-controller-deployment.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: eventsource-controller -spec: - replicas: 1 - selector: - matchLabels: - app: eventsource-controller - template: - metadata: - labels: - app: eventsource-controller - spec: - serviceAccountName: argo-events-sa - securityContext: - runAsNonRoot: true - runAsUser: 9731 - containers: - - name: eventsource-controller - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - args: - - eventsource-controller - env: - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: EVENTSOURCE_IMAGE - value: quay.io/argoproj/argo-events:latest - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 diff --git a/manifests/base/eventsource-controller/kustomization.yaml b/manifests/base/eventsource-controller/kustomization.yaml deleted file mode 100644 index 2e4af20477..0000000000 --- a/manifests/base/eventsource-controller/kustomization.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization - -resources: - - eventsource-controller-deployment.yaml diff --git a/manifests/base/kustomization.yaml b/manifests/base/kustomization.yaml index b7ef810883..ef6f39f3da 100644 --- a/manifests/base/kustomization.yaml +++ b/manifests/base/kustomization.yaml @@ -8,9 +8,7 @@ kind: Kustomization resources: - crds - argo-events-sa.yaml - - eventsource-controller - - sensor-controller - - eventbus-controller + - controller-manager images: - name: quay.io/argoproj/argo-events @@ -21,25 +19,12 @@ patchesStrategicMerge: apiVersion: apps/v1 kind: Deployment metadata: - name: eventsource-controller + name: controller-manager spec: template: spec: containers: - - name: eventsource-controller + - name: controller-manager env: - - name: EVENTSOURCE_IMAGE - value: quay.io/argoproj/argo-events:latest - - |- - apiVersion: apps/v1 - kind: Deployment - metadata: - name: sensor-controller - spec: - template: - spec: - containers: - - name: sensor-controller - env: - - name: SENSOR_IMAGE + - name: ARGO_EVENTS_IMAGE value: quay.io/argoproj/argo-events:latest diff --git a/manifests/base/sensor-controller/kustomization.yaml b/manifests/base/sensor-controller/kustomization.yaml deleted file mode 100644 index 6b120ddd82..0000000000 --- a/manifests/base/sensor-controller/kustomization.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization - -resources: - - sensor-controller-deployment.yaml diff --git a/manifests/base/sensor-controller/sensor-controller-deployment.yaml b/manifests/base/sensor-controller/sensor-controller-deployment.yaml deleted file mode 100644 index 57b43169b5..0000000000 --- a/manifests/base/sensor-controller/sensor-controller-deployment.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: sensor-controller -spec: - replicas: 1 - selector: - matchLabels: - app: sensor-controller - template: - metadata: - labels: - app: sensor-controller - spec: - serviceAccountName: argo-events-sa - securityContext: - runAsNonRoot: true - runAsUser: 9731 - containers: - - name: sensor-controller - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - args: - - sensor-controller - env: - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: SENSOR_IMAGE - value: quay.io/argoproj/argo-events:latest - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 diff --git a/manifests/install.yaml b/manifests/install.yaml index 23b0eaac99..be23bc12ef 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -321,22 +321,24 @@ metadata: apiVersion: apps/v1 kind: Deployment metadata: - name: eventbus-controller + name: controller-manager namespace: argo-events spec: replicas: 1 selector: matchLabels: - app: eventbus-controller + app: controller-manager template: metadata: labels: - app: eventbus-controller + app: controller-manager spec: containers: - args: - - eventbus-controller + - controller env: + - name: ARGO_EVENTS_IMAGE + value: quay.io/argoproj/argo-events:latest - name: NAMESPACE valueFrom: fieldRef: @@ -349,7 +351,7 @@ spec: port: 8081 initialDelaySeconds: 3 periodSeconds: 3 - name: eventbus-controller + name: controller-manager readinessProbe: httpGet: path: /readyz @@ -367,93 +369,3 @@ spec: - configMap: name: argo-events-controller-config name: controller-config-volume ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: eventsource-controller - namespace: argo-events -spec: - replicas: 1 - selector: - matchLabels: - app: eventsource-controller - template: - metadata: - labels: - app: eventsource-controller - spec: - containers: - - args: - - eventsource-controller - env: - - name: EVENTSOURCE_IMAGE - value: quay.io/argoproj/argo-events:latest - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - name: eventsource-controller - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - securityContext: - runAsNonRoot: true - runAsUser: 9731 - serviceAccountName: argo-events-sa ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: sensor-controller - namespace: argo-events -spec: - replicas: 1 - selector: - matchLabels: - app: sensor-controller - template: - metadata: - labels: - app: sensor-controller - spec: - containers: - - args: - - sensor-controller - env: - - name: SENSOR_IMAGE - value: quay.io/argoproj/argo-events:latest - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - name: sensor-controller - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - securityContext: - runAsNonRoot: true - runAsUser: 9731 - serviceAccountName: argo-events-sa diff --git a/manifests/namespace-install.yaml b/manifests/namespace-install.yaml index 11bdfd3cde..cb975ab222 100644 --- a/manifests/namespace-install.yaml +++ b/manifests/namespace-install.yaml @@ -241,23 +241,25 @@ metadata: apiVersion: apps/v1 kind: Deployment metadata: - name: eventbus-controller + name: controller-manager namespace: argo-events spec: replicas: 1 selector: matchLabels: - app: eventbus-controller + app: controller-manager template: metadata: labels: - app: eventbus-controller + app: controller-manager spec: containers: - args: - - eventbus-controller + - controller - --namespaced env: + - name: ARGO_EVENTS_IMAGE + value: quay.io/argoproj/argo-events:latest - name: NAMESPACE valueFrom: fieldRef: @@ -270,7 +272,7 @@ spec: port: 8081 initialDelaySeconds: 3 periodSeconds: 3 - name: eventbus-controller + name: controller-manager readinessProbe: httpGet: path: /readyz @@ -288,95 +290,3 @@ spec: - configMap: name: argo-events-controller-config name: controller-config-volume ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: eventsource-controller - namespace: argo-events -spec: - replicas: 1 - selector: - matchLabels: - app: eventsource-controller - template: - metadata: - labels: - app: eventsource-controller - spec: - containers: - - args: - - eventsource-controller - - --namespaced - env: - - name: EVENTSOURCE_IMAGE - value: quay.io/argoproj/argo-events:latest - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - name: eventsource-controller - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - securityContext: - runAsNonRoot: true - runAsUser: 9731 - serviceAccountName: argo-events-sa ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: sensor-controller - namespace: argo-events -spec: - replicas: 1 - selector: - matchLabels: - app: sensor-controller - template: - metadata: - labels: - app: sensor-controller - spec: - containers: - - args: - - sensor-controller - - --namespaced - env: - - name: SENSOR_IMAGE - value: quay.io/argoproj/argo-events:latest - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - image: quay.io/argoproj/argo-events:latest - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - name: sensor-controller - readinessProbe: - httpGet: - path: /readyz - port: 8081 - initialDelaySeconds: 3 - periodSeconds: 3 - securityContext: - runAsNonRoot: true - runAsUser: 9731 - serviceAccountName: argo-events-sa diff --git a/test/manifests/kustomization.yaml b/test/manifests/kustomization.yaml index d7f80bd05e..21758cd9b8 100644 --- a/test/manifests/kustomization.yaml +++ b/test/manifests/kustomization.yaml @@ -12,21 +12,7 @@ patches: value: IfNotPresent target: kind: Deployment - name: eventbus-controller - - patch: |- - - op: replace - path: /spec/template/spec/containers/0/imagePullPolicy - value: IfNotPresent - target: - kind: Deployment - name: eventsource-controller - - patch: |- - - op: replace - path: /spec/template/spec/containers/0/imagePullPolicy - value: IfNotPresent - target: - kind: Deployment - name: sensor-controller + name: controller-manager - patch: |- - op: replace path: /spec/template/spec/containers/0/imagePullPolicy @@ -42,16 +28,7 @@ patches: value: IfNotPresent target: kind: Deployment - name: eventsource-controller - - patch: |- - - op: add - path: /spec/template/spec/containers/0/env/- - value: - name: IMAGE_PULL_POLICY - value: IfNotPresent - target: - kind: Deployment - name: sensor-controller + name: controller-manager namespace: argo-events