diff --git a/controller/controlplane/controller.go b/controller/controlplane/controller.go index f2a95620d..4142a63e9 100644 --- a/controller/controlplane/controller.go +++ b/controller/controlplane/controller.go @@ -115,7 +115,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) err func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.GetLogger(ctx, "controlplane", r.DevelopmentMode) - log.Trace(logger, "reconciling ControlPlane resource", req) + log.Trace(logger, "reconciling ControlPlane resource") cp := new(operatorv1beta1.ControlPlane) if err := r.Client.Get(ctx, req.NamespacedName, cp); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) @@ -125,7 +125,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if !cp.DeletionTimestamp.IsZero() { // wait for termination grace period before cleaning up roles and bindings if cp.DeletionTimestamp.After(metav1.Now().Time) { - log.Debug(logger, "control plane deletion still under grace period", cp) + log.Debug(logger, "control plane deletion still under grace period") return ctrl.Result{ Requeue: true, // Requeue when grace period expires. @@ -136,7 +136,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu }, nil } - log.Trace(logger, "controlplane marked for deletion, removing owned cluster roles, cluster role bindings and validating webhook configurations", cp) + log.Trace(logger, "controlplane marked for deletion, removing owned cluster roles, cluster role bindings and validating webhook configurations") newControlPlane := cp.DeepCopy() @@ -146,7 +146,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if deletions { - log.Debug(logger, "ValidatingWebhookConfiguration deleted", cp) + log.Debug(logger, "ValidatingWebhookConfiguration deleted") return ctrl.Result{}, nil // ValidatingWebhookConfiguration deletion will requeue } @@ -155,7 +155,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err := r.Client.Patch(ctx, newControlPlane, client.MergeFrom(cp)); err != nil { return ctrl.Result{}, err } - log.Debug(logger, "ValidatingWebhookConfigurations finalizer removed", cp) + log.Debug(logger, "ValidatingWebhookConfigurations finalizer removed") return ctrl.Result{}, nil // ControlPlane update will requeue } @@ -165,7 +165,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if deletions { - log.Debug(logger, "clusterRoleBinding deleted", cp) + log.Debug(logger, "clusterRoleBinding deleted") return ctrl.Result{}, nil // ClusterRoleBinding deletion will requeue } @@ -174,7 +174,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err := r.Client.Patch(ctx, newControlPlane, client.MergeFrom(cp)); err != nil { return ctrl.Result{}, err } - log.Debug(logger, "clusterRoleBinding finalizer removed", cp) + log.Debug(logger, "clusterRoleBinding finalizer removed") return ctrl.Result{}, nil // ControlPlane update will requeue } @@ -184,7 +184,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if deletions { - log.Debug(logger, "clusterRole deleted", cp) + log.Debug(logger, "clusterRole deleted") return ctrl.Result{}, nil // ClusterRole deletion will requeue } @@ -193,12 +193,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err := r.Client.Patch(ctx, newControlPlane, client.MergeFrom(cp)); err != nil { return ctrl.Result{}, err } - log.Debug(logger, "clusterRole finalizer removed", cp) + log.Debug(logger, "clusterRole finalizer removed") return ctrl.Result{}, nil // ControlPlane update will requeue } // cleanup completed - log.Debug(logger, "resource cleanup completed, controlplane deleted", cp) + log.Debug(logger, "resource cleanup completed, controlplane deleted") return ctrl.Result{}, nil } @@ -207,10 +207,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu crbFinalizerSet := controllerutil.AddFinalizer(cp, string(ControlPlaneFinalizerCleanupClusterRoleBinding)) vwcFinalizerSet := controllerutil.AddFinalizer(cp, string(ControlPlaneFinalizerCleanupValidatingWebhookConfiguration)) if crFinalizerSet || crbFinalizerSet || vwcFinalizerSet { - log.Trace(logger, "setting finalizers", cp) + log.Trace(logger, "setting finalizers") if err := r.Client.Update(ctx, cp); err != nil { if k8serrors.IsConflict(err) { - log.Debug(logger, "conflict found when updating ControlPlane, retrying", cp) + log.Debug(logger, "conflict found when updating ControlPlane, retrying") return ctrl.Result{Requeue: true, RequeueAfter: controller.RequeueWithoutBackoff}, nil } return ctrl.Result{}, fmt.Errorf("failed updating ControlPlane's finalizers : %w", err) @@ -222,50 +222,50 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu k8sutils.InitReady(cp) - log.Trace(logger, "validating ControlPlane resource conditions", cp) + log.Trace(logger, "validating ControlPlane resource conditions") if r.ensureIsMarkedScheduled(cp) { res, err := r.patchStatus(ctx, logger, cp) if err != nil { - log.Debug(logger, "unable to update ControlPlane resource", cp, "error", err) + log.Debug(logger, "unable to update ControlPlane resource", "error", err) return res, err } if !res.IsZero() { - log.Debug(logger, "unable to update ControlPlane resource", cp) + log.Debug(logger, "unable to update ControlPlane resource") return res, nil } - log.Debug(logger, "ControlPlane resource now marked as scheduled", cp) + log.Debug(logger, "ControlPlane resource now marked as scheduled") return ctrl.Result{}, nil // no need to requeue, status update will requeue } - log.Trace(logger, "retrieving connected dataplane", cp) + log.Trace(logger, "retrieving connected dataplane") dataplane, err := gatewayutils.GetDataPlaneForControlPlane(ctx, r.Client, cp) var dataplaneIngressServiceName, dataplaneAdminServiceName string if err != nil { if !errors.Is(err, operatorerrors.ErrDataPlaneNotSet) { return ctrl.Result{}, err } - log.Debug(logger, "no existing dataplane for controlplane", cp, "error", err) + log.Debug(logger, "no existing dataplane for controlplane", "error", err) } else { dataplaneIngressServiceName, err = gatewayutils.GetDataPlaneServiceName(ctx, r.Client, dataplane, consts.DataPlaneIngressServiceLabelValue) if err != nil { - log.Debug(logger, "no existing dataplane ingress service for controlplane", cp, "error", err) + log.Debug(logger, "no existing dataplane ingress service for controlplane", "error", err) return ctrl.Result{}, err } dataplaneAdminServiceName, err = gatewayutils.GetDataPlaneServiceName(ctx, r.Client, dataplane, consts.DataPlaneAdminServiceLabelValue) if err != nil { - log.Debug(logger, "no existing dataplane admin service for controlplane", cp, "error", err) + log.Debug(logger, "no existing dataplane admin service for controlplane", "error", err) return ctrl.Result{}, err } } - log.Trace(logger, "validating ControlPlane configuration", cp) + log.Trace(logger, "validating ControlPlane configuration") if err := validateControlPlane(cp, r.DevelopmentMode); err != nil { return ctrl.Result{}, err } - log.Trace(logger, "configuring ControlPlane resource", cp) + log.Trace(logger, "configuring ControlPlane resource") defaultArgs := controlplane.DefaultsArgs{ Namespace: cp.Namespace, ControlPlaneName: cp.Name, @@ -283,11 +283,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu &cp.Spec.ControlPlaneOptions, defaultArgs) if changed { - log.Debug(logger, "updating ControlPlane resource after defaults are set since resource has changed", cp) + log.Debug(logger, "updating ControlPlane resource after defaults are set since resource has changed") err := r.Client.Update(ctx, cp) if err != nil { if k8serrors.IsConflict(err) { - log.Debug(logger, "conflict found when updating ControlPlane resource, retrying", cp) + log.Debug(logger, "conflict found when updating ControlPlane resource, retrying") return ctrl.Result{Requeue: true, RequeueAfter: controller.RequeueWithoutBackoff}, nil } return ctrl.Result{}, fmt.Errorf("failed updating ControlPlane: %w", err) @@ -295,7 +295,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, nil // no need to requeue, the update will trigger. } - log.Trace(logger, "validating that the ControlPlane's DataPlane configuration is up to date", cp) + log.Trace(logger, "validating that the ControlPlane's DataPlane configuration is up to date") if err = r.ensureDataPlaneConfiguration(ctx, cp, dataplaneIngressServiceName); err != nil { if k8serrors.IsConflict(err) { log.Debug( @@ -308,51 +308,51 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } - log.Trace(logger, "validating ControlPlane's DataPlane status", cp) + log.Trace(logger, "validating ControlPlane's DataPlane status") dataplaneIsSet := r.ensureDataPlaneStatus(cp, dataplane) if dataplaneIsSet { - log.Trace(logger, "DataPlane is set, deployment for ControlPlane will be provisioned", cp) + log.Trace(logger, "DataPlane is set, deployment for ControlPlane will be provisioned") } else { - log.Debug(logger, "DataPlane not set, deployment for ControlPlane will remain dormant", cp) + log.Debug(logger, "DataPlane not set, deployment for ControlPlane will remain dormant") } - log.Trace(logger, "ensuring ServiceAccount for ControlPlane deployment exists", cp) + log.Trace(logger, "ensuring ServiceAccount for ControlPlane deployment exists") createdOrUpdated, controlplaneServiceAccount, err := r.ensureServiceAccount(ctx, cp) if err != nil { return ctrl.Result{}, err } if createdOrUpdated { - log.Debug(logger, "serviceAccount updated", cp) + log.Debug(logger, "serviceAccount updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "ensuring ClusterRoles for ControlPlane deployment exist", cp) + log.Trace(logger, "ensuring ClusterRoles for ControlPlane deployment exist") createdOrUpdated, controlplaneClusterRole, err := r.ensureClusterRole(ctx, cp) if err != nil { return ctrl.Result{}, err } if createdOrUpdated { - log.Debug(logger, "clusterRole updated", cp) + log.Debug(logger, "clusterRole updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "ensuring that ClusterRoleBindings for ControlPlane Deployment exist", cp) + log.Trace(logger, "ensuring that ClusterRoleBindings for ControlPlane Deployment exist") createdOrUpdated, _, err = r.ensureClusterRoleBinding(ctx, cp, controlplaneServiceAccount.Name, controlplaneClusterRole.Name) if err != nil { return ctrl.Result{}, err } if createdOrUpdated { - log.Debug(logger, "clusterRoleBinding updated", cp) + log.Debug(logger, "clusterRoleBinding updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "creating mTLS certificate", cp) + log.Trace(logger, "creating mTLS certificate") res, adminCertificate, err := r.ensureAdminMTLSCertificateSecret(ctx, cp) if err != nil { return ctrl.Result{}, err } if res != op.Noop { - log.Debug(logger, "mTLS certificate created/updated", cp) + log.Debug(logger, "mTLS certificate created/updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } @@ -370,31 +370,31 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } deploymentParams.AdmissionWebhookCertSecretName = admissionWebhookCertificateSecretName - log.Trace(logger, "looking for existing Deployments for ControlPlane resource", cp) + log.Trace(logger, "looking for existing Deployments for ControlPlane resource") res, controlplaneDeployment, err := r.ensureDeployment(ctx, logger, deploymentParams) if err != nil { return ctrl.Result{}, err } if res != op.Noop { if !dataplaneIsSet { - log.Debug(logger, "DataPlane not set, deployment for ControlPlane has been scaled down to 0 replicas", cp) + log.Debug(logger, "DataPlane not set, deployment for ControlPlane has been scaled down to 0 replicas") res, err := r.patchStatus(ctx, logger, cp) if err != nil { - log.Debug(logger, "unable to reconcile ControlPlane status", cp, "error", err) + log.Debug(logger, "unable to reconcile ControlPlane status", "error", err) return ctrl.Result{}, err } if !res.IsZero() { - log.Debug(logger, "unable to update ControlPlane resource", cp) + log.Debug(logger, "unable to update ControlPlane resource") return res, nil } return ctrl.Result{}, nil } return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "checking readiness of ControlPlane deployments", cp) + log.Trace(logger, "checking readiness of ControlPlane deployments") if controlplaneDeployment.Status.Replicas == 0 || controlplaneDeployment.Status.AvailableReplicas < controlplaneDeployment.Status.Replicas { - log.Trace(logger, "deployment for ControlPlane not ready yet", controlplaneDeployment) + log.Trace(logger, "deployment for ControlPlane not ready yet", "deployment", controlplaneDeployment) // Set Ready to false for controlplane as the underlying deployment is not ready. k8sutils.SetCondition( k8sutils.NewCondition(consts.ReadyType, metav1.ConditionFalse, consts.WaitingToBecomeReadyReason, consts.WaitingToBecomeReadyMessage), @@ -403,11 +403,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu res, err := r.patchStatus(ctx, logger, cp) if err != nil { - log.Debug(logger, "unable to patch ControlPlane status", cp, "error", err) + log.Debug(logger, "unable to patch ControlPlane status", "error", err) return ctrl.Result{}, err } if !res.IsZero() { - log.Debug(logger, "unable to patch ControlPlane status", cp) + log.Debug(logger, "unable to patch ControlPlane status") return res, nil } return ctrl.Result{}, nil @@ -418,15 +418,15 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu result, err := r.patchStatus(ctx, logger, cp) if err != nil { - log.Debug(logger, "unable to patch ControlPlane status", cp, "error", err) + log.Debug(logger, "unable to patch ControlPlane status", "error", err) return ctrl.Result{}, err } if !result.IsZero() { - log.Debug(logger, "unable to patch ControlPlane status", cp) + log.Debug(logger, "unable to patch ControlPlane status") return result, nil } - log.Debug(logger, "reconciliation complete for ControlPlane resource", cp) + log.Debug(logger, "reconciliation complete for ControlPlane resource") return ctrl.Result{}, nil } @@ -450,10 +450,10 @@ func (r *Reconciler) patchStatus(ctx context.Context, logger logr.Logger, update } if k8sutils.NeedsUpdate(current, updated) { - log.Debug(logger, "patching ControlPlane status", updated, "status", updated.Status) + log.Debug(logger, "patching ControlPlane status", "status", updated.Status) if err := r.Client.Status().Patch(ctx, updated, client.MergeFrom(current)); err != nil { if k8serrors.IsConflict(err) { - log.Debug(logger, "conflict found when updating ControlPlane, retrying", current) + log.Debug(logger, "conflict found when updating ControlPlane, retrying") return ctrl.Result{Requeue: true, RequeueAfter: controller.RequeueWithoutBackoff}, nil } return ctrl.Result{}, fmt.Errorf("failed updating ControlPlane's status : %w", err) @@ -469,49 +469,49 @@ func (r *Reconciler) ensureWebhookResources( ) (string, op.Result, error) { webhookEnabled := isAdmissionWebhookEnabled(ctx, r.Client, logger, cp) if !webhookEnabled { - log.Debug(logger, "admission webhook disabled, ensuring admission webhook resources are not present", cp) + log.Debug(logger, "admission webhook disabled, ensuring admission webhook resources are not present") } else { - log.Debug(logger, "admission webhook enabled, enforcing admission webhook resources", cp) + log.Debug(logger, "admission webhook enabled, enforcing admission webhook resources") } - log.Trace(logger, "ensuring admission webhook service", cp) + log.Trace(logger, "ensuring admission webhook service") res, admissionWebhookService, err := r.ensureAdmissionWebhookService(ctx, logger, r.Client, cp) if err != nil { return "", res, fmt.Errorf("failed to ensure admission webhook service: %w", err) } if res != op.Noop { if !webhookEnabled { - log.Debug(logger, "admission webhook service has been removed", cp) + log.Debug(logger, "admission webhook service has been removed") } else { - log.Debug(logger, "admission webhook service has been created/updated", cp) + log.Debug(logger, "admission webhook service has been created/updated") } return "", res, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "ensuring admission webhook certificate", cp) + log.Trace(logger, "ensuring admission webhook certificate") res, admissionWebhookCertificateSecret, err := r.ensureAdmissionWebhookCertificateSecret(ctx, logger, cp, admissionWebhookService) if err != nil { return "", res, err } if res != op.Noop { if !webhookEnabled { - log.Debug(logger, "admission webhook service certificate has been removed", cp) + log.Debug(logger, "admission webhook service certificate has been removed") } else { - log.Debug(logger, "admission webhook service certificate has been created/updated", cp) + log.Debug(logger, "admission webhook service certificate has been created/updated") } return "", res, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "ensuring admission webhook configuration", cp) + log.Trace(logger, "ensuring admission webhook configuration") res, err = r.ensureValidatingWebhookConfiguration(ctx, cp, admissionWebhookCertificateSecret, admissionWebhookService) if err != nil { return "", res, err } if res != op.Noop { if !webhookEnabled { - log.Debug(logger, "ValidatingWebhookConfiguration has been removed", cp) + log.Debug(logger, "ValidatingWebhookConfiguration has been removed") } else { - log.Debug(logger, "ValidatingWebhookConfiguration has been created/updated", cp) + log.Debug(logger, "ValidatingWebhookConfiguration has been created/updated") } } if webhookEnabled { @@ -531,7 +531,7 @@ func isAdmissionWebhookEnabled(ctx context.Context, cl client.Client, logger log } admissionWebhookListen, ok, err := k8sutils.GetEnvValueFromContainer(ctx, container, cp.Namespace, "CONTROLLER_ADMISSION_WEBHOOK_LISTEN", cl) if err != nil { - log.Debug(logger, "unable to get CONTROLLER_ADMISSION_WEBHOOK_LISTEN env var", cp, "error", err) + log.Debug(logger, "unable to get CONTROLLER_ADMISSION_WEBHOOK_LISTEN env var", "error", err) return false } if !ok { diff --git a/controller/controlplane/controller_reconciler_utils.go b/controller/controlplane/controller_reconciler_utils.go index da98f32c9..f01299e04 100644 --- a/controller/controlplane/controller_reconciler_utils.go +++ b/controller/controlplane/controller_reconciler_utils.go @@ -240,7 +240,7 @@ func (r *Reconciler) ensureDeployment( return op.Noop, nil, fmt.Errorf("failed creating ControlPlane Deployment %s: %w", generatedDeployment.Name, err) } - log.Debug(logger, "deployment for ControlPlane created", params.ControlPlane, "deployment", generatedDeployment.Name) + log.Debug(logger, "deployment for ControlPlane created", "deployment", generatedDeployment.Name) return op.Created, generatedDeployment, nil } @@ -431,7 +431,6 @@ func (r *Reconciler) ensureClusterRoleBinding( // Delete and re-create ClusterRoleBinding if name of ClusterRole changed because RoleRef is immutable. if !k8sresources.CompareClusterRoleName(existing, clusterRoleName) { log.Debug(logger, "ClusterRole name changed, delete and re-create a ClusterRoleBinding", - existing, "old_cluster_role", existing.RoleRef.Name, "new_cluster_role", clusterRoleName, ) @@ -865,7 +864,7 @@ func (r *Reconciler) ensureValidatingWebhookConfiguration( } if updated { - log.Debug(logger, "patching existing ValidatingWebhookConfiguration", webhookConfiguration) + log.Debug(logger, "patching existing ValidatingWebhookConfiguration") return op.Updated, r.Client.Patch(ctx, &webhookConfiguration, client.MergeFrom(old)) } diff --git a/controller/dataplane/bluegreen_controller.go b/controller/dataplane/bluegreen_controller.go index b4e15bfdc..8c654c995 100644 --- a/controller/dataplane/bluegreen_controller.go +++ b/controller/dataplane/bluegreen_controller.go @@ -96,7 +96,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( if err := r.prunePreviewSubresources(ctx, &dataplane); err != nil { return ctrl.Result{}, fmt.Errorf("failed pruning preview DataPlane subresources: %w", err) } - log.Trace(logger, "no Rollout with BlueGreen strategy specified, delegating to DataPlaneReconciler", req) + log.Trace(logger, "no Rollout with BlueGreen strategy specified, delegating to DataPlaneReconciler") return r.DataPlaneController.Reconcile(ctx, req) } @@ -150,7 +150,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, nil } - log.Trace(logger, "ensuring mTLS certificate", dataplane) + log.Trace(logger, "ensuring mTLS certificate") res, certSecret, err := ensureDataPlaneCertificate(ctx, r.Client, &dataplane, types.NamespacedName{ Namespace: r.ClusterCASecretNamespace, @@ -165,7 +165,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, err } if res != op.Noop { - log.Debug(logger, "mTLS certificate created/updated", dataplane) + log.Debug(logger, "mTLS certificate created/updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } @@ -200,7 +200,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( if deployment.Status.Replicas == 0 || deployment.Status.AvailableReplicas != deployment.Status.Replicas || deployment.Status.ReadyReplicas != deployment.Status.Replicas { - log.Trace(logger, "preview deployment for DataPlane not ready yet", dataplane) + log.Trace(logger, "preview deployment for DataPlane not ready yet") err := r.ensureRolledOutCondition(ctx, logger, &dataplane, metav1.ConditionFalse, consts.DataPlaneConditionReasonRolloutProgressing, consts.DataPlaneConditionMessageRolledOutPreviewDeploymentNotYetReady) return ctrl.Result{}, err } @@ -211,7 +211,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( if proceedWithPromotion, err := canProceedWithPromotion(dataplane); err != nil { return ctrl.Result{}, fmt.Errorf("failed checking if DataPlane %s/%s can be promoted: %w", dataplane.Namespace, dataplane.Name, err) } else if !proceedWithPromotion { - log.Debug(logger, "DataPlane preview resources cannot be promoted yet or is awaiting promotion trigger", dataplane, + log.Debug(logger, "DataPlane preview resources cannot be promoted yet or is awaiting promotion trigger", "promotion_strategy", dataplane.Spec.Deployment.Rollout.Strategy.BlueGreen.Promotion.Strategy) err := r.ensureRolledOutCondition(ctx, logger, &dataplane, metav1.ConditionFalse, consts.DataPlaneConditionReasonRolloutAwaitingPromotion, "") @@ -232,7 +232,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( cErr := r.ensureRolledOutCondition(ctx, logger, &dataplane, metav1.ConditionFalse, consts.DataPlaneConditionReasonRolloutPromotionFailed, "failed to update DataPlane's selector") return ctrl.Result{}, fmt.Errorf("failed to update DataPlane %s/%s: %w", dataplane.Namespace, dataplane.Name, errors.Join(cErr, err)) } else if updated { - log.Debug(logger, "preview deployment selector assigned to a live selector, promotion in progress", dataplane) + log.Debug(logger, "preview deployment selector assigned to a live selector, promotion in progress") return ctrl.Result{}, nil } @@ -252,7 +252,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( ); err != nil { return ctrl.Result{}, fmt.Errorf("failed waiting for live %q service to have the expected selector: %w", serviceType, err) } else if !ok { - log.Debug(logger, fmt.Sprintf("%q live service do not have the expected selector yet, delegating to DP controller", serviceType), dataplane) + log.Debug(logger, fmt.Sprintf("%q live service does not have the expected selector yet, delegating to DP controller", serviceType)) return r.DataPlaneController.Reconcile(ctx, req) } } @@ -266,7 +266,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( cErr := r.ensureRolledOutCondition(ctx, logger, &dataplane, metav1.ConditionFalse, consts.DataPlaneConditionReasonRolloutPromotionFailed, "failed to label DataPlane's preview Deployment for promotion") return ctrl.Result{}, fmt.Errorf("failed to ensure preview deployment becomes live %s/%s: %w", dataplane.Namespace, dataplane.Name, errors.Join(cErr, err)) } else if updated { - log.Trace(logger, "preview deployment labeled as live", dataplane) + log.Trace(logger, "preview deployment labeled as live") } // We can clear the selector in RolloutStatus which will cause next @@ -293,7 +293,7 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, fmt.Errorf("failed to reduce live deployments: %w", err) } - log.Debug(logger, "BlueGreen reconciliation complete for DataPlane resource", dataplane) + log.Debug(logger, "BlueGreen reconciliation complete for DataPlane resource") return ctrl.Result{}, nil } @@ -341,7 +341,7 @@ func shouldDelegateToDataPlaneController( cReady.ObservedGeneration == cRolledOut.ObservedGeneration && cReady.ObservedGeneration == dataplane.Generation { if cRolledOut.Reason == string(consts.DataPlaneConditionReasonRolloutWaitingForChange) { - log.Debug(logger, "DataPlane is up to date, waiting for changes, delegating to DataPlaneReconciler", dataplane) + log.Debug(logger, "DataPlane is up to date, waiting for changes, delegating to DataPlaneReconciler") return true } } @@ -352,7 +352,7 @@ func shouldDelegateToDataPlaneController( // the DataPlane with the current spec which would cause the rollout to progress // which is what the promotion does. if cReady.Status == metav1.ConditionFalse && cReady.ObservedGeneration == dataplane.Generation { - log.Debug(logger, "DataPlane is not ready yet to proceed with BlueGreen rollout, delegating to DataPlaneReconciler", dataplane) + log.Debug(logger, "DataPlane is not ready yet to proceed with BlueGreen rollout, delegating to DataPlaneReconciler") return true } @@ -385,7 +385,7 @@ func (r *BlueGreenReconciler) prunePreviewSubresources( return err } if len(deployments) > 0 { - log.Debug(logger, "removing preview Deployments", dataplane) + log.Debug(logger, "removing preview Deployments") if err := removeObjectSliceWithDataPlaneOwnedFinalizer(ctx, r.Client, deployments); err != nil { return err } @@ -419,13 +419,13 @@ func (r *BlueGreenReconciler) prunePreviewSubresources( return err } - log.Debug(logger, "removing preview Secrets", dataplane) + log.Debug(logger, "removing preview Secrets") if err := removeObjectSliceWithDataPlaneOwnedFinalizer(ctx, r.Client, secrets); err != nil { return err } } if len(services) > 0 { - log.Debug(logger, "removing preview Services", dataplane) + log.Debug(logger, "removing preview Services") if err := removeObjectSliceWithDataPlaneOwnedFinalizer(ctx, r.Client, services); err != nil { return err } @@ -510,11 +510,11 @@ func (r *BlueGreenReconciler) ensureDeploymentForDataPlane( switch res { case op.Created, op.Updated: - log.Debug(logger, "deployment modified", dataplane, "reason", res) + log.Debug(logger, "deployment modified", "reason") // requeue will be triggered by the creation or update of the owned object return deployment, res, nil default: - log.Debug(logger, "no need for deployment update", dataplane) + log.Debug(logger, "no need for deployment update") return deployment, op.Noop, nil } } @@ -567,8 +567,9 @@ func (r *BlueGreenReconciler) reduceLiveDeployments( }) // Delete all but the last deployment. for _, deployment := range deployments[:len(deployments)-1] { - log.Debug(logger, "reducing live deployment", dataPlane, - "deployment", fmt.Sprintf("%s/%s", deployment.Namespace, deployment.Name)) + log.Debug(logger, "reducing live deployment", + "deployment", client.ObjectKeyFromObject(&deployment), + ) if err := dataplane.OwnedObjectPreDeleteHook(ctx, r.Client, &deployment); err != nil { return fmt.Errorf("failed executing pre delete hook: %w", err) @@ -700,7 +701,7 @@ func (r *BlueGreenReconciler) ensureDataPlaneAdminAPIInRolloutStatus( // It returns a bool flag indicating that the status has been patched and an error. func (r *BlueGreenReconciler) patchRolloutStatus(ctx context.Context, logger logr.Logger, old, updated *operatorv1beta1.DataPlane) (bool, error) { if rolloutStatusChanged(old, updated) { - log.Debug(logger, "patching DataPlane status", updated, "status", updated.Status) + log.Debug(logger, "patching DataPlane status", "status", updated.Status) return true, r.Client.Status().Patch(ctx, updated, client.MergeFrom(old)) } @@ -752,9 +753,9 @@ func (r *BlueGreenReconciler) ensurePreviewAdminAPIService( switch res { case op.Created, op.Updated: - log.Debug(logger, "preview admin service modified", dataplane, "service", svc.Name, "reason", res) + log.Debug(logger, "preview admin service modified", "service", svc.Name, "reason", res) case op.Noop: - log.Trace(logger, "no need for preview Admin API service update", dataplane) + log.Trace(logger, "no need for preview Admin API service update") case op.Deleted: } return res, svc, nil // dataplane admin service creation/update will trigger reconciliation @@ -785,9 +786,9 @@ func (r *BlueGreenReconciler) ensurePreviewIngressService( switch res { case op.Created, op.Updated: - log.Debug(logger, "preview ingress service modified", dataplane, "service", svc.Name, "reason", res) + log.Debug(logger, "preview ingress service modified", "service", svc.Name, "reason", res) case op.Noop: - log.Trace(logger, "no need for preview ingress service update", dataplane) + log.Trace(logger, "no need for preview ingress service update") case op.Deleted: } @@ -912,8 +913,7 @@ func (r *BlueGreenReconciler) ensurePreviewDeploymentLabeledLive( // It shouldn't happen in practice, but we'll log it just in case. if len(deployments) > 1 { ds := lo.Map(deployments, func(d appsv1.Deployment, _ int) string { return fmt.Sprintf("%s/%s", d.Namespace, d.Name) }) - log.Info(logger, "found multiple preview deployments, expected one, will label live only the first one", - dataplane, "deployments", ds) + log.Info(logger, "found multiple preview deployments, expected one, will label live only the first one", "deployments", ds) } deployment := deployments[0] diff --git a/controller/dataplane/controller.go b/controller/dataplane/controller.go index df9aa63b9..a62916fab 100644 --- a/controller/dataplane/controller.go +++ b/controller/dataplane/controller.go @@ -63,7 +63,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu ctx = r.ContextInjector.InjectKeyValues(ctx) logger := log.GetLogger(ctx, "dataplane", r.DevelopmentMode) - log.Trace(logger, "reconciling DataPlane resource", req) + log.Trace(logger, "reconciling DataPlane resource") dpNn := req.NamespacedName dataplane := new(operatorv1beta1.DataPlane) if err := r.Client.Get(ctx, dpNn, dataplane); err != nil { @@ -82,20 +82,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, fmt.Errorf("failed updating DataPlane with selector in Status: %w", err) } - log.Trace(logger, "validating DataPlane configuration", dataplane) + log.Trace(logger, "validating DataPlane configuration") err := r.Validator.Validate(dataplane) if err != nil { - log.Info(logger, "failed to validate dataplane: "+err.Error(), dataplane) + log.Info(logger, "failed to validate dataplane: "+err.Error()) r.eventRecorder.Event(dataplane, "Warning", "ValidationFailed", err.Error()) markErr := ensureDataPlaneIsMarkedNotReady(ctx, logger, r.Client, dataplane, DataPlaneConditionValidationFailed, err.Error()) return ctrl.Result{}, markErr } - log.Trace(logger, "applying extensions", dataplane) + log.Trace(logger, "applying extensions") patched, requeue, err := applyExtensions(ctx, r.Client, logger, dataplane, r.KonnectEnabled) if err != nil { if !requeue { - log.Debug(logger, "failed to apply extensions", dataplane, "error:", err) + log.Debug(logger, "failed to apply extensions", "err", err) return ctrl.Result{}, nil } return ctrl.Result{}, err @@ -104,7 +104,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, nil } - log.Trace(logger, "exposing DataPlane deployment admin API via headless service", dataplane) + log.Trace(logger, "exposing DataPlane deployment admin API via headless service") res, dataplaneAdminService, err := ensureAdminServiceForDataPlane(ctx, r.Client, dataplane, client.MatchingLabels{ consts.DataPlaneServiceStateLabel: consts.DataPlaneStateLabelValueLive, @@ -116,13 +116,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } switch res { case op.Created, op.Updated: - log.Debug(logger, "DataPlane admin service modified", dataplane, "service", dataplaneAdminService.Name, "reason", res) + log.Debug(logger, "DataPlane admin service modified", "service", dataplaneAdminService.Name, "reason", res) return ctrl.Result{}, nil // dataplane admin service creation/update will trigger reconciliation case op.Noop: case op.Deleted: // This should not happen. } - log.Trace(logger, "exposing DataPlane deployment via service", dataplane) + log.Trace(logger, "exposing DataPlane deployment via service") additionalServiceLabels := map[string]string{ consts.DataPlaneServiceStateLabel: consts.DataPlaneStateLabelValueLive, } @@ -139,7 +139,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if serviceRes == op.Created || serviceRes == op.Updated { - log.Debug(logger, "DataPlane ingress service created/updated", dataplane, "service", dataplaneIngressService.Name) + log.Debug(logger, "DataPlane ingress service created/updated", "service", dataplaneIngressService.Name) return ctrl.Result{}, nil } @@ -148,11 +148,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if dataplaneServiceChanged { - log.Debug(logger, "ingress service updated in the dataplane status", dataplane) + log.Debug(logger, "ingress service updated in the dataplane status") return ctrl.Result{}, nil // dataplane status update will trigger reconciliation } - log.Trace(logger, "ensuring mTLS certificate", dataplane) + log.Trace(logger, "ensuring mTLS certificate") res, certSecret, err := ensureDataPlaneCertificate(ctx, r.Client, dataplane, types.NamespacedName{ Namespace: r.ClusterCASecretNamespace, @@ -167,20 +167,20 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if res != op.Noop { - log.Debug(logger, "mTLS certificate created/updated", dataplane) + log.Debug(logger, "mTLS certificate created/updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "checking readiness of DataPlane service", dataplaneIngressService) + log.Trace(logger, "checking readiness of DataPlane service", "service", dataplaneIngressService.Name) if dataplaneIngressService.Spec.ClusterIP == "" { return ctrl.Result{}, nil // no need to requeue, the update will trigger. } - log.Trace(logger, "ensuring DataPlane has service addresses in status", dataplaneIngressService) + log.Trace(logger, "ensuring DataPlane has service addresses in status", "service", dataplaneIngressService.Name) if updated, err := r.ensureDataPlaneAddressesStatus(ctx, logger, dataplane, dataplaneIngressService); err != nil { return ctrl.Result{}, err } else if updated { - log.Debug(logger, "dataplane status.Addresses updated", dataplane) + log.Debug(logger, "dataplane status.Addresses updated") return ctrl.Result{}, nil // no need to requeue, the update will trigger. } @@ -191,7 +191,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu labelSelectorFromDataPlaneStatusSelectorDeploymentOpt(dataplane), } - log.Trace(logger, "ensuring generation of deployment configuration for KongPluginInstallations configured for DataPlane", dataplane) + log.Trace(logger, "ensuring generation of deployment configuration for KongPluginInstallations configured for DataPlane") kpisForDeployment, requeue, err := ensureMappedConfigMapToKongPluginInstallationForDataPlane(ctx, logger, r.Client, dataplane) if err != nil { return ctrl.Result{}, fmt.Errorf("cannot ensure KongPluginInstallation for DataPlane: %w", err) @@ -230,7 +230,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, fmt.Errorf("could not ensure PodDisruptionBudget for DataPlane %s: %w", dpNn, err) } if res != op.Noop { - log.Debug(logger, "PodDisruptionBudget created/updated", dataplane) + log.Debug(logger, "PodDisruptionBudget created/updated") return ctrl.Result{}, nil } @@ -240,7 +240,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return res, nil } - log.Debug(logger, "reconciliation complete for DataPlane resource", dataplane) + log.Debug(logger, "reconciliation complete for DataPlane resource") return ctrl.Result{}, nil } diff --git a/controller/dataplane/controller_reconciler_utils.go b/controller/dataplane/controller_reconciler_utils.go index 8f5aafa80..2b4372c41 100644 --- a/controller/dataplane/controller_reconciler_utils.go +++ b/controller/dataplane/controller_reconciler_utils.go @@ -159,12 +159,12 @@ func populateDedicatedConfigMapForKongPluginInstallation( Namespace: kpi.Namespace, Name: kpi.Status.UnderlyingConfigMapName, } - log.Trace(logger, fmt.Sprintf("Fetch underlying ConfigMap %s for KongPluginInstallation", backingCMNN), kpi) + log.Trace(logger, fmt.Sprintf("Fetch underlying ConfigMap %s for KongPluginInstallation", backingCMNN)) if err := c.Get(ctx, backingCMNN, &underlyingCM); err != nil { return customPlugin{}, false, fmt.Errorf("could not fetch underlying ConfigMap to clone %s: %w", backingCMNN, err) } - log.Trace(logger, "Find ConfigMap mapped to KongPluginInstallation", kpi) + log.Trace(logger, "Find ConfigMap mapped to KongPluginInstallation") mappedConfigMapForKPI := lo.Filter(cms, func(cm corev1.ConfigMap, _ int) bool { kpiNN := cm.Annotations[consts.AnnotationMappedToKongPluginInstallation] return kpiNN == client.ObjectKeyFromObject(&kpi).String() @@ -172,7 +172,7 @@ func populateDedicatedConfigMapForKongPluginInstallation( var cm corev1.ConfigMap switch len(mappedConfigMapForKPI) { case 0: - log.Trace(logger, "Create new ConfigMap for KongPluginInstallation", kpi) + log.Trace(logger, "Create new ConfigMap for KongPluginInstallation") cm.GenerateName = dataplane.Name + "-" cm.Namespace = dataplane.Namespace k8sutils.SetOwnerForObject(&cm, dataplane) @@ -183,12 +183,12 @@ func populateDedicatedConfigMapForKongPluginInstallation( return customPlugin{}, false, fmt.Errorf("could not create new ConfigMap for KongPluginInstallation: %w", err) } case 1: - log.Trace(logger, fmt.Sprintf("Check if update existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm)), kpi) + log.Trace(logger, fmt.Sprintf("Check if update existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm))) cm = mappedConfigMapForKPI[0] if maps.Equal(cm.Data, underlyingCM.Data) { - log.Trace(logger, fmt.Sprintf("Nothing to update in existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm)), kpi) + log.Trace(logger, fmt.Sprintf("Nothing to update in existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm))) } else { - log.Trace(logger, fmt.Sprintf("Update existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm)), kpi) + log.Trace(logger, fmt.Sprintf("Update existing ConfigMap %s for KongPluginInstallation", client.ObjectKeyFromObject(&cm))) cm.Data = underlyingCM.Data if err := c.Update(ctx, &cm); err != nil { if k8serrors.IsConflict(err) { @@ -382,7 +382,7 @@ func patchDataPlaneStatus(ctx context.Context, cl client.Client, logger logr.Log current.Status.Service != updated.Status.Service || current.Status.Selector != updated.Status.Selector { - log.Debug(logger, "patching DataPlane status", updated, "status", updated.Status) + log.Debug(logger, "patching DataPlane status", "status", updated.Status) return true, cl.Status().Patch(ctx, updated, client.MergeFrom(current)) } diff --git a/controller/dataplane/controller_utils.go b/controller/dataplane/controller_utils.go index 0f2c033c3..d7539a092 100644 --- a/controller/dataplane/controller_utils.go +++ b/controller/dataplane/controller_utils.go @@ -140,7 +140,7 @@ func ensureDataPlaneReadyStatus( switch len(deployments) { case 0: - log.Debug(logger, "Deployment for DataPlane not present yet", dataplane) + log.Debug(logger, "Deployment for DataPlane not present yet") // Set Ready to false for dataplane as the underlying deployment is not ready. k8sutils.SetCondition( @@ -168,13 +168,13 @@ func ensureDataPlaneReadyStatus( case 1: // Expect just 1. default: // More than 1. - log.Info(logger, "expected only 1 Deployment for DataPlane", dataplane) + log.Info(logger, "expected only 1 Deployment for DataPlane") return ctrl.Result{Requeue: true}, nil } deployment := deployments[0] if _, ready := isDeploymentReady(deployment.Status); !ready { - log.Debug(logger, "Deployment for DataPlane not ready yet", dataplane) + log.Debug(logger, "Deployment for DataPlane not ready yet") // Set Ready to false for dataplane as the underlying deployment is not ready. k8sutils.SetCondition( @@ -201,7 +201,7 @@ func ensureDataPlaneReadyStatus( switch len(services) { case 0: - log.Debug(logger, "Ingress Service for DataPlane not present", dataplane) + log.Debug(logger, "Ingress Service for DataPlane not present") // Set Ready to false for dataplane as the Service is not ready yet. k8sutils.SetCondition( @@ -224,13 +224,13 @@ func ensureDataPlaneReadyStatus( case 1: // Expect just 1. default: // More than 1. - log.Info(logger, "expected only 1 ingress Service for DataPlane", dataplane) + log.Info(logger, "expected only 1 ingress Service for DataPlane") return ctrl.Result{Requeue: true}, nil } ingressService := services[0] if !dataPlaneIngressServiceIsReady(&ingressService) { - log.Debug(logger, "Ingress Service for DataPlane not ready yet", dataplane) + log.Debug(logger, "Ingress Service for DataPlane not ready yet") // Set Ready to false for dataplane as the Service is not ready yet. k8sutils.SetCondition( diff --git a/controller/dataplane/konnectextension_controller.go b/controller/dataplane/konnectextension_controller.go index 4fc72f78c..fbbe30650 100644 --- a/controller/dataplane/konnectextension_controller.go +++ b/controller/dataplane/konnectextension_controller.go @@ -112,7 +112,7 @@ func (r *KonnectExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, err } - log.Info(logger, "KonnectExtension finalizer updated", konnectExtension) + log.Info(logger, "KonnectExtension finalizer updated") } return ctrl.Result{}, nil diff --git a/controller/dataplane/owned_deployment.go b/controller/dataplane/owned_deployment.go index 969131733..28103512a 100644 --- a/controller/dataplane/owned_deployment.go +++ b/controller/dataplane/owned_deployment.go @@ -342,7 +342,7 @@ func reconcileDataPlaneDeployment( } if updated { diff := cmp.Diff(original.Spec.Template, desired.Spec.Template, opts...) - log.Trace(logger, "DataPlane Deployment diff detected", dataplane, "diff", diff) + log.Trace(logger, "DataPlane Deployment diff detected", "diff", diff) } return patch.ApplyPatchIfNotEmpty(ctx, cl, logger, existing, original, updated) @@ -352,6 +352,6 @@ func reconcileDataPlaneDeployment( return op.Noop, nil, fmt.Errorf("failed creating Deployment for DataPlane %s: %w", dataplane.Name, err) } - log.Debug(logger, "deployment for DataPlane created", dataplane, "deployment", desired.Name) + log.Debug(logger, "deployment for DataPlane created", "deployment", desired.Name) return op.Created, desired, nil } diff --git a/controller/dataplane/owned_finalizer_controller.go b/controller/dataplane/owned_finalizer_controller.go index c7b900cf7..04d8579c2 100644 --- a/controller/dataplane/owned_finalizer_controller.go +++ b/controller/dataplane/owned_finalizer_controller.go @@ -172,7 +172,7 @@ func (r DataPlaneOwnedResourceFinalizerReconciler[T, PT]) Reconcile(ctx context. // If the DataPlane still exists, we wait for it to be deleted. if !ownerIsGone { - log.Debug(logger, "not deleting, owner dataplane still exists", obj, "dataplane", ownerRef.Name) + log.Debug(logger, "not deleting, owner dataplane still exists", "dataplane", ownerRef.Name) return ctrl.Result{}, nil } @@ -185,7 +185,7 @@ func (r DataPlaneOwnedResourceFinalizerReconciler[T, PT]) Reconcile(ctx context. if err := r.Client.Patch(ctx, obj, client.MergeFrom(old)); err != nil { if k8serrors.IsNotFound(err) { // If the object is already gone, we don't need to do anything. - log.Debug(logger, "object is already gone", obj) + log.Debug(logger, "object is already gone") return ctrl.Result{}, nil } return ctrl.Result{}, fmt.Errorf("failed to remove finalizer from %s %s: %w", obj.GetObjectKind().GroupVersionKind().Kind, obj.GetName(), err) diff --git a/controller/gateway/controller.go b/controller/gateway/controller.go index 48d477d82..28081788a 100644 --- a/controller/gateway/controller.go +++ b/controller/gateway/controller.go @@ -107,24 +107,24 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) err func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.GetLogger(ctx, "gateway", r.DevelopmentMode) - log.Trace(logger, "reconciling gateway resource", req) + log.Trace(logger, "reconciling gateway resource") var gateway gwtypes.Gateway if err := r.Client.Get(ctx, req.NamespacedName, &gateway); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } - log.Trace(logger, "managing cleanup for gateway resource", gateway) + log.Trace(logger, "managing cleanup for gateway resource") if shouldReturnEarly, result, err := r.cleanup(ctx, logger, &gateway); err != nil || !result.IsZero() { return result, err } else if shouldReturnEarly { return ctrl.Result{}, nil } - log.Trace(logger, "checking gatewayclass", gateway) + log.Trace(logger, "checking gatewayclass") gwc, err := gatewayclass.Get(ctx, r.Client, string(gateway.Spec.GatewayClassName)) if err != nil { if errors.As(err, &operatorerrors.ErrUnsupportedGatewayClass{}) { - log.Debug(logger, "resource not supported, ignoring", gateway, + log.Debug(logger, "resource not supported, ignoring", "expectedGatewayClass", vars.ControllerName(), "gatewayClass", gateway.Spec.GatewayClassName, "reason", err.Error(), @@ -134,14 +134,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } - log.Trace(logger, "managing the gateway resource finalizers", gateway) + log.Trace(logger, "managing the gateway resource finalizers") cpFinalizerSet := controllerutil.AddFinalizer(&gateway, string(GatewayFinalizerCleanupControlPlanes)) dpFinalizerSet := controllerutil.AddFinalizer(&gateway, string(GatewayFinalizerCleanupDataPlanes)) npFinalizerSet := controllerutil.AddFinalizer(&gateway, string(GatewayFinalizerCleanupNetworkPolicies)) if cpFinalizerSet || dpFinalizerSet || npFinalizerSet { - log.Trace(logger, "Setting finalizers", gateway) + log.Trace(logger, "Setting finalizers") if err := r.Client.Update(ctx, &gateway); err != nil { - res, err := handleGatewayFinalizerPatchOrUpdateError(err, &gateway, logger) + res, err := handleGatewayFinalizerPatchOrUpdateError(err, logger) if err != nil { return res, fmt.Errorf("failed updating Gateway's finalizers: %w", err) } @@ -153,7 +153,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if !gwc.IsAccepted() { - log.Debug(logger, "gatewayclass not accepted , ignoring", gateway) + log.Debug(logger, "gatewayclass not accepted , ignoring") return ctrl.Result{}, nil } @@ -161,7 +161,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu gwConditionAware := gatewayConditionsAndListenersAware(&gateway) oldGwConditionsAware := gatewayConditionsAndListenersAware(oldGateway) - log.Trace(logger, "resource is supported, ensuring that it gets marked as accepted", gateway) + log.Trace(logger, "resource is supported that it gets marked as accepted") gwConditionAware.initListenersStatus() gwConditionAware.setConflicted() if err = gwConditionAware.setAcceptedAndAttachedRoutes(ctx, r.Client); err != nil { @@ -180,9 +180,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } if acceptedCondition.Status == metav1.ConditionTrue { - log.Info(logger, "gateway accepted", gateway) + log.Info(logger, "gateway accepted") } else { - log.Info(logger, "gateway not accepted", gateway) + log.Info(logger, "gateway not accepted") } return ctrl.Result{}, nil } @@ -192,7 +192,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, nil } - log.Trace(logger, "determining configuration", gateway) + log.Trace(logger, "determining configuration") gatewayConfig, err := r.getOrCreateGatewayConfiguration(ctx, gwc.GatewayClass) if err != nil { return ctrl.Result{}, err @@ -212,7 +212,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // ControlPlane as well to make DataPlane ready. if c, ok := k8sutils.GetCondition(DataPlaneReadyType, gwConditionAware); !ok || c.Status == metav1.ConditionFalse || provisionErr != nil { if provisionErr != nil { - log.Error(logger, provisionErr, "failed to provision dataplane", gateway) + log.Error(logger, provisionErr, "failed to provision dataplane") } oldCondition, oldFound := k8sutils.GetCondition(DataPlaneReadyType, oldGwConditionsAware) @@ -221,7 +221,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err := r.patchStatus(ctx, &gateway, oldGateway); err != nil { return ctrl.Result{}, err } - log.Debug(logger, "dataplane not ready yet", gateway) + log.Debug(logger, "dataplane not ready yet") return ctrl.Result{}, nil } @@ -234,7 +234,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu "dataplane is not ready yet, and the dataplane ready condition has already been set in the gateway, requeue after %s", provisionDataPlaneFailRetryAfter, ), - gateway) + ) return ctrl.Result{RequeueAfter: provisionDataPlaneFailRetryAfter}, nil } @@ -272,11 +272,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // if too many dataplane services are found here, this is a temporary situation. // the number of services will be reduced to 1 by the dataplane controller. if count > 1 { - log.Info(logger, fmt.Sprintf("found %d ingress services found for dataplane, requeuing...", count), gateway, "dataplane", client.ObjectKeyFromObject(dataplane)) + log.Info(logger, + fmt.Sprintf("found %d ingress services found for dataplane, requeuing...", count), + "dataplane", client.ObjectKeyFromObject(dataplane), + ) return ctrl.Result{Requeue: true}, nil } if count == 0 { - log.Info(logger, "no ingress services found for dataplane", gateway, "dataplane", client.ObjectKeyFromObject(dataplane)) + log.Info(logger, + "no ingress services found for dataplane", + "dataplane", client.ObjectKeyFromObject(dataplane), + ) return ctrl.Result{Requeue: true}, nil } @@ -299,11 +305,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // If too many dataplane services are found here, this is a temporary situation. // The number of services will be reduced to 1 by the dataplane controller. if count > 1 { - log.Info(logger, fmt.Sprintf("found %d admin services found for dataplane, requeuing...", count), gateway, "dataplane", client.ObjectKeyFromObject(dataplane)) + log.Info(logger, + fmt.Sprintf("found %d admin services found for dataplane, requeuing...", count), + "dataplane", client.ObjectKeyFromObject(dataplane), + ) return ctrl.Result{Requeue: true}, nil } if count == 0 { - log.Info(logger, "no admin services found for dataplane", gateway, "dataplane", client.ObjectKeyFromObject(dataplane)) + log.Info(logger, + "no admin services found for dataplane", + "dataplane", client.ObjectKeyFromObject(dataplane), + ) return ctrl.Result{Requeue: true}, nil } @@ -316,7 +328,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // * the new status is false and the previous status was true if condition, found := k8sutils.GetCondition(ControlPlaneReadyType, gwConditionAware); found && condition.Status != metav1.ConditionTrue { if condition.Reason == string(consts.UnableToProvisionReason) { - log.Debug(logger, "unable to provision controlplane, requeueing", gateway) + log.Debug(logger, "unable to provision controlplane, requeueing") return ctrl.Result{Requeue: true}, nil } @@ -325,18 +337,18 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err := r.patchStatus(ctx, &gateway, oldGateway); err != nil { return ctrl.Result{}, err } - log.Debug(logger, "controlplane not ready yet", gateway) + log.Debug(logger, "controlplane not ready yet") } return ctrl.Result{}, nil // requeue will be triggered by the update of the controlplane status } // if the controlplane wasn't ready before this reconciliation loop and now is ready, log this event if !k8sutils.IsConditionTrue(ControlPlaneReadyType, oldGwConditionsAware) { - log.Debug(logger, "controlplane is ready", gateway) + log.Debug(logger, "controlplane is ready") } // If the dataplane has not been marked as ready yet, return and wait for the next reconciliation loop. if !k8sutils.IsConditionTrue(DataPlaneReadyType, gwConditionAware) { - log.Debug(logger, "controlplane is ready, but dataplane is not ready yet", gateway) + log.Debug(logger, "controlplane is ready, but dataplane is not ready yet") return ctrl.Result{}, nil } // This should never happen as the controlplane at this point is always != nil. @@ -346,23 +358,23 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } // DataPlane NetworkPolicies - log.Trace(logger, "ensuring DataPlane's NetworkPolicy exists", gateway) + log.Trace(logger, "ensuring DataPlane's NetworkPolicy exists") createdOrUpdated, err := r.ensureDataPlaneHasNetworkPolicy(ctx, &gateway, dataplane, controlplane) if err != nil { return ctrl.Result{}, err } if createdOrUpdated { - log.Debug(logger, "networkPolicy updated", gateway) + log.Debug(logger, "networkPolicy updated") return ctrl.Result{}, nil // requeue will be triggered by the creation or update of the owned object } - log.Trace(logger, "ensuring DataPlane connectivity for Gateway", gateway) + log.Trace(logger, "ensuring DataPlane connectivity for Gateway") gateway.Status.Addresses, err = r.getGatewayAddresses(ctx, dataplane) if err == nil { k8sutils.SetCondition(k8sutils.NewConditionWithGeneration(GatewayServiceType, metav1.ConditionTrue, consts.ResourceReadyReason, "", gateway.Generation), gatewayConditionsAndListenersAware(&gateway)) } else { - log.Info(logger, "could not determine gateway status: %s", err) + log.Info(logger, "could not determine gateway status", "err", err) k8sutils.SetCondition(k8sutils.NewConditionWithGeneration(GatewayServiceType, metav1.ConditionFalse, GatewayReasonServiceError, err.Error(), gateway.Generation), gatewayConditionsAndListenersAware(&gateway)) } @@ -377,10 +389,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if k8sutils.IsProgrammed(gwConditionAware) && !k8sutils.IsProgrammed(oldGwConditionsAware) { - log.Debug(logger, "gateway is Programmed", gateway) + log.Debug(logger, "gateway is Programmed") } - log.Debug(logger, "reconciliation complete for Gateway resource", gateway) + log.Debug(logger, "reconciliation complete for Gateway resource") return ctrl.Result{}, nil } @@ -393,7 +405,7 @@ func (r *Reconciler) provisionDataPlane( logger = logger.WithName("dataplaneProvisioning") r.setDataPlaneGatewayConfigDefaults(gatewayConfig) - log.Trace(logger, "looking for associated dataplanes", gateway) + log.Trace(logger, "looking for associated dataplanes") dataplanes, err := gatewayutils.ListDataPlanesForGateway( ctx, r.Client, @@ -415,7 +427,7 @@ func (r *Reconciler) provisionDataPlane( createDataPlaneCondition(metav1.ConditionFalse, consts.UnableToProvisionReason, err.Error(), gateway.Generation), gatewayConditionsAndListenersAware(gateway), ) - log.Debug(logger, "reducing dataplanes", gateway, "count", count) + log.Debug(logger, "reducing dataplanes", "count", count) rErr := k8sreduce.ReduceDataPlanes(ctx, r.Client, dataplanes) if rErr != nil { return nil, fmt.Errorf("failed reducing data planes: %w", rErr) @@ -432,7 +444,7 @@ func (r *Reconciler) provisionDataPlane( ) return nil, err } - log.Debug(logger, "dataplane created", gateway) + log.Debug(logger, "dataplane created") k8sutils.SetCondition( createDataPlaneCondition(metav1.ConditionFalse, consts.ResourceCreatedOrUpdatedReason, consts.ResourceCreatedMessage, gateway.Generation), gatewayConditionsAndListenersAware(gateway), @@ -441,7 +453,7 @@ func (r *Reconciler) provisionDataPlane( } dataplane := dataplanes[0].DeepCopy() - log.Trace(logger, "ensuring dataplane config is up to date", gateway) + log.Trace(logger, "ensuring dataplane config is up to date") // compare deployment option of dataplane with dataplane deployment option of gatewayconfiguration. // if not configured in gatewayconfiguration, compare deployment option of dataplane with an empty one. expectedDataPlaneOptions := &operatorv1beta1.DataPlaneOptions{} @@ -461,7 +473,7 @@ func (r *Reconciler) provisionDataPlane( } if !dataplaneSpecDeepEqual(&dataplane.Spec.DataPlaneOptions, expectedDataPlaneOptions) { - log.Trace(logger, "dataplane config is out of date, updating", gateway) + log.Trace(logger, "dataplane config is out of date") oldDataPlane := dataplane.DeepCopy() dataplane.Spec.DataPlaneOptions = *expectedDataPlaneOptions @@ -476,10 +488,10 @@ func (r *Reconciler) provisionDataPlane( createDataPlaneCondition(metav1.ConditionFalse, consts.ResourceCreatedOrUpdatedReason, consts.ResourceUpdatedMessage, gateway.Generation), gatewayConditionsAndListenersAware(gateway), ) - log.Debug(logger, "dataplane config updated", gateway) + log.Debug(logger, "dataplane config updated") } - log.Trace(logger, "waiting for dataplane readiness", gateway) + log.Trace(logger, "waiting for dataplane readiness") if k8sutils.IsReady(dataplane) { k8sutils.SetCondition( @@ -507,10 +519,10 @@ func (r *Reconciler) provisionControlPlane( ) *operatorv1beta1.ControlPlane { logger = logger.WithName("controlplaneProvisioning") - log.Trace(logger, "looking for associated controlplanes", gateway) + log.Trace(logger, "looking for associated controlplanes") controlplanes, err := gatewayutils.ListControlPlanesForGateway(ctx, r.Client, gateway) if err != nil { - log.Debug(logger, fmt.Sprintf("failed listing associated controlplanes - error: %v", err), gateway) + log.Debug(logger, fmt.Sprintf("failed listing associated controlplanes - error: %v", err)) k8sutils.SetCondition( createControlPlaneCondition(metav1.ConditionFalse, consts.UnableToProvisionReason, err.Error(), gateway.Generation), gatewayConditionsAndListenersAware(gateway), @@ -526,13 +538,13 @@ func (r *Reconciler) provisionControlPlane( r.setControlPlaneGatewayConfigDefaults(gateway, gatewayConfig, dataplane.Name, ingressService.Name, adminService.Name, "") err := r.createControlPlane(ctx, gatewayClass, gateway, gatewayConfig, dataplane.Name) if err != nil { - log.Debug(logger, fmt.Sprintf("controlplane creation failed - error: %v", err), gateway) + log.Debug(logger, fmt.Sprintf("controlplane creation failed - error: %v", err)) k8sutils.SetCondition( createControlPlaneCondition(metav1.ConditionFalse, consts.UnableToProvisionReason, err.Error(), gateway.Generation), gatewayConditionsAndListenersAware(gateway), ) } else { - log.Debug(logger, "controlplane created", gateway) + log.Debug(logger, "controlplane created") k8sutils.SetCondition( createControlPlaneCondition(metav1.ConditionFalse, consts.ResourceCreatedOrUpdatedReason, consts.ResourceCreatedMessage, gateway.Generation), gatewayConditionsAndListenersAware(gateway), @@ -552,7 +564,7 @@ func (r *Reconciler) provisionControlPlane( controlPlane = controlplanes[0].DeepCopy() r.setControlPlaneGatewayConfigDefaults(gateway, gatewayConfig, dataplane.Name, ingressService.Name, adminService.Name, controlPlane.Name) - log.Trace(logger, "ensuring controlplane config is up to date", gateway) + log.Trace(logger, "ensuring controlplane config is up to date") // compare deployment option of controlplane with controlplane deployment option of gatewayconfiguration. // if not configured in gatewayconfiguration, compare deployment option of controlplane with an empty one. expectedControlPlaneOptions := &operatorv1beta1.ControlPlaneOptions{} @@ -563,7 +575,7 @@ func (r *Reconciler) provisionControlPlane( setControlPlaneOptionsDefaults(expectedControlPlaneOptions) if !controlplanecontroller.SpecDeepEqual(&controlPlane.Spec.ControlPlaneOptions, expectedControlPlaneOptions) { - log.Trace(logger, "controlplane config is out of date, updating", gateway) + log.Trace(logger, "controlplane config is out of date") controlplaneOld := controlPlane.DeepCopy() controlPlane.Spec.ControlPlaneOptions = *expectedControlPlaneOptions if err := r.Client.Patch(ctx, controlPlane, client.MergeFrom(controlplaneOld)); err != nil { @@ -579,7 +591,7 @@ func (r *Reconciler) provisionControlPlane( ) } - log.Trace(logger, "waiting for controlplane readiness", gateway) + log.Trace(logger, "waiting for controlplane readiness") if !k8sutils.IsReady(controlPlane) { k8sutils.SetCondition( createControlPlaneCondition(metav1.ConditionFalse, consts.WaitingToBecomeReadyReason, consts.WaitingToBecomeReadyMessage, gateway.Generation), diff --git a/controller/gateway/controller_cleanup.go b/controller/gateway/controller_cleanup.go index 0f7e96e4a..920dce07a 100644 --- a/controller/gateway/controller_cleanup.go +++ b/controller/gateway/controller_cleanup.go @@ -45,18 +45,18 @@ func (r *Reconciler) cleanup( error, ) { if gateway.DeletionTimestamp.IsZero() { - log.Trace(logger, "no cleanup required for Gateway", gateway) + log.Trace(logger, "no cleanup required for Gateway") return false, ctrl.Result{}, nil } if gateway.DeletionTimestamp.After(time.Now()) { - log.Debug(logger, "gateway deletion still under grace period", gateway) + log.Debug(logger, "gateway deletion still under grace period") return false, ctrl.Result{ Requeue: true, RequeueAfter: time.Until(gateway.DeletionTimestamp.Time), }, nil } - log.Trace(logger, "gateway is marked for deletion, waiting for owned resources to be deleted", gateway) + log.Trace(logger, "gateway is marked for deletion for owned resources to be deleted") // Delete owned controlplanes. // Because controlplanes have finalizers, so we only remove the finalizer @@ -71,7 +71,7 @@ func (r *Reconciler) cleanup( return false, ctrl.Result{}, err } if deletions { - log.Debug(logger, "deleted owned controlplanes", gateway) + log.Debug(logger, "deleted owned controlplanes") // Return early from reconciliation, deletion will trigger a new reconcile. return true, ctrl.Result{}, nil } @@ -79,10 +79,10 @@ func (r *Reconciler) cleanup( oldGateway := gateway.DeepCopy() if controllerutil.RemoveFinalizer(gateway, string(GatewayFinalizerCleanupControlPlanes)) { if err := r.Client.Patch(ctx, gateway, client.MergeFrom(oldGateway)); err != nil { - res, err := handleGatewayFinalizerPatchOrUpdateError(err, gateway, logger) + res, err := handleGatewayFinalizerPatchOrUpdateError(err, logger) return false, res, err } - log.Debug(logger, "finalizer for cleaning up controlplanes removed", gateway) + log.Debug(logger, "finalizer for cleaning up controlplanes removed") // Requeue to ensure that we continue reconciliation in case the patch // was empty and didn't trigger a new reconcile. return false, ctrl.Result{Requeue: true}, nil @@ -101,7 +101,7 @@ func (r *Reconciler) cleanup( return false, ctrl.Result{}, err } if deletions { - log.Debug(logger, "deleted owned dataplanes", gateway) + log.Debug(logger, "deleted owned dataplanes") // Return early from reconciliation, deletion will trigger a new reconcile. return true, ctrl.Result{}, err } @@ -109,10 +109,10 @@ func (r *Reconciler) cleanup( oldGateway := gateway.DeepCopy() if controllerutil.RemoveFinalizer(gateway, string(GatewayFinalizerCleanupDataPlanes)) { if err := r.Client.Patch(ctx, gateway, client.MergeFrom(oldGateway)); err != nil { - res, err := handleGatewayFinalizerPatchOrUpdateError(err, gateway, logger) + res, err := handleGatewayFinalizerPatchOrUpdateError(err, logger) return false, res, err } - log.Debug(logger, "finalizer for cleaning up dataplanes removed", gateway) + log.Debug(logger, "finalizer for cleaning up dataplanes removed") // Requeue to ensure that we continue reconciliation in case the patch // was empty and didn't trigger a new reconcile. return false, ctrl.Result{Requeue: true}, nil @@ -130,7 +130,7 @@ func (r *Reconciler) cleanup( return false, ctrl.Result{}, err } if deletions { - log.Debug(logger, "deleted owned network policies", gateway) + log.Debug(logger, "deleted owned network policies") // Return early from reconciliation, deletion will trigger a new reconcile. return true, ctrl.Result{}, err } @@ -138,21 +138,21 @@ func (r *Reconciler) cleanup( oldGateway := gateway.DeepCopy() if controllerutil.RemoveFinalizer(gateway, string(GatewayFinalizerCleanupNetworkPolicies)) { if err := r.Client.Patch(ctx, gateway, client.MergeFrom(oldGateway)); err != nil { - res, err := handleGatewayFinalizerPatchOrUpdateError(err, gateway, logger) + res, err := handleGatewayFinalizerPatchOrUpdateError(err, logger) return true, res, err } - log.Debug(logger, "finalizer for cleaning up network policies removed", gateway) + log.Debug(logger, "finalizer for cleaning up network policies removed") // Requeue to ensure that we continue reconciliation in case the patch // was empty and didn't trigger a new reconcile. return false, ctrl.Result{Requeue: true}, nil } } - log.Debug(logger, "owned resources cleanup completed", gateway) + log.Debug(logger, "owned resources cleanup completed") return false, ctrl.Result{}, nil } -func handleGatewayFinalizerPatchOrUpdateError(err error, gateway *gatewayv1.Gateway, logger logr.Logger) (ctrl.Result, error) { +func handleGatewayFinalizerPatchOrUpdateError(err error, logger logr.Logger) (ctrl.Result, error) { // Short cirtcuit. if err == nil { return ctrl.Result{}, nil @@ -171,7 +171,7 @@ func handleGatewayFinalizerPatchOrUpdateError(err error, gateway *gatewayv1.Gate // Forbidden: no new finalizers can be added if the object is being deleted, found new finalizers []string{...} // Code below handles that gracefully to not show users the errors that are not actionable. if cause, ok := k8serrors.StatusCause(err, metav1.CauseTypeForbidden); k8serrors.IsInvalid(err) && ok { - log.Debug(logger, "failed to delete a finalizer on Gateway, requeueing request", gateway, "cause", cause) + log.Debug(logger, "failed to delete a finalizer on Gateway, requeueing request", "cause", cause) return ctrl.Result{ Requeue: true, RequeueAfter: controller.RequeueWithoutBackoff, diff --git a/controller/gateway/controller_watch.go b/controller/gateway/controller_watch.go index fe0c3524e..963b39f8d 100644 --- a/controller/gateway/controller_watch.go +++ b/controller/gateway/controller_watch.go @@ -230,9 +230,9 @@ func (r *Reconciler) listManagedGatewaysInNamespace(ctx context.Context, obj cli if _, err := gatewayclass.Get(ctx, r.Client, string(gateway.Spec.GatewayClassName)); err != nil { if errors.As(err, &operatorerrors.ErrUnsupportedGatewayClass{}) { - log.Debug(logger, "gateway class not supported, ignoring", gateway) + log.Debug(logger, "gateway class not supported, ignoring") } else { - log.Error(logger, err, "failed to get Gateway's GatewayClass", gateway, + log.Error(logger, err, "failed to get Gateway's GatewayClass", "gatewayClass", objKey.Name, "gateway", gateway.Name, "namespace", gateway.Namespace, diff --git a/controller/gatewayclass/controller.go b/controller/gatewayclass/controller.go index 9a21e4313..74689ea55 100644 --- a/controller/gatewayclass/controller.go +++ b/controller/gatewayclass/controller.go @@ -43,13 +43,13 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) err func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.GetLogger(ctx, "gatewayclass", r.DevelopmentMode) - log.Trace(logger, "reconciling gatewayclass resource", req) + log.Trace(logger, "reconciling gatewayclass resource") gwc := gatewayclass.NewDecorator() if err := r.Client.Get(ctx, req.NamespacedName, gwc.GatewayClass); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } - log.Debug(logger, "processing gatewayclass", gwc.GatewayClass) + log.Debug(logger, "processing gatewayclass") if !gwc.IsControlled() { return ctrl.Result{}, nil @@ -70,7 +70,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu ) if err := r.Status().Patch(ctx, gwc.GatewayClass, client.MergeFrom(oldGwc)); err != nil { if k8serrors.IsConflict(err) { - log.Debug(logger, "conflict found when updating GatewayClass, retrying", gwc.GatewayClass) + log.Debug(logger, "conflict found when updating GatewayClass, retrying") return ctrl.Result{ Requeue: true, RequeueAfter: controller.RequeueWithoutBackoff, diff --git a/controller/kongplugininstallation/controller.go b/controller/kongplugininstallation/controller.go index 579479f0f..e8ee45344 100644 --- a/controller/kongplugininstallation/controller.go +++ b/controller/kongplugininstallation/controller.go @@ -87,7 +87,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) err func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.GetLogger(ctx, "kongplugininstallation", r.DevelopmentMode) - log.Trace(logger, "reconciling KongPluginInstallation resource", req) + log.Trace(logger, "reconciling KongPluginInstallation resource") var kpi v1alpha1.KongPluginInstallation if err := r.Client.Get(ctx, req.NamespacedName, &kpi); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) @@ -98,10 +98,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu return ctrl.Result{}, err } - log.Trace(logger, "managing KongPluginInstallation resource", kpi) + log.Trace(logger, "managing KongPluginInstallation resource") var credentialsStore credentials.Store if kpi.Spec.ImagePullSecretRef != nil { - log.Trace(logger, "getting secret for KongPluginInstallation resource", kpi) + log.Trace(logger, "getting secret for KongPluginInstallation resource") kpiNamespace := gatewayv1.Namespace(kpi.Namespace) imagePullSecretRef := kpi.Spec.ImagePullSecretRef ref.EnsureNamespaceInSecretRef(imagePullSecretRef, kpiNamespace) @@ -148,7 +148,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } } - log.Trace(logger, "fetch plugin for KongPluginInstallation resource", kpi) + log.Trace(logger, "fetch plugin for KongPluginInstallation resource") plugin, err := image.FetchPlugin(ctx, kpi.Spec.Image, credentialsStore) if err != nil { return ctrl.Result{}, setStatusConditionFailedForKongPluginInstallation(ctx, r.Client, &kpi, fmt.Sprintf("problem with the image: %q error: %s", kpi.Spec.Image, err)) diff --git a/controller/konnect/ops/ops.go b/controller/konnect/ops/ops.go index 1805754a3..770991cd3 100644 --- a/controller/konnect/ops/ops.go +++ b/controller/konnect/ops/ops.go @@ -273,7 +273,7 @@ func shouldUpdate[ timeFromLastUpdate <= syncPeriod { requeueAfter := syncPeriod - timeFromLastUpdate log.Debug(ctrllog.FromContext(ctx), - "no need for update, requeueing after configured sync period", ent, + "no need for update, requeueing after configured sync period", "last_update", condProgrammed.LastTransitionTime.Time.String(), "time_from_last_update", timeFromLastUpdate.String(), "requeue_after", requeueAfter.String(), diff --git a/controller/konnect/reconciler_generic.go b/controller/konnect/reconciler_generic.go index 0c097dc1f..71afcda84 100644 --- a/controller/konnect/reconciler_generic.go +++ b/controller/konnect/reconciler_generic.go @@ -142,7 +142,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile( logger = logger.WithValues("konnect_id", id) } ctx = ctrllog.IntoContext(ctx, logger) - log.Debug(logger, "reconciling", ent) + log.Debug(logger, "reconciling") // If a type has a ControlPlane ref, handle it. res, err := handleControlPlaneRef(ctx, r.Client, ent) @@ -212,7 +212,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, fmt.Errorf("failed to remove finalizer %s: %w", KonnectCleanupFinalizer, err) } - log.Debug(logger, "finalizer removed as the owning KongConsumer is being deleted or is already gone", ent, + log.Debug(logger, "finalizer removed as the owning KongConsumer is being deleted or is already gone", "finalizer", KonnectCleanupFinalizer, ) } @@ -252,7 +252,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, fmt.Errorf("failed to remove finalizer %s: %w", KonnectCleanupFinalizer, err) } - log.Debug(logger, "finalizer removed as the owning KongUpstream is being deleted or is already gone", ent, + log.Debug(logger, "finalizer removed as the owning KongUpstream is being deleted or is already gone", "finalizer", KonnectCleanupFinalizer, ) } @@ -291,7 +291,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, fmt.Errorf("failed to remove finalizer %s: %w", KonnectCleanupFinalizer, err) } - log.Debug(logger, "finalizer removed as the owning KongCertificate is being deleted or is already gone", ent, + log.Debug(logger, "finalizer removed as the owning KongCertificate is being deleted or is already gone", "finalizer", KonnectCleanupFinalizer, ) } @@ -329,7 +329,7 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, fmt.Errorf("failed to remove finalizer %s: %w", KonnectCleanupFinalizer, err) } - log.Debug(logger, "finalizer removed as the owning KongKeySet is being deleted or is already gone", ent, + log.Debug(logger, "finalizer removed as the owning KongKeySet is being deleted or is already gone", "finalizer", KonnectCleanupFinalizer, ) return ctrl.Result{}, nil diff --git a/controller/konnect/reconciler_generic_pluginbindingfinalizer.go b/controller/konnect/reconciler_generic_pluginbindingfinalizer.go index 634387209..f27bf8f81 100644 --- a/controller/konnect/reconciler_generic_pluginbindingfinalizer.go +++ b/controller/konnect/reconciler_generic_pluginbindingfinalizer.go @@ -158,7 +158,7 @@ func (r *KonnectEntityPluginBindingFinalizerReconciler[T, TEnt]) Reconcile( } ctx = ctrllog.IntoContext(ctx, logger) - log.Debug(logger, "reconciling", ent) + log.Debug(logger, "reconciling") cl := client.NewNamespacedClient(r.Client, ent.GetNamespace()) kongPluginBindingList := configurationv1alpha1.KongPluginBindingList{} @@ -183,7 +183,7 @@ func (r *KonnectEntityPluginBindingFinalizerReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, err } - log.Debug(logger, "KongPluginBinding deleted", kpb) + log.Debug(logger, "KongPluginBinding deleted") } // in case no KongPluginBindings are referencing the entity, but it has the finalizer, // we need to remove the finalizer. @@ -216,7 +216,7 @@ func (r *KonnectEntityPluginBindingFinalizerReconciler[T, TEnt]) Reconcile( } return ctrl.Result{}, err } - log.Debug(logger, "finalizers changed", ent, + log.Debug(logger, "finalizers changed", "action", finalizersChangedAction, "finalizer", consts.CleanupPluginBindingFinalizer, ) diff --git a/controller/konnect/reconciler_kongplugin.go b/controller/konnect/reconciler_kongplugin.go index 82eca0708..560c919b1 100644 --- a/controller/konnect/reconciler_kongplugin.go +++ b/controller/konnect/reconciler_kongplugin.go @@ -100,7 +100,7 @@ func (r *KongPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, client.IgnoreNotFound(err) } - log.Debug(logger, "reconciling", kongPlugin) + log.Debug(logger, "reconciling") clientWithNamespace := client.NewNamespacedClient(r.client, kongPlugin.Namespace) kongPluginNN := client.ObjectKeyFromObject(&kongPlugin) @@ -195,7 +195,7 @@ func (r *KongPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) if err = clientWithNamespace.Create(ctx, kongPluginBinding); err != nil { return ctrl.Result{}, fmt.Errorf("failed to create KongPluginBinding: %w", err) } - log.Debug(logger, "Managed KongPluginBinding created", kongPluginBinding) + log.Debug(logger, "Managed KongPluginBinding created") case 1: existing := kpbList[0] @@ -214,13 +214,13 @@ func (r *KongPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) } return ctrl.Result{}, fmt.Errorf("failed to update KongPluginBinding: %w", err) } - log.Debug(logger, "Managed KongPluginBinding updated", kongPluginBinding) + log.Debug(logger, "Managed KongPluginBinding updated") default: if err := k8sreduce.ReduceKongPluginBindings(ctx, clientWithNamespace, kpbList); err != nil { return ctrl.Result{}, fmt.Errorf("failed to reduce KongPluginBindings: %w", err) } - log.Info(logger, "deleted duplicated KongPluginBindings for KongPlugin", kongPlugin) + log.Info(logger, "deleted duplicated KongPluginBindings for KongPlugin") } } @@ -239,7 +239,7 @@ func (r *KongPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) } return ctrl.Result{}, err } - log.Debug(logger, "KongPlugin finalizer added", kongPlugin, "finalizer", consts.PluginInUseFinalizer) + log.Debug(logger, "KongPlugin finalizer added", "finalizer", consts.PluginInUseFinalizer) return ctrl.Result{}, nil } } else { @@ -250,12 +250,12 @@ func (r *KongPluginReconciler) Reconcile(ctx context.Context, req ctrl.Request) } return ctrl.Result{}, err } - log.Debug(logger, "KongPlugin finalizer removed", kongPlugin, "finalizer", consts.PluginInUseFinalizer) + log.Debug(logger, "KongPlugin finalizer removed", "finalizer", consts.PluginInUseFinalizer) return ctrl.Result{}, nil } } - log.Debug(logger, "reconciliation completed", kongPlugin) + log.Debug(logger, "reconciliation completed") return ctrl.Result{}, nil } @@ -338,7 +338,7 @@ func deleteKongPluginBindings( } return err } - log.Info(logger, "KongPluginBinding deleted", pb) + log.Info(logger, "KongPluginBinding deleted") } return nil } diff --git a/controller/konnect/reconciler_konnectapiauth.go b/controller/konnect/reconciler_konnectapiauth.go index 389242113..d9a2bd2e9 100644 --- a/controller/konnect/reconciler_konnectapiauth.go +++ b/controller/konnect/reconciler_konnectapiauth.go @@ -98,7 +98,7 @@ func (r *KonnectAPIAuthConfigurationReconciler) Reconcile( logger = log.GetLogger(ctx, entityTypeName, r.developmentMode) ) - log.Debug(logger, "reconciling", apiAuth) + log.Debug(logger, "reconciling") if !apiAuth.GetDeletionTimestamp().IsZero() { logger.Info("resource is being deleted") // wait for termination grace period before cleaning up diff --git a/controller/konnect/watch_kongplugin.go b/controller/konnect/watch_kongplugin.go index 967e43cc7..7ce993074 100644 --- a/controller/konnect/watch_kongplugin.go +++ b/controller/konnect/watch_kongplugin.go @@ -36,7 +36,7 @@ func mapPluginsFromAnnotation[ logger := log.GetLogger(ctx, entityTypeName, devMode) log.Error(logger, fmt.Errorf("cannot cast object to %s", entityTypeName), - fmt.Sprintf("%s mapping handler", entityTypeName), obj, + fmt.Sprintf("%s mapping handler", entityTypeName), ) return []ctrl.Request{} } @@ -64,7 +64,10 @@ func (r *KongPluginReconciler) mapKongPluginBindings(ctx context.Context, obj cl logger := log.GetLogger(ctx, "KongPlugin", r.developmentMode) kongPluginBinding, ok := obj.(*configurationv1alpha1.KongPluginBinding) if !ok { - log.Error(logger, errors.New("cannot cast object to KongPluginBinding"), "KongPluginBinding mapping handler", obj) + log.Error(logger, + errors.New("cannot cast object to KongPluginBinding"), + "KongPluginBinding mapping handler", + ) return []ctrl.Request{} } diff --git a/controller/konnect/watch_kongpluginbinding.go b/controller/konnect/watch_kongpluginbinding.go index 9795aa467..dd9731356 100644 --- a/controller/konnect/watch_kongpluginbinding.go +++ b/controller/konnect/watch_kongpluginbinding.go @@ -241,7 +241,6 @@ func enqueueKongPluginBindingFor[ logger, fmt.Errorf("unsupported entity type %s in KongPluginBinding watch", constraints.EntityTypeName[T]()), "unsupported entity type", - ent, ) return nil @@ -259,7 +258,6 @@ func enqueueKongPluginBindingFor[ logger, err, "failed to list KongPluginBindings referencing %ss", constraints.EntityTypeName[T](), - ent, ) return nil } diff --git a/controller/pkg/log/log.go b/controller/pkg/log/log.go index 7ed24da81..45ba1cc21 100644 --- a/controller/pkg/log/log.go +++ b/controller/pkg/log/log.go @@ -2,6 +2,7 @@ package log import ( "context" + "fmt" "github.com/go-logr/logr" ctrllog "sigs.k8s.io/controller-runtime/pkg/log" @@ -10,27 +11,43 @@ import ( ) // Info logs a message at the info level. -func Info[T any](log logr.Logger, msg string, rawObj T, keysAndValues ...interface{}) { - _log(log, logging.InfoLevel, msg, rawObj, keysAndValues...) +func Info(logger logr.Logger, msg string, keysAndValues ...interface{}) { + _log(logger, logging.InfoLevel, msg, keysAndValues...) } // Debug logs a message at the debug level. -func Debug[T any](log logr.Logger, msg string, rawObj T, keysAndValues ...interface{}) { - _log(log, logging.DebugLevel, msg, rawObj, keysAndValues...) +func Debug(logger logr.Logger, msg string, keysAndValues ...interface{}) { + _log(logger, logging.DebugLevel, msg, keysAndValues...) } // Trace logs a message at the trace level. -func Trace[T any](log logr.Logger, msg string, rawObj T, keysAndValues ...interface{}) { - _log(log, logging.TraceLevel, msg, rawObj, keysAndValues...) +func Trace(logger logr.Logger, msg string, keysAndValues ...interface{}) { + _log(logger, logging.TraceLevel, msg, keysAndValues...) } // Error logs a message at the error level. -func Error[T any](log logr.Logger, err error, msg string, rawObj T, keysAndValues ...interface{}) { - log.Error(err, msg, keysAndValues...) +func Error(logger logr.Logger, err error, msg string, keysAndValues ...interface{}) { + if !oddKeyValues(logger, msg, keysAndValues...) { + return + } + logger.Error(err, msg, keysAndValues...) } -func _log[T any](log logr.Logger, level logging.Level, msg string, rawObj T, keysAndValues ...interface{}) { //nolint:unparam - log.V(level.Value()).Info(msg, keysAndValues...) +func _log(logger logr.Logger, level logging.Level, msg string, keysAndValues ...interface{}) { + if !oddKeyValues(logger, msg, keysAndValues...) { + return + } + logger.V(level.Value()). + Info(msg, keysAndValues...) +} + +func oddKeyValues(logger logr.Logger, msg string, keysAndValues ...interface{}) bool { + if len(keysAndValues)%2 != 0 { + err := fmt.Errorf("log message has odd number of arguments") + logger.Error(err, msg) + return false + } + return true } // GetLogger returns a configured instance of logger. diff --git a/controller/pkg/patch/patch.go b/controller/pkg/patch/patch.go index c28f01f54..aa5fab6e0 100644 --- a/controller/pkg/patch/patch.go +++ b/controller/pkg/patch/patch.go @@ -28,7 +28,7 @@ func ApplyPatchIfNotEmpty[ kind := existingResource.GetObjectKind().GroupVersionKind().Kind if !updated { - log.Trace(logger, "No need for update", existingResource, kind, existingResource.GetName()) + log.Trace(logger, "No need for update", "kind", kind, "name", existingResource.GetName()) return op.Noop, existingResource, nil } @@ -41,7 +41,7 @@ func ApplyPatchIfNotEmpty[ } // Only perform the patch operation if the resulting patch is non empty. if len(b) == 0 || bytes.Equal(b, []byte("{}")) { - log.Trace(logger, "No need for update", existingResource, kind, existingResource.GetName()) + log.Trace(logger, "No need for update", "kind", kind, "name", existingResource.GetName()) return op.Noop, existingResource, nil } @@ -49,7 +49,7 @@ func ApplyPatchIfNotEmpty[ var t T return op.Noop, t, fmt.Errorf("failed patching %s %s: %w", kind, existingResource.GetName(), err) } - log.Debug(logger, "Resource modified", existingResource, kind, existingResource.GetName()) + log.Debug(logger, "Resource modified", "kind", kind, "name", existingResource.GetName()) return op.Updated, existingResource, nil } @@ -74,7 +74,7 @@ func ApplyStatusPatchIfNotEmpty[ } // Only perform the patch operation if the resulting patch is non empty. if len(b) == 0 || bytes.Equal(b, []byte("{}")) { - log.Trace(logger, "No need for status patch", existing) + log.Trace(logger, "No need for status patch") return op.Noop, nil } @@ -83,6 +83,6 @@ func ApplyStatusPatchIfNotEmpty[ existing, client.ObjectKeyFromObject(existing), err, ) } - log.Debug(logger, "Resource modified", existing) + log.Debug(logger, "Resource modified") return op.Updated, nil } diff --git a/controller/pkg/secrets/cert_test.go b/controller/pkg/secrets/cert_test.go index 6ef74461b..c9b3deb2d 100644 --- a/controller/pkg/secrets/cert_test.go +++ b/controller/pkg/secrets/cert_test.go @@ -31,7 +31,6 @@ import ( operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1" "github.com/kong/gateway-operator/controller/pkg/log" "github.com/kong/gateway-operator/controller/pkg/op" - gwtypes "github.com/kong/gateway-operator/internal/types" k8sresources "github.com/kong/gateway-operator/pkg/utils/kubernetes/resources" ) @@ -151,43 +150,37 @@ func TestLog(t *testing.T) { o.DestWriter = &buf }) - gw := gwtypes.Gateway{ - ObjectMeta: metav1.ObjectMeta{ - Name: "gw", - Namespace: "ns", - }, - } t.Run("info logging works both for values and pointers to objects", func(t *testing.T) { t.Cleanup(func() { buf.Reset() }) - log.Info(logger, "message about gw", gw) + log.Info(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") buf.Reset() - log.Info(logger, "message about gw", &gw) + log.Info(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") }) t.Run("debug logging works both for values and pointers to objects", func(t *testing.T) { t.Cleanup(func() { buf.Reset() }) - log.Debug(logger, "message about gw", gw) + log.Debug(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") - log.Debug(logger, "message about gw", &gw) + log.Debug(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") }) t.Run("trace logging works both for values and pointers to objects", func(t *testing.T) { t.Cleanup(func() { buf.Reset() }) - log.Trace(logger, "message about gw", gw) + log.Trace(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") t.Logf("log: %s", buf.String()) buf.Reset() - log.Trace(logger, "message about gw", &gw) + log.Trace(logger, "message about gw") require.NotContains(t, buf.String(), "unexpected type processed for") t.Logf("log: %s", buf.String()) }) t.Run("logging works and prints correct fields", func(t *testing.T) { t.Cleanup(func() { buf.Reset() }) - log.Info(logger, "message about gw", gw) + log.Info(logger, "message about gw") entry := struct { Level string `json:"level,omitempty"` Msg string `json:"msg,omitempty"` diff --git a/controller/specialized/aigateway_controller.go b/controller/specialized/aigateway_controller.go index aa3ef9a9b..085a8e8c5 100644 --- a/controller/specialized/aigateway_controller.go +++ b/controller/specialized/aigateway_controller.go @@ -61,7 +61,7 @@ func (r *AIGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{}, client.IgnoreNotFound(err) } - log.Trace(logger, "verifying gatewayclass for aigateway", aigateway) + log.Trace(logger, "verifying gatewayclass for aigateway") // we verify the GatewayClass in the watch predicates as well, but the watch // predicates are known to be lossy, so they are considered only an optimization // and this check must be done here to ensure consistency. @@ -70,34 +70,34 @@ func (r *AIGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( gwc, err := gatewayclass.Get(ctx, r.Client, aigateway.Spec.GatewayClassName) if err != nil { if errors.As(err, &operatorerrors.ErrUnsupportedGatewayClass{}) { - log.Debug(logger, "resource not supported, ignoring", aigateway, "ExpectedGatewayClass", vars.ControllerName()) + log.Debug(logger, "resource not supported, ignoring", "ExpectedGatewayClass", vars.ControllerName()) return ctrl.Result{}, nil } return ctrl.Result{}, err } if !gwc.IsAccepted() { - log.Debug(logger, "gatewayclass for aigateway is not accepted, ignoring", aigateway) + log.Debug(logger, "gatewayclass for aigateway is not accepted") return ctrl.Result{}, nil } - log.Trace(logger, "handling any necessary aigateway cleanup", aigateway) + log.Trace(logger, "handling any necessary aigateway cleanup") if aigateway.GetDeletionTimestamp() != nil { - log.Debug(logger, "aigateway is being deleted, ignoring", aigateway) + log.Debug(logger, "aigateway is being deleted") return ctrl.Result{}, nil } - log.Trace(logger, "marking aigateway as accepted", aigateway) + log.Trace(logger, "marking aigateway as accepted") oldAIGateway := aigateway.DeepCopy() k8sutils.SetCondition(newAIGatewayAcceptedCondition(&aigateway), &aigateway) if k8sutils.NeedsUpdate(oldAIGateway, &aigateway) { if err := r.Client.Status().Patch(ctx, &aigateway, client.MergeFrom(oldAIGateway)); err != nil { return ctrl.Result{}, fmt.Errorf("failed to patch status for aigateway: %w", err) } - log.Info(logger, "aigateway marked as accepted", aigateway) + log.Info(logger, "aigateway marked as accepted") return ctrl.Result{}, nil // update will re-queue } - log.Info(logger, "managing gateway resources for aigateway", aigateway) + log.Info(logger, "managing gateway resources for aigateway") gatewayResourcesChanged, err := r.manageGateway(ctx, logger, &aigateway) if err != nil { return ctrl.Result{}, err @@ -106,7 +106,7 @@ func (r *AIGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return ctrl.Result{Requeue: true}, nil } - log.Info(logger, "configuring plugin and route resources for aigateway", aigateway) + log.Info(logger, "configuring plugin and route resources for aigateway") pluginResourcesChanged, err := r.configurePlugins(ctx, logger, &aigateway) if err != nil { return ctrl.Result{}, err @@ -119,6 +119,6 @@ func (r *AIGatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // // See: https://github.com/Kong/gateway-operator/issues/137 - log.Info(logger, "reconciliation complete for aigateway resource", aigateway) + log.Info(logger, "reconciliation complete for aigateway resource") return ctrl.Result{}, nil } diff --git a/controller/specialized/aigateway_controller_reconciler_owned_resources.go b/controller/specialized/aigateway_controller_reconciler_owned_resources.go index 57b80f1f7..c8ce12287 100644 --- a/controller/specialized/aigateway_controller_reconciler_owned_resources.go +++ b/controller/specialized/aigateway_controller_reconciler_owned_resources.go @@ -23,10 +23,9 @@ import ( func (r *AIGatewayReconciler) createOrUpdateHttpRoute( ctx context.Context, logger logr.Logger, - aiGateway *v1alpha1.AIGateway, httpRoute *gatewayv1.HTTPRoute, ) (bool, error) { - log.Trace(logger, "checking for any existing httproute for aigateway", aiGateway) + log.Trace(logger, "checking for any existing httproute for aigateway") // TODO - use GenerateName // @@ -38,7 +37,7 @@ func (r *AIGatewayReconciler) createOrUpdateHttpRoute( }, found) if err != nil { if k8serrors.IsNotFound(err) { - log.Info(logger, "creating httproute for aigateway", aiGateway) + log.Info(logger, "creating httproute for aigateway") return true, r.Client.Create(ctx, httpRoute) } return false, err @@ -54,10 +53,9 @@ func (r *AIGatewayReconciler) createOrUpdateHttpRoute( func (r *AIGatewayReconciler) createOrUpdatePlugin( ctx context.Context, logger logr.Logger, - aiGateway *v1alpha1.AIGateway, kongPlugin *configurationv1.KongPlugin, ) (bool, error) { - log.Trace(logger, "checking for any existing plugin for aigateway", aiGateway) + log.Trace(logger, "checking for any existing plugin for aigateway") // TODO - use GenerateName // @@ -69,7 +67,7 @@ func (r *AIGatewayReconciler) createOrUpdatePlugin( }, found) if err != nil { if k8serrors.IsNotFound(err) { - log.Info(logger, "creating plugin for aigateway", aiGateway) + log.Info(logger, "creating plugin for aigateway") return true, r.Client.Create(ctx, kongPlugin) } return false, err @@ -85,10 +83,9 @@ func (r *AIGatewayReconciler) createOrUpdatePlugin( func (r *AIGatewayReconciler) createOrUpdateGateway( ctx context.Context, logger logr.Logger, - aiGateway *v1alpha1.AIGateway, gateway *gatewayv1.Gateway, ) (bool, error) { - log.Trace(logger, "checking for any existing gateway for aigateway", aiGateway) + log.Trace(logger, "checking for any existing gateway for aigateway") found := &gatewayv1.Gateway{} // TODO - use GenerateName @@ -100,7 +97,7 @@ func (r *AIGatewayReconciler) createOrUpdateGateway( }, found) if err != nil { if k8serrors.IsNotFound(err) { - log.Info(logger, "creating gateway for aigateway", aiGateway) + log.Info(logger, "creating gateway for aigateway") return true, r.Client.Create(ctx, gateway) } @@ -117,10 +114,9 @@ func (r *AIGatewayReconciler) createOrUpdateGateway( func (r *AIGatewayReconciler) createOrUpdateSvc( ctx context.Context, logger logr.Logger, - aiGateway *v1alpha1.AIGateway, service *corev1.Service, ) (bool, error) { - log.Trace(logger, "checking for any existing service for aigateway", aiGateway) + log.Trace(logger, "checking for any existing service for aigateway") // TODO - use GenerateName // @@ -132,7 +128,7 @@ func (r *AIGatewayReconciler) createOrUpdateSvc( }, found) if err != nil { if k8serrors.IsNotFound(err) { - log.Info(logger, "creating service for aigateway", aiGateway) + log.Info(logger, "creating service for aigateway") return true, r.Client.Create(ctx, service) } @@ -158,7 +154,7 @@ func (r *AIGatewayReconciler) manageGateway( bool, // whether any changes were made error, ) { - change, err := r.createOrUpdateGateway(ctx, logger, aiGateway, aiGatewayToGateway(aiGateway)) + change, err := r.createOrUpdateGateway(ctx, logger, aiGatewayToGateway(aiGateway)) if change { return true, err } @@ -179,9 +175,9 @@ func (r *AIGatewayReconciler) configurePlugins( ) { changes := false - log.Trace(logger, "configuring sink service for aigateway", aiGateway) + log.Trace(logger, "configuring sink service for aigateway") aiGatewaySinkService := aiCloudGatewayToKubeSvc(aiGateway) - changed, err := r.createOrUpdateSvc(ctx, logger, aiGateway, aiGatewaySinkService) + changed, err := r.createOrUpdateSvc(ctx, logger, aiGatewaySinkService) if changed { changes = true } @@ -189,7 +185,7 @@ func (r *AIGatewayReconciler) configurePlugins( return changes, err } - log.Trace(logger, "retrieving the cloud provider credentials secret for aigateway", aiGateway) + log.Trace(logger, "retrieving the cloud provider credentials secret for aigateway") if aiGateway.Spec.CloudProviderCredentials == nil { return changes, fmt.Errorf("ai gateway '%s' requires secret reference for Cloud Provider API keys", aiGateway.Name) } @@ -209,11 +205,11 @@ func (r *AIGatewayReconciler) configurePlugins( ) } - log.Trace(logger, "generating routes and plugins for aigateway", aiGateway) + log.Trace(logger, "generating routes and plugins for aigateway") for _, v := range aiGateway.Spec.LargeLanguageModels.CloudHosted { cloudHostedLLM := v - log.Trace(logger, "determining whether we have API keys configured for cloud provider", aiGateway) + log.Trace(logger, "determining whether we have API keys configured for cloud provider") credentialData, ok := credentialSecret.Data[string(cloudHostedLLM.AICloudProvider.Name)] if !ok { return changes, fmt.Errorf( @@ -222,12 +218,12 @@ func (r *AIGatewayReconciler) configurePlugins( ) } - log.Trace(logger, "configuring the base aiproxy plugin for aigateway", aiGateway) + log.Trace(logger, "configuring the base aiproxy plugin for aigateway") aiProxyPlugin, err := aiCloudGatewayToKongPlugin(&cloudHostedLLM, aiGateway, &credentialData) if err != nil { return changes, err } - changed, err := r.createOrUpdatePlugin(ctx, logger, aiGateway, aiProxyPlugin) + changed, err := r.createOrUpdatePlugin(ctx, logger, aiProxyPlugin) if changed { changes = true } @@ -235,13 +231,13 @@ func (r *AIGatewayReconciler) configurePlugins( return changes, err } - log.Trace(logger, "configuring the ai prompt decorator plugin for aigateway", aiGateway) + log.Trace(logger, "configuring the ai prompt decorator plugin for aigateway") decoratorPlugin, err := aiCloudGatewayToKongPromptDecoratorPlugin(&cloudHostedLLM, aiGateway) if err != nil { return changes, err } if decoratorPlugin != nil { - changed, err := r.createOrUpdatePlugin(ctx, logger, aiGateway, decoratorPlugin) + changed, err := r.createOrUpdatePlugin(ctx, logger, decoratorPlugin) if changed { changes = true } @@ -250,13 +246,13 @@ func (r *AIGatewayReconciler) configurePlugins( } } - log.Trace(logger, "configuring an httproute for aigateway", aiGateway) + log.Trace(logger, "configuring an httproute for aigateway") plugins := []string{aiProxyPlugin.Name} if decoratorPlugin != nil { plugins = append(plugins, decoratorPlugin.Name) } httpRoute := aiCloudGatewayToHTTPRoute(&cloudHostedLLM, aiGateway, aiGatewaySinkService, plugins) - changed, err = r.createOrUpdateHttpRoute(ctx, logger, aiGateway, httpRoute) + changed, err = r.createOrUpdateHttpRoute(ctx, logger, httpRoute) if changed { changes = true }