Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redpanda-Operator: code clean up eventrecorder #12609

Merged
merged 2 commits into from
Aug 4, 2023
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
44 changes: 43 additions & 1 deletion src/go/k8s/apis/redpanda/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions src/go/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
helmController "github.com/fluxcd/helm-controller/controllers"
"github.com/fluxcd/pkg/runtime/client"
helper "github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/events"
"github.com/fluxcd/pkg/runtime/logger"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
helmSourceController "github.com/fluxcd/source-controller/controllers"
Expand Down Expand Up @@ -100,6 +101,7 @@ func main() {
metricsTimeout time.Duration
restrictToRedpandaVersion string
namespace string
eventsAddr string

// allowPVCDeletion controls the PVC deletion feature in the Cluster custom resource.
// PVCs will be deleted when its Pod has been deleted and the Node that Pod is assigned to
Expand All @@ -109,6 +111,7 @@ func main() {
debug bool
)

flag.StringVar(&eventsAddr, "events-addr", "", "The address of the events receiver.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-bind-address", ":8082", "The address the metric endpoint binds to.")
Expand Down Expand Up @@ -193,12 +196,18 @@ func main() {
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(30*time.Second, 60*time.Second),
}

var helmReleaseEventRecorder *events.Recorder
if helmReleaseEventRecorder, err = events.NewRecorder(mgr, ctrl.Log, eventsAddr, "HelmReleaseReconciler"); err != nil {
setupLog.Error(err, "unable to create event recorder for: HelmReleaseReconciler")
os.Exit(1)
}

// Helm Release Controller
helmRelease := helmController.HelmReleaseReconciler{
Client: mgr.GetClient(),
Config: mgr.GetConfig(),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("HelmReleaseReconciler"),
EventRecorder: helmReleaseEventRecorder,
ClientOpts: clientOptions,
KubeConfigOpts: kubeConfigOpts,
}
Expand All @@ -207,22 +216,34 @@ func main() {
}

// Helm Chart Controller
var helmChartEventRecorder *events.Recorder
if helmChartEventRecorder, err = events.NewRecorder(mgr, ctrl.Log, eventsAddr, "HelmChartReconciler"); err != nil {
setupLog.Error(err, "unable to create event recorder for: HelmChartReconciler")
os.Exit(1)
}

helmChart := helmSourceController.HelmChartReconciler{
Client: mgr.GetClient(),
RegistryClientGenerator: redpandacontrollers.ClientGenerator,
Getters: getters,
Metrics: metricsH,
Storage: storage,
EventRecorder: mgr.GetEventRecorderFor("HelmChartReconciler"),
EventRecorder: helmChartEventRecorder,
}
if err = helmChart.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "Unable to create controller", "controller", "HelmChart")
}

// Helm Repository Controller
var helmRepositoryEventRecorder *events.Recorder
if helmRepositoryEventRecorder, err = events.NewRecorder(mgr, ctrl.Log, eventsAddr, "HelmRepositoryReconciler"); err != nil {
setupLog.Error(err, "unable to create event recorder for: HelmRepositoryReconciler")
os.Exit(1)
}

helmRepository := helmSourceController.HelmRepositoryReconciler{
Client: mgr.GetClient(),
EventRecorder: mgr.GetEventRecorderFor("HelmRepositoryReconciler"),
EventRecorder: helmRepositoryEventRecorder,
Getters: getters,
ControllerName: "redpanda-controller",
TTL: 15 * time.Minute,
Expand All @@ -241,11 +262,18 @@ func main() {

redpandacontrollers.StartFileServer(storage.BasePath, storageAddr, setupLog)
}()
// Redpanda Reconciler

var redpandaEventRecorder *events.Recorder
if redpandaEventRecorder, err = events.NewRecorder(mgr, ctrl.Log, eventsAddr, "RedpandaReconciler"); err != nil {
setupLog.Error(err, "unable to create event recorder for: RedpandaReconciler")
os.Exit(1)
}

if err = (&redpandacontrollers.RedpandaReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("RedpandaReconciler"),
EventRecorder: redpandaEventRecorder,
RequeueHelmDeps: 10 * time.Second,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Redpanda")
Expand Down
Loading