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

Adding logging statements for pullsecret controller #3613

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,22 @@ func (r *Reconciler) ensureGlobalPullSecret(ctx context.Context, operatorSecret,
// allows for simpler logic flow, when delete and create are not handled separately
// this call happens only when there is a need to change, it has no significant impact on performance
err := r.client.Delete(ctx, secret)
r.log.Info("Global Pull secret Not Found, Creating Again")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be one line above or after if err clause.
It would be better that there is always a if err clause just after it gets err.

if err != nil && !kerrors.IsNotFound(err) {
return nil, err
}

err = r.client.Create(ctx, secret)
if err == nil {
r.log.Info("Global Pull secret Created")
}
Comment on lines 192 to +195
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a matter of preference, but I don't want to have if clause just for one line log.
If you want to check if it failed then you can check outside of the function by checking err returned.

Suggested change
err = r.client.Create(ctx, secret)
if err == nil {
r.log.Info("Global Pull secret Created")
}
r.log.Info("Creating global pull secret")
err = r.client.Create(ctx, secret)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it the way it is personally, because it only logs when something was successful. If there's a failure, you'd get the error updating the k8s object returned instead. These logs were primarily what we were missing before, but either way works for me.

return secret, err
}

err = r.client.Update(ctx, secret)
if err == nil {
r.log.Info("Updating Existing Global Pull secret")
kimorris27 marked this conversation as resolved.
Show resolved Hide resolved
}
return secret, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ func TestEnsureGlobalPullSecret(t *testing.T) {

r := &Reconciler{
client: clientBuilder.Build(),
log: logrus.NewEntry(logrus.StandardLogger()),
}

s, err := r.ensureGlobalPullSecret(ctx, tt.operatorPullSecret, tt.pullSecret)
Expand Down
Loading