From fad61670b94395eae01aebb2dfc440115fe7ade5 Mon Sep 17 00:00:00 2001 From: Jintao Zhang Date: Fri, 8 Dec 2023 08:29:41 +0800 Subject: [PATCH] Backport `--emit-kubernetes-events` to release/3.0.x (#5306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Add --emit-translation-events to toggle creating of events in translation and config applying (#5296) * add --emit-translation-events to toggle creating of events in translation and config applying * update changelog * Update internal/manager/run.go Co-authored-by: Jintao Zhang * Capitalize logs Co-authored-by: Jakub Warczarek --------- Co-authored-by: Jintao Zhang Co-authored-by: Jakub Warczarek (cherry picked from commit 8b3d551ea7c93048add583f517992e8a6883e7d7) * fix: change events emit toggle name to --emit-kubernetes-events (#5299) --------- Co-authored-by: Tao Yi Co-authored-by: Grzegorz BurzyƄski --- CHANGELOG.md | 25 ++++++++++++++++++++++--- docs/cli-arguments.md | 1 + internal/manager/config.go | 2 ++ internal/manager/run.go | 11 ++++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12c1f9ddc0..e817c74d36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,11 +76,30 @@ Adding a new version? You'll need three changes: - [0.0.5](#005) - [0.0.4 and prior](#004-and-prior) -## Unreleased +## [3.0.2] -Nothing yet. +> Release date: TBD + +### Added + +- Added `--emit-kubernetes-events` CLI flag to disable the creation of events + in translating and applying configurations to Kong. + [#5296](https://github.com/Kong/kubernetes-ingress-controller/pull/5296) + [#5299](https://github.com/Kong/kubernetes-ingress-controller/pull/5299) + +## [3.0.1] + +> Release date: 2023-11-22 + +### Fixed + +- Using an Ingress with annotation `konghq.com/rewrite` and another Ingress without it pointing to the same Service, + will no longer cause synchronization loop and random request failures due to incorrect routing. + [#5218](https://github.com/Kong/kubernetes-ingress-controller/pull/5218) +- Using the same Service in one Ingress as a target for ingress rule and default backend works without issues. + [#5219](https://github.com/Kong/kubernetes-ingress-controller/pull/5219) -## 3.0.0 +## [3.0.0] > Release date: 2023-11-03 diff --git a/docs/cli-arguments.md b/docs/cli-arguments.md index 2afbe910ef..4fd6dc99a5 100644 --- a/docs/cli-arguments.md +++ b/docs/cli-arguments.md @@ -18,6 +18,7 @@ | `--dump-sensitive-config` | `bool` | Include credentials and TLS secrets in configs exposed with --dump-config flag. | `false` | | `--election-id` | `string` | Election id to use for status update. | `5b374a9e.konghq.com` | | `--election-namespace` | `string` | Leader election namespace to use when running outside a cluster. | | +| `--emit-kubernetes-events` | `bool` | Emit Kubernetes events for successful configuration applies, translation failures and configuration apply failures on managed objects. | `true` | | `--enable-controller-gwapi-gateway` | `bool` | Enable the Gateway API Gateway controller. | `true` | | `--enable-controller-gwapi-httproute` | `bool` | Enable the Gateway API HTTPRoute controller. | `true` | | `--enable-controller-gwapi-reference-grant` | `bool` | Enable the Gateway API ReferenceGrant controller. | `true` | diff --git a/internal/manager/config.go b/internal/manager/config.go index 2546852be3..f87749c85d 100644 --- a/internal/manager/config.go +++ b/internal/manager/config.go @@ -85,6 +85,7 @@ type Config struct { WatchNamespaces []string GatewayAPIControllerName string Impersonate string + EmitKubernetesEvents bool // Ingress status PublishServiceUDP OptionalNamespacedName @@ -211,6 +212,7 @@ func (c *Config) FlagSet() *pflag.FlagSet { flagSet.IntVar(&c.Concurrency, "kong-admin-concurrency", 10, "Max number of concurrent requests sent to Kong's Admin API.") flagSet.StringSliceVar(&c.WatchNamespaces, "watch-namespace", nil, `Namespace(s) in comma-separated format (or specify this flag multiple times) to watch for Kubernetes resources. Defaults to all namespaces.`) + flagSet.BoolVar(&c.EmitKubernetesEvents, "emit-kubernetes-events", true, `Emit Kubernetes events for successful configuration applies, translation failures and configuration apply failures on managed objects.`) // Ingress status flagSet.Var(flags.NewValidatedValue(&c.PublishService, namespacedNameFromFlagValue, nnTypeNameOverride), "publish-service", diff --git a/internal/manager/run.go b/internal/manager/run.go index 9b6c90b4f3..def32cb339 100644 --- a/internal/manager/run.go +++ b/internal/manager/run.go @@ -14,6 +14,7 @@ import ( "github.com/blang/semver/v4" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -140,7 +141,15 @@ func Run( } setupLog.Info("Initializing Dataplane Client") - eventRecorder := mgr.GetEventRecorderFor(KongClientEventRecorderComponentName) + var eventRecorder record.EventRecorder + if c.EmitKubernetesEvents { + setupLog.Info("Emitting Kubernetes events enabled, creating an event recorder for " + KongClientEventRecorderComponentName) + eventRecorder = mgr.GetEventRecorderFor(KongClientEventRecorderComponentName) + } else { + setupLog.Info("Emitting Kubernetes events disabled, discarding all events") + // Create an empty record.FakeRecorder with no Events channel to discard all events. + eventRecorder = &record.FakeRecorder{} + } readinessChecker := clients.NewDefaultReadinessChecker(adminAPIClientsFactory, setupLog.WithName("readiness-checker")) clientsManager, err := clients.NewAdminAPIClientsManager(