Skip to content

Commit

Permalink
logs: remove/replace WithName
Browse files Browse the repository at this point in the history
  • Loading branch information
phlg committed Aug 12, 2024
1 parent edbd00c commit 0e162b2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const bucketFinalizer = "s3.onyxia.sh/finalizer"
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("bcktCtrl")
logger := log.FromContext(ctx)

// Checking for bucket resource existence
bucketResource := &s3v1alpha1.Bucket{}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (r *BucketReconciler) finalizeBucket(bucketResource *s3v1alpha1.Bucket) err
}

func (r *BucketReconciler) SetBucketStatusConditionAndUpdate(ctx context.Context, bucketResource *s3v1alpha1.Bucket, conditionType string, status metav1.ConditionStatus, reason string, message string, srcError error) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("bcktCtrl")
logger := log.FromContext(ctx)

// We moved away from meta.SetStatusCondition, as the implementation did not allow for updating
// lastTransitionTime if a Condition (as identified by Reason instead of Type) was previously
Expand Down
6 changes: 3 additions & 3 deletions controllers/path_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const pathFinalizer = "s3.onyxia.sh/finalizer"
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
func (r *PathReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("pathCtrl")
logger := log.FromContext(ctx)

// Checking for path resource existence
pathResource := &s3v1alpha1.Path{}
Expand Down Expand Up @@ -184,7 +184,7 @@ func (r *PathReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *PathReconciler) finalizePath(pathResource *s3v1alpha1.Path) error {
logger := log.Log.WithName("finalize")
logger := log.Log.WithValues("controller", "path")
if r.PathDeletion {
var failedPaths []string = make([]string, 0)
for _, path := range pathResource.Spec.Paths {
Expand All @@ -210,7 +210,7 @@ func (r *PathReconciler) finalizePath(pathResource *s3v1alpha1.Path) error {
}

func (r *PathReconciler) SetPathStatusConditionAndUpdate(ctx context.Context, pathResource *s3v1alpha1.Path, conditionType string, status metav1.ConditionStatus, reason string, message string, srcError error) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("pathCtrl")
logger := log.FromContext(ctx)

// We moved away from meta.SetStatusCondition, as the implementation did not allow for updating
// lastTransitionTime if a Condition (as identified by Reason instead of Type) was previously
Expand Down
4 changes: 2 additions & 2 deletions controllers/policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const policyFinalizer = "s3.onyxia.sh/finalizer"
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
func (r *PolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("plcyCtrl")
logger := log.FromContext(ctx)

// Checking for policy resource existence
policyResource := &s3v1alpha1.Policy{}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (r *PolicyReconciler) finalizePolicy(policyResource *s3v1alpha1.Policy) err
}

func (r *PolicyReconciler) SetPolicyStatusConditionAndUpdate(ctx context.Context, policyResource *s3v1alpha1.Policy, conditionType string, status metav1.ConditionStatus, reason string, message string, srcError error) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("plcyCtrl")
logger := log.FromContext(ctx)

// We moved away from meta.SetStatusCondition, as the implementation did not allow for updating
// lastTransitionTime if a Condition (as identified by Reason instead of Type) was previously
Expand Down
2 changes: 1 addition & 1 deletion controllers/s3/factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
s3Logger = ctrl.Log.WithName("s3Client")
s3Logger = ctrl.Log.WithValues("logger", "s3client")
)

type S3Client interface {
Expand Down
18 changes: 9 additions & 9 deletions controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
func (r *S3UserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

// Checking for userResource existence
userResource := &s3v1alpha1.S3User{}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (r *S3UserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

func (r *S3UserReconciler) handleS3ExistingUser(ctx context.Context, userResource *s3v1alpha1.S3User) (reconcile.Result, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

// --- Begin Secret management section

Expand Down Expand Up @@ -239,7 +239,7 @@ func (r *S3UserReconciler) handleS3ExistingUser(ctx context.Context, userResourc
}

func (r *S3UserReconciler) handleS3NewUser(ctx context.Context, userResource *s3v1alpha1.S3User) (reconcile.Result, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

// Generating a random secret key
secretKey, err := password.Generate(20, true, false, true)
Expand Down Expand Up @@ -357,7 +357,7 @@ func (r *S3UserReconciler) handleS3NewUser(ctx context.Context, userResource *s3
}

func (r *S3UserReconciler) addPoliciesToUser(ctx context.Context, userResource *s3v1alpha1.S3User) error {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)
policies := userResource.Spec.Policies
if policies != nil {
err := r.S3Client.AddPoliciesToUser(userResource.Spec.AccessKey, policies)
Expand All @@ -370,7 +370,7 @@ func (r *S3UserReconciler) addPoliciesToUser(ctx context.Context, userResource *
}

func (r *S3UserReconciler) handleS3UserDeletion(ctx context.Context, userResource *s3v1alpha1.S3User) (reconcile.Result, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

if controllerutil.ContainsFinalizer(userResource, userFinalizer) {
// Run finalization logic for S3UserFinalizer. If the finalization logic fails, don't remove the finalizer so that we can retry during the next reconciliation.
Expand All @@ -397,7 +397,7 @@ func (r *S3UserReconciler) handleS3UserDeletion(ctx context.Context, userResourc
}

func (r *S3UserReconciler) getUserSecret(ctx context.Context, userResource *s3v1alpha1.S3User) (corev1.Secret, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

// Listing every secrets in the S3User's namespace, as a first step
// to get the actual secret matching the S3User proper.
Expand Down Expand Up @@ -443,7 +443,7 @@ func (r *S3UserReconciler) getUserSecret(ctx context.Context, userResource *s3v1
}

func (r *S3UserReconciler) deleteSecret(ctx context.Context, secret *corev1.Secret) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)
err := r.Delete(ctx, secret)
if err != nil {
logger.Error(err, "an error occurred while deleting a secret")
Expand Down Expand Up @@ -492,7 +492,7 @@ func (r *S3UserReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *S3UserReconciler) setS3UserStatusConditionAndUpdate(ctx context.Context, userResource *s3v1alpha1.S3User, conditionType string, status metav1.ConditionStatus, reason string, message string, srcError error) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

// We moved away from meta.SetStatusCondition, as the implementation did not allow for updating
// lastTransitionTime if a Condition (as identified by Reason instead of Type) was previously
Expand Down Expand Up @@ -524,7 +524,7 @@ func (r *S3UserReconciler) finalizeS3User(userResource *s3v1alpha1.S3User) error
// newSecretForCR returns a secret with the same name/namespace as the CR.
// The secret will include all labels and annotations from the CR.
func (r *S3UserReconciler) newSecretForCR(ctx context.Context, userResource *s3v1alpha1.S3User, data map[string][]byte) (*corev1.Secret, error) {
logger := log.FromContext(ctx).WithName("userCtrl")
logger := log.FromContext(ctx)

labels := map[string]string{}
for k, v := range userResource.ObjectMeta.Labels {
Expand Down

0 comments on commit 0e162b2

Please sign in to comment.