Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update log calls to be more consistent #92

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/gatekeepersync/gatekeeper_constraint_sync.go
Expand Up @@ -112,7 +112,7 @@ func (r *GatekeeperConstraintReconciler) Reconcile(
err := r.Get(ctx, request.NamespacedName, policy)
if err != nil {
if k8serrors.IsNotFound(err) {
log.V(1).Info("The Policy was deleted. Cleaning up watchers and status message cache.")
log.Info("The Policy was deleted. Cleaning up watchers and status message cache.")

r.lastSentMessages.Range(func(key, value any) bool {
keyTyped := key.(policyKindName)
Expand Down
24 changes: 14 additions & 10 deletions controllers/secretsync/secret_sync.go
Expand Up @@ -63,15 +63,15 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ
)

if uninstall.DeploymentIsUninstalling {
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
reqLogger.Info("Skipping reconcile because the deployment is in uninstallation mode")

return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}

reqLogger.Info("Reconciling Secret")
// The cache configuration of SelectorsByObject should prevent this from happening, but add this as a precaution.
if request.Name != SecretName {
log.Info("Got a reconciliation request for an unexpected Secret. This should have been filtered out.")
reqLogger.Info("Got a reconciliation request for an unexpected Secret. This should have been filtered out.")

return reconcile.Result{}, nil
}
Expand All @@ -81,12 +81,12 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ
err := r.Get(ctx, request.NamespacedName, hubEncryptionSecret)
if err != nil {
if !errors.IsNotFound(err) {
log.Error(err, "Failed to get the Secret on the Hub. Requeueing the request.")
reqLogger.Error(err, "Failed to get the Secret on the Hub. Requeueing the request.")

return reconcile.Result{}, err
}

log.Info("The Secret is no longer on the Hub. Deleting the replicated Secret.")
reqLogger.Info("The Secret is no longer on the Hub. Deleting the replicated Secret.")

err := r.ManagedClient.Delete(
ctx,
Expand All @@ -98,11 +98,13 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ
},
)
if err != nil && !errors.IsNotFound(err) {
log.Error(err, "Failed to delete the replicated Secret. Requeueing the request.")
reqLogger.Error(err, "Failed to delete the replicated Secret. Requeueing the request.")

return reconcile.Result{}, err
}

reqLogger.Info("Secret deleted, Reconciliation complete.")

return reconcile.Result{}, nil
}

Expand All @@ -113,11 +115,13 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ

if err != nil {
if !errors.IsNotFound(err) {
log.Error(err, "Failed to get the replicated Secret. Requeueing the request.")
reqLogger.Error(err, "Failed to get the replicated Secret. Requeueing the request.")

return reconcile.Result{}, err
}

reqLogger.Info("Creating the replicated secret")

// Don't completely copy the Hub secret since it isn't desired to have any annotations related to disaster
// recovery copied over.
managedEncryptionSecret := &corev1.Secret{
Expand All @@ -130,24 +134,24 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ

err := r.ManagedClient.Create(ctx, managedEncryptionSecret)
if err != nil {
log.Error(err, "Failed to replicate the Secret. Requeueing the request.")
reqLogger.Error(err, "Failed to replicate the Secret. Requeueing the request.")

return reconcile.Result{}, err
}

reqLogger.Info("Reconciliation complete")
reqLogger.Info("Secret replicated, Reconciliation complete")

return reconcile.Result{}, nil
}

if !equality.Semantic.DeepEqual(hubEncryptionSecret.Data, managedEncryptionSecret.Data) {
log.Info("Updating the replicated secret due to it not matching the source on the Hub")
reqLogger.Info("Updating the replicated secret due to it not matching the source on the Hub")

managedEncryptionSecret.Data = hubEncryptionSecret.Data

err := r.ManagedClient.Update(ctx, managedEncryptionSecret)
if err != nil {
log.Error(err, "Failed to update the replicated Secret. Requeueing the request.")
reqLogger.Error(err, "Failed to update the replicated Secret. Requeueing the request.")

return reconcile.Result{}, err
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/specsync/policy_spec_sync.go
Expand Up @@ -72,7 +72,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
)

if uninstall.DeploymentIsUninstalling {
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
reqLogger.Info("Skipping reconcile because the deployment is in uninstallation mode")

return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}
Expand Down Expand Up @@ -101,6 +101,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ

if err != nil && !errors.IsNotFound(err) {
reqLogger.Error(err, "Failed to remove policy on managed cluster...")

return reconcile.Result{}, err
}

reqLogger.Info("Policy has been removed from managed cluster...Reconciliation complete.")
Expand Down
20 changes: 5 additions & 15 deletions controllers/statussync/eventMapper.go
Expand Up @@ -5,7 +5,6 @@ package statussync

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -17,13 +16,9 @@ func eventMapper(_ context.Context, obj client.Object) []reconcile.Request {
//nolint:forcetypeassert
event := obj.(*corev1.Event)

log.Info(
fmt.Sprintf(
"Reconcile Request for Event %s in namespace %s",
event.GetName(),
event.GetNamespace(),
),
)
log := log.WithValues("eventName", event.GetName(), "eventNamespace", event.GetNamespace())

log.V(2).Info("Reconcile Request")

var result []reconcile.Request

Expand All @@ -32,13 +27,8 @@ func eventMapper(_ context.Context, obj client.Object) []reconcile.Request {
Namespace: event.InvolvedObject.Namespace,
}}

log.Info(
fmt.Sprintf(
"Queue event for Policy %s in namespace %s",
event.InvolvedObject.Name,
event.InvolvedObject.Namespace,
),
)
log.V(2).Info("Queueing event", "involvedName", event.InvolvedObject.Name,
"involvedNamespace", event.InvolvedObject.Namespace)

return append(result, request)
}
10 changes: 6 additions & 4 deletions controllers/statussync/policy_status_sync.go
Expand Up @@ -86,7 +86,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
)

if uninstall.DeploymentIsUninstalling {
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
reqLogger.Info("Skipping reconcile because the deployment is in uninstallation mode")

return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}
Expand Down Expand Up @@ -130,6 +130,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
managedInstance.SetOwnerReferences(nil)
managedInstance.SetResourceVersion("")

reqLogger.Info("Policy missing from managed cluster, creating it.")

return reconcile.Result{}, r.ManagedClient.Create(ctx, managedInstance)
}
// Error reading the object - requeue the request.
Expand Down Expand Up @@ -245,7 +247,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
existingDpt = dpt
found = true

reqLogger.Info("Found existing status, retrieving it", "PolicyTemplate", tName)
reqLogger.V(1).Info("Found existing status, retrieving it", "PolicyTemplate", tName)

break
}
Expand Down Expand Up @@ -360,7 +362,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
// append existingDpt to status
newStatus.Details = append(newStatus.Details, existingDpt)

reqLogger.Info("Status update complete", "PolicyTemplate", tName)
reqLogger.V(1).Info("Status update complete", "PolicyTemplate", tName)
}

instance.Status = newStatus
Expand Down Expand Up @@ -411,7 +413,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
// Re-fetch the hub template in case it changed
err = r.HubClient.Get(ctx, types.NamespacedName{Namespace: r.ClusterNamespaceOnHub, Name: request.Name}, hubPlc)
if err != nil {
log.Error(err, "Failed to refresh the cached policy. Will use existing policy.")
reqLogger.Error(err, "Failed to refresh the cached policy. Will use existing policy.")
}

if !equality.Semantic.DeepEqual(hubPlc.Status, instance.Status) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/templatesync/template_sync.go
Expand Up @@ -222,7 +222,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
}

if uninstall.DeploymentIsUninstalling {
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
reqLogger.Info("Skipping reconcile because the deployment is in uninstallation mode")

return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}
Expand Down