Skip to content

Commit e58b856

Browse files
Avoid credentials in logs
Signed-off-by: Gowtham Shanmugasundaram <gshanmug@redhat.com>
1 parent 43918a0 commit e58b856

4 files changed

+21
-23
lines changed

controllers/common-controller-utils.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func createOrUpdateDestinationSecretsFromSource(ctx context.Context, rc client.C
2929
logger := log.FromContext(ctx)
3030
err := common.ValidateSourceSecret(sourceSecret)
3131
if err != nil {
32-
logger.Error(err, "Updating secrets failed. Invalid secret type.", "secret", sourceSecret)
32+
logger.Error(err, "Updating secrets failed. Invalid secret type.", "secret", sourceSecret.Name)
3333
return err
3434
}
3535

@@ -44,10 +44,10 @@ func createOrUpdateDestinationSecretsFromSource(ctx context.Context, rc client.C
4444

4545
uniqueConnectedPeers, err := PeersConnectedToSecret(sourceSecret, mirrorPeers)
4646
if err != nil {
47-
logger.Error(err, "ConnectedPeers returned an error", "secret", sourceSecret, "mirrorpeers", mirrorPeers)
47+
logger.Error(err, "ConnectedPeers returned an error", "secret", sourceSecret.Name, "mirrorpeers", mirrorPeers)
4848
return err
4949
}
50-
logger.V(2).Info("Listing all the Peers connected to the Source", "SourceSecret", sourceSecret, "#connected-peers", len(uniqueConnectedPeers))
50+
logger.V(2).Info("Listing all the Peers connected to the Source", "SourceSecret", sourceSecret.Name, "#connected-peers", len(uniqueConnectedPeers))
5151

5252
// anyErr will have the last found error
5353
var anyErr error
@@ -67,7 +67,7 @@ func processDestinationSecretUpdation(ctx context.Context, rc client.Client, des
6767
logger := log.FromContext(ctx)
6868
err := common.ValidateDestinationSecret(destSecret)
6969
if err != nil {
70-
logger.Error(err, "Destination secret validation failed", "secret", destSecret)
70+
logger.Error(err, "Destination secret validation failed", "secret", destSecret.Name)
7171
return err
7272
}
7373
mirrorPeers, err := common.FetchAllMirrorPeers(ctx, rc)
@@ -77,7 +77,7 @@ func processDestinationSecretUpdation(ctx context.Context, rc client.Client, des
7777
}
7878
uniqueConnectedPeers, err := PeersConnectedToSecret(destSecret, mirrorPeers)
7979
if err != nil {
80-
logger.Error(err, "Failed to get the peers connected to the secret", "secret", destSecret)
80+
logger.Error(err, "Failed to get the peers connected to the secret", "secret", destSecret.Name)
8181
return err
8282
}
8383
var connectedSource *corev1.Secret
@@ -89,7 +89,7 @@ func processDestinationSecretUpdation(ctx context.Context, rc client.Client, des
8989
if k8serrors.IsNotFound(err) {
9090
continue
9191
}
92-
logger.Error(err, "Unexpected error while finding the source secret", "peer-ref", eachConnectedPeer, "secret", destSecret)
92+
logger.Error(err, "Unexpected error while finding the source secret", "peer-ref", eachConnectedPeer, "secret", destSecret.Name)
9393
return err
9494
}
9595
if common.IsSecretSource(&connectedSecret) {
@@ -99,7 +99,7 @@ func processDestinationSecretUpdation(ctx context.Context, rc client.Client, des
9999
}
100100

101101
if connectedSource == nil {
102-
logger.Error(nil, "No connected source found. Removing the dangling destination secret", "secret", destSecret)
102+
logger.Error(nil, "No connected source found. Removing the dangling destination secret", "secret", destSecret.Name)
103103
err = rc.Delete(ctx, destSecret)
104104
return err
105105
}
@@ -119,7 +119,7 @@ func processDestinationSecretCleanup(ctx context.Context, rc client.Client) erro
119119
err = processDestinationSecretUpdation(ctx, rc, &eachDSecret)
120120
if err != nil {
121121
anyError = err
122-
logger.Error(err, "Failed to update destination secret", "secret", eachDSecret)
122+
logger.Error(err, "Failed to update destination secret", "secret", eachDSecret.Name)
123123
}
124124
}
125125
return anyError
@@ -153,7 +153,7 @@ func createOrUpdateRamenS3Secret(ctx context.Context, rc client.Client, secret *
153153
if err != nil {
154154
if k8serrors.IsNotFound(err) {
155155
// creating new s3 secret on ramen openshift-dr-system namespace
156-
logger.Info("Creating a s3 secret", "secret", expectedSecret)
156+
logger.Info("Creating a s3 secret", "secret", expectedSecret.Name)
157157
return rc.Create(ctx, &expectedSecret)
158158
}
159159
logger.Error(err, "unable to fetch the s3 secret", "secret", secret.Name, "namespace", ramenHubNamespace)
@@ -289,7 +289,7 @@ func createOrUpdateSecretsFromInternalSecret(ctx context.Context, rc client.Clie
289289
logger := log.FromContext(ctx)
290290

291291
if err := common.ValidateInternalSecret(secret, common.InternalLabel); err != nil {
292-
logger.Error(err, "Provided internal secret is not valid", "secret", secret)
292+
logger.Error(err, "Provided internal secret is not valid", "secret", secret.Name)
293293
return err
294294
}
295295

@@ -348,7 +348,7 @@ func processDeletedSecrets(ctx context.Context, rc client.Client, req types.Name
348348
// secrets of same name.
349349
if sourceSecretPointer != nil {
350350
err = errors.New("multiple source secrets detected")
351-
logger.Error(err, "Cannot have more than one source secrets with the same name", "request", req, "source-secret", *sourceSecretPointer)
351+
logger.Error(err, "Cannot have more than one source secrets with the same name", "request", req, "source-secret", sourceSecretPointer.Name)
352352
return err
353353
}
354354
sourceSecretPointer = eachSecret.DeepCopy()
@@ -358,7 +358,7 @@ func processDeletedSecrets(ctx context.Context, rc client.Client, req types.Name
358358
}
359359
}
360360

361-
logger.V(2).Info("List of secrets with requested name", "secret-name", req.Name, "secretlist", sameNamedDestinationSecrets, "#secrets", len(sameNamedDestinationSecrets))
361+
logger.V(2).Info("List of secrets with requested name", "secret-name", req.Name, "secret-length", len(sameNamedDestinationSecrets))
362362

363363
if sourceSecretPointer == nil {
364364
// if there is neither source secret nor any other similarly named secrets,
@@ -372,7 +372,7 @@ func processDeletedSecrets(ctx context.Context, rc client.Client, req types.Name
372372
for _, eachDestSecret := range sameNamedDestinationSecrets {
373373
err = rc.Delete(ctx, &eachDestSecret)
374374
if err != nil {
375-
logger.Error(err, "Deletion failed", "secret", eachDestSecret)
375+
logger.Error(err, "Deletion failed", "secret", eachDestSecret.Name)
376376
anyErr = err
377377
}
378378
}
@@ -388,7 +388,7 @@ func processDeletedSecrets(ctx context.Context, rc client.Client, req types.Name
388388
// and restore the missing destination secret
389389
err = createOrUpdateDestinationSecretsFromSource(ctx, rc, sourceSecretPointer)
390390
if err != nil {
391-
logger.Error(err, "Unable to update the destination secret", "source-secret", sourceSecretPointer)
391+
logger.Error(err, "Unable to update the destination secret", "source-secret", sourceSecretPointer.Name)
392392
return err
393393
}
394394
}

controllers/mirrorpeer_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func processMirrorPeerSecretChanges(ctx context.Context, rc client.Client, mirro
242242
}
243243
err = createOrUpdateDestinationSecretsFromSource(ctx, rc, matchingSourceSecret, mirrorPeerObj)
244244
if err != nil {
245-
logger.Error(err, "Error while updating Destination secrets", "source-secret", *matchingSourceSecret)
245+
logger.Error(err, "Error while updating Destination secrets", "source-secret", matchingSourceSecret.Name)
246246
anyErr = err
247247
}
248248
}

controllers/mirrorpeersecret_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,25 @@ func mirrorPeerSecretReconcile(ctx context.Context, rc client.Client, req ctrl.R
6868
}
6969
if common.IsSecretSource(&peerSecret) {
7070
if err := common.ValidateSourceSecret(&peerSecret); err != nil {
71-
logger.Error(err, "Provided source secret is not valid", "secret", peerSecret)
71+
logger.Error(err, "Provided source secret is not valid", "secret", peerSecret.Name)
7272
return err
7373
}
7474
err = createOrUpdateDestinationSecretsFromSource(ctx, rc, &peerSecret)
7575
if err != nil {
76-
logger.Error(err, "Updating the destination secret failed", "secret", peerSecret)
76+
logger.Error(err, "Updating the destination secret failed", "secret", peerSecret.Name)
7777
return err
7878
}
7979
} else if common.IsSecretDestination(&peerSecret) {
8080
// a destination secret updation happened
8181
err = processDestinationSecretUpdation(ctx, rc, &peerSecret)
8282
if err != nil {
83-
logger.Error(err, "Restoring destination secret failed", "secret", peerSecret)
83+
logger.Error(err, "Restoring destination secret failed", "secret", peerSecret.Name)
8484
return err
8585
}
8686
} else if common.IsSecretInternal(&peerSecret) {
8787
err = createOrUpdateSecretsFromInternalSecret(ctx, rc, &peerSecret, nil)
8888
if err != nil {
89-
logger.Error(err, "Updating the secret from internal secret is failed", "secret", peerSecret)
89+
logger.Error(err, "Updating the secret from internal secret is failed", "secret", peerSecret.Name)
9090
return err
9191
}
9292
}

controllers/named-peerref-with-data.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (nPR *NamedPeerRefWithSecretData) CreateOrUpdateDestinationSecret(ctx conte
113113
err = nPR.GetAssociatedSecret(ctx, rc, &currentDest)
114114
if err != nil {
115115
if k8serrors.IsNotFound(err) {
116-
logger.Info("Creating destination secret", "secret", expectedDest)
116+
logger.Info("Creating destination secret", "secret", expectedDest.Name)
117117
return rc.Create(ctx, expectedDest)
118118
}
119119
logger.Error(err, "Unable to get the destination secret", "destination-ref", nPR.PeerRef)
@@ -122,9 +122,7 @@ func (nPR *NamedPeerRefWithSecretData) CreateOrUpdateDestinationSecret(ctx conte
122122

123123
// recieved a destination secret, now compare
124124
if !reflect.DeepEqual(expectedDest.Data, currentDest.Data) {
125-
logger.Info("Updating the destination secret",
126-
"current-data", currentDest.Data,
127-
"expected-data", expectedDest.Data)
125+
logger.Info("Updating the destination secret", "secret", currentDest.Name)
128126
_, err := controllerutil.CreateOrUpdate(ctx, rc, &currentDest, func() error {
129127
currentDest.Data = expectedDest.Data
130128
return nil

0 commit comments

Comments
 (0)