From b208dfe25590ee7d16351ec61028795d6be9cba2 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Fri, 22 Nov 2024 08:48:33 +0100 Subject: [PATCH 01/11] Add runtime + shoot to FSM logs --- internal/controller/runtime/runtime_controller.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index f621ae40..4e84dbbe 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -62,8 +62,18 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) r.Log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) + runtimeID, ok := runtime.Labels["kyma-project.io/runtime-id"] + if !ok { + runtimeID = runtime.Name + } + + shootName, ok := runtime.Labels["kyma-project.io/shoot-name"] + if !ok { + shootName = "N/D" + } + stateFSM := fsm.NewFsm( - r.Log.WithName(fmt.Sprintf("reqID %d", requCounter)), + r.Log.WithName(fmt.Sprintf("reqID %d", requCounter)).WithValues("runtime", runtimeID, "shoot", shootName), r.Cfg, fsm.K8s{ Client: r.Client, From d5c39b1d3df3096ddeee9458d7c24fb432f443b8 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Fri, 22 Nov 2024 08:56:39 +0100 Subject: [PATCH 02/11] Reorder fields and logs --- internal/controller/runtime/runtime_controller.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index 4e84dbbe..4a71edd2 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -60,8 +60,6 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) }, client.IgnoreNotFound(err) } - r.Log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) - runtimeID, ok := runtime.Labels["kyma-project.io/runtime-id"] if !ok { runtimeID = runtime.Name @@ -72,8 +70,11 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) shootName = "N/D" } + log := r.Log.WithValues("runtime", runtimeID, "shoot", shootName) + log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) + stateFSM := fsm.NewFsm( - r.Log.WithName(fmt.Sprintf("reqID %d", requCounter)).WithValues("runtime", runtimeID, "shoot", shootName), + log.WithName(fmt.Sprintf("reqID %d", requCounter)), r.Cfg, fsm.K8s{ Client: r.Client, From be42c93dd40a78ef2ae1097431c34a1f82e33c85 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 08:50:39 +0100 Subject: [PATCH 03/11] Improve log field names --- internal/controller/runtime/runtime_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index 4a71edd2..abe33778 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -70,7 +70,7 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) shootName = "N/D" } - log := r.Log.WithValues("runtime", runtimeID, "shoot", shootName) + log := r.Log.WithValues("runtimeID", runtimeID, "shootID", shootName) log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) stateFSM := fsm.NewFsm( From 240ef20165d02c564a7a4fe3c6c1eb8e6bb07816 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 08:53:44 +0100 Subject: [PATCH 04/11] Log patch shoot error --- internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go index 506fd052..b435f8a9 100644 --- a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go +++ b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go @@ -67,7 +67,7 @@ func sFnPatchExistingShoot(ctx context.Context, m *fsm, s *systemState) (stateFn m.log.Error(err, "Failed to patch shoot object, exiting with no retry") m.Metrics.IncRuntimeFSMStopCounter() - return updateStatePendingWithErrorAndStop(&s.instance, imv1.ConditionTypeRuntimeProvisioned, imv1.ConditionReasonProcessingErr, "Shoot patch error") + return updateStatePendingWithErrorAndStop(&s.instance, imv1.ConditionTypeRuntimeProvisioned, imv1.ConditionReasonProcessingErr, fmt.Sprintf("Gardener API shoot patch error: %v", err)) } if updatedShoot.Generation == s.shoot.Generation { From 36eee00c9f28470b54f00cc2e88250757b664d11 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 09:01:57 +0100 Subject: [PATCH 05/11] Add missing import --- internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go index b435f8a9..f45df6c9 100644 --- a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go +++ b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go @@ -3,6 +3,7 @@ package fsm import ( "context" "slices" + "fmt" gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" imv1 "github.com/kyma-project/infrastructure-manager/api/v1" From 43bd6793daa43226a9260ab4429cf6b5006aac2c Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 10:48:06 +0100 Subject: [PATCH 06/11] Sort imports --- hack/runtime-migrator/cmd/main.go | 9 ++++----- hack/runtime-migrator/cmd/migration.go | 2 +- hack/runtime-migrator/internal/config/config.go | 3 ++- hack/runtime-migrator/internal/migration/output.go | 7 ++++--- hack/runtime-migrator/internal/runtime/migrator.go | 1 + hack/runtime-migrator/internal/runtime/verifier.go | 3 ++- internal/controller/metrics/mocks/Metrics.go | 6 ++---- .../controller/runtime/fsm/runtime_fsm_patch_shoot.go | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hack/runtime-migrator/cmd/main.go b/hack/runtime-migrator/cmd/main.go index eb00d060..71e5c25b 100644 --- a/hack/runtime-migrator/cmd/main.go +++ b/hack/runtime-migrator/cmd/main.go @@ -11,18 +11,17 @@ import ( "strings" "time" - "github.com/go-playground/validator/v10" - "github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/auditlogs" - v12 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/types" - "github.com/gardener/gardener/pkg/apis/core/v1beta1" gardener_types "github.com/gardener/gardener/pkg/client/core/clientset/versioned/typed/core/v1beta1" + "github.com/go-playground/validator/v10" "github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app/internal/config" kimConfig "github.com/kyma-project/infrastructure-manager/pkg/config" "github.com/kyma-project/infrastructure-manager/pkg/gardener" "github.com/kyma-project/infrastructure-manager/pkg/gardener/kubeconfig" + "github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/auditlogs" "github.com/pkg/errors" + v12 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" diff --git a/hack/runtime-migrator/cmd/migration.go b/hack/runtime-migrator/cmd/migration.go index 263d38ef..a496fe96 100644 --- a/hack/runtime-migrator/cmd/migration.go +++ b/hack/runtime-migrator/cmd/migration.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "github.com/pkg/errors" "log/slog" "github.com/gardener/gardener/pkg/apis/core/v1beta1" @@ -15,6 +14,7 @@ import ( "github.com/kyma-project/infrastructure-manager/pkg/config" "github.com/kyma-project/infrastructure-manager/pkg/gardener/kubeconfig" "github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/auditlogs" + "github.com/pkg/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/hack/runtime-migrator/internal/config/config.go b/hack/runtime-migrator/internal/config/config.go index 451968a9..2f1a60ac 100644 --- a/hack/runtime-migrator/internal/config/config.go +++ b/hack/runtime-migrator/internal/config/config.go @@ -3,11 +3,12 @@ package config import ( "flag" "fmt" + "log" + v1 "github.com/kyma-project/infrastructure-manager/api/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/clientcmd" - "log" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/hack/runtime-migrator/internal/migration/output.go b/hack/runtime-migrator/internal/migration/output.go index e34d13bc..24d4fff0 100644 --- a/hack/runtime-migrator/internal/migration/output.go +++ b/hack/runtime-migrator/internal/migration/output.go @@ -3,12 +3,13 @@ package migration import ( "encoding/json" "fmt" - v1 "github.com/kyma-project/infrastructure-manager/api/v1" - "github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app/internal/runtime" "os" "path" - "sigs.k8s.io/yaml" "time" + + v1 "github.com/kyma-project/infrastructure-manager/api/v1" + "github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app/internal/runtime" + "sigs.k8s.io/yaml" ) type OutputWriter struct { diff --git a/hack/runtime-migrator/internal/runtime/migrator.go b/hack/runtime-migrator/internal/runtime/migrator.go index d63aa723..45574acd 100644 --- a/hack/runtime-migrator/internal/runtime/migrator.go +++ b/hack/runtime-migrator/internal/runtime/migrator.go @@ -3,6 +3,7 @@ package runtime import ( "context" "fmt" + "github.com/gardener/gardener/pkg/apis/core/v1beta1" v1 "github.com/kyma-project/infrastructure-manager/api/v1" migrator "github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app/internal/config" diff --git a/hack/runtime-migrator/internal/runtime/verifier.go b/hack/runtime-migrator/internal/runtime/verifier.go index 87451a54..af3e40b0 100644 --- a/hack/runtime-migrator/internal/runtime/verifier.go +++ b/hack/runtime-migrator/internal/runtime/verifier.go @@ -1,6 +1,8 @@ package runtime import ( + "slices" + "github.com/gardener/gardener/pkg/apis/core/v1beta1" v1 "github.com/kyma-project/infrastructure-manager/api/v1" "github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/shoot" @@ -8,7 +10,6 @@ import ( gardener_shoot "github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot" "github.com/kyma-project/infrastructure-manager/pkg/gardener/shoot/extender/auditlogs" "k8s.io/utils/ptr" - "slices" ) type Verifier struct { diff --git a/internal/controller/metrics/mocks/Metrics.go b/internal/controller/metrics/mocks/Metrics.go index ffd12e7d..737e7d73 100644 --- a/internal/controller/metrics/mocks/Metrics.go +++ b/internal/controller/metrics/mocks/Metrics.go @@ -3,13 +3,11 @@ package mocks import ( - corev1 "k8s.io/api/core/v1" - - mock "github.com/stretchr/testify/mock" - time "time" v1 "github.com/kyma-project/infrastructure-manager/api/v1" + mock "github.com/stretchr/testify/mock" + corev1 "k8s.io/api/core/v1" ) // Metrics is an autogenerated mock type for the Metrics type diff --git a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go index f45df6c9..664109ab 100644 --- a/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go +++ b/internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go @@ -2,8 +2,8 @@ package fsm import ( "context" - "slices" "fmt" + "slices" gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" imv1 "github.com/kyma-project/infrastructure-manager/api/v1" From 71979e44785662558adab000ed245be9c602086c Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 14:59:18 +0100 Subject: [PATCH 07/11] fixup! Improve log field names --- internal/controller/runtime/runtime_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index abe33778..bf898fda 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -70,7 +70,7 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) shootName = "N/D" } - log := r.Log.WithValues("runtimeID", runtimeID, "shootID", shootName) + log := r.Log.WithValues("runtimeID", runtimeID, "shootName", shootName) log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) stateFSM := fsm.NewFsm( From 83990ce1d82cb95ccd959570badd6fcd5547a308 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 15:00:30 +0100 Subject: [PATCH 08/11] Add requestID to logs --- internal/controller/runtime/runtime_controller.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index bf898fda..9d39a760 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -19,6 +19,7 @@ package runtime import ( "context" "fmt" + "sync/atomic" "github.com/go-logr/logr" imv1 "github.com/kyma-project/infrastructure-manager/api/v1" @@ -42,6 +43,7 @@ type RuntimeReconciler struct { Log logr.Logger Cfg fsm.RCCfg EventRecorder record.EventRecorder + RequestID atomic.Uint64 } //+kubebuilder:rbac:groups=infrastructuremanager.kyma-project.io,resources=runtimes,verbs=get;list;watch;create;update;patch;delete @@ -70,11 +72,11 @@ func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) shootName = "N/D" } - log := r.Log.WithValues("runtimeID", runtimeID, "shootName", shootName) + log := r.Log.WithValues("runtimeID", runtimeID, "shootName", shootName, "requestID", r.RequestID.Add(1)) log.Info("Reconciling Runtime", "Name", runtime.Name, "Namespace", runtime.Namespace) stateFSM := fsm.NewFsm( - log.WithName(fmt.Sprintf("reqID %d", requCounter)), + log, r.Cfg, fsm.K8s{ Client: r.Client, From ca3135136a0df7695a801c6c82a3498366fd6196 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Mon, 25 Nov 2024 15:01:39 +0100 Subject: [PATCH 09/11] Correct imports --- internal/controller/runtime/runtime_controller.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index 9d39a760..c4af0468 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -18,7 +18,6 @@ package runtime import ( "context" - "fmt" "sync/atomic" "github.com/go-logr/logr" From 83d2e2876acb8a8c0b3b74b915551c3cafe717b5 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Tue, 26 Nov 2024 09:17:59 +0100 Subject: [PATCH 10/11] Disable debug logger --- cmd/main.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index a1d15634..8d616bee 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -115,9 +115,7 @@ func main() { flag.BoolVar(&shootSpecDumpEnabled, "shoot-spec-dump-enabled", false, "Feature flag to allow persisting specs of created shoots") flag.BoolVar(&auditLogMandatory, "audit-log-mandatory", true, "Feature flag to enable strict mode for audit log configuration") - opts := zap.Options{ - Development: true, - } + opts := zap.Options{} opts.BindFlags(flag.CommandLine) flag.Parse() From 11bf66f912fccdb36a53686a2b5abc1b13f3fab6 Mon Sep 17 00:00:00 2001 From: VOID404 Date: Tue, 26 Nov 2024 10:32:25 +0100 Subject: [PATCH 11/11] Remove unused global --- internal/controller/runtime/runtime_controller.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index c4af0468..20f181fb 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -49,8 +49,6 @@ type RuntimeReconciler struct { //+kubebuilder:rbac:groups=infrastructuremanager.kyma-project.io,resources=runtimes/status,verbs=get;update;patch //+kubebuilder:rbac:groups=infrastructuremanager.kyma-project.io,resources=runtimes/finalizers,verbs=update -var requCounter = 0 // nolint:gochecknoglobals - func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { r.Log.Info(request.String())