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

replace bytes.Compare() with bytes.Equal() #83071

Merged
merged 1 commit into from
Sep 27, 2019
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 cluster/images/etcd/migrate/migrate_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (e *CombinedEtcdClient) AttachLease(leaseDuration time.Duration) error {
if err != nil {
klog.Errorf("Error while attaching lease to: %s", string(kv.Key))
}
if bytes.Compare(putResp.PrevKv.Value, kv.Value) != 0 {
if !bytes.Equal(putResp.PrevKv.Value, kv.Value) {
return fmt.Errorf("concurrent access to key detected when setting lease on %s, expected previous value of %s but got %s",
kv.Key, kv.Value, putResp.PrevKv.Value)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/serviceaccount/tokens_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (e *TokensController) hasReferencedToken(serviceAccount *v1.ServiceAccount)

func (e *TokensController) secretUpdateNeeded(secret *v1.Secret) (bool, bool, bool) {
caData := secret.Data[v1.ServiceAccountRootCAKey]
needsCA := len(e.rootCA) > 0 && bytes.Compare(caData, e.rootCA) != 0
needsCA := len(e.rootCA) > 0 && !bytes.Equal(caData, e.rootCA)

needsNamespace := len(secret.Data[v1.ServiceAccountNamespaceKey]) == 0

Expand Down
2 changes: 1 addition & 1 deletion pkg/serviceaccount/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (v *legacyValidator) Validate(tokenData string, public *jwt.Claims, private
klog.V(4).Infof("Token is deleted and awaiting removal: %s/%s for service account %s/%s", namespace, secretName, namespace, serviceAccountName)
return nil, errors.New("Token has been invalidated")
}
if bytes.Compare(secret.Data[v1.ServiceAccountTokenKey], []byte(tokenData)) != 0 {
if !bytes.Equal(secret.Data[v1.ServiceAccountTokenKey], []byte(tokenData)) {
klog.V(4).Infof("Token contents no longer matches %s/%s for service account %s/%s", namespace, secretName, namespace, serviceAccountName)
return nil, errors.New("Token does not match server's copy")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/util/atomic_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func shouldWriteFile(path string, content []byte) (bool, error) {
return false, err
}

return (bytes.Compare(content, contentOnFs) != 0), nil
return !bytes.Equal(content, contentOnFs), nil
}

// pathsToRemove walks the current version of the data directory and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestEncryptionProviderConfigCorrect(t *testing.T) {
if stale != (transformer.Name != testCase.Name) {
t.Fatalf("%s: wrong stale information on reading using %s transformer, should be %v", testCase.Name, transformer.Name, testCase.Name == transformer.Name)
}
if bytes.Compare(untransformedData, originalText) != 0 {
if !bytes.Equal(untransformedData, originalText) {
t.Fatalf("%s: %s transformer transformed data incorrectly. Expected: %v, got %v", testCase.Name, transformer.Name, originalText, untransformedData)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestEnvelopeCaching(t *testing.T) {
if err != nil {
t.Fatalf("could not decrypt Envelope transformer's encrypted data even once: %v", err)
}
if bytes.Compare(untransformedData, originalText) != 0 {
if !bytes.Equal(untransformedData, originalText) {
t.Fatalf("envelopeTransformer transformed data incorrectly. Expected: %v, got %v", originalText, untransformedData)
}

Expand All @@ -104,7 +104,7 @@ func TestEnvelopeCaching(t *testing.T) {
if err != nil {
t.Fatalf("could not decrypt Envelope transformer's encrypted data using just cache: %v", err)
}
if bytes.Compare(untransformedData, originalText) != 0 {
if !bytes.Equal(untransformedData, originalText) {
t.Fatalf("envelopeTransformer transformed data incorrectly using cache. Expected: %v, got %v", originalText, untransformedData)
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestEnvelopeCacheLimit(t *testing.T) {
t.Fatalf("envelopeTransformer: error while transforming data (%v) from storage: %s", transformedOutputs[i], err)
}

if bytes.Compare(numberText, output) != 0 {
if !bytes.Equal(numberText, output) {
t.Fatalf("envelopeTransformer transformed data incorrectly using cache. Expected: %v, got %v", numberText, output)
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestBackwardsCompatibility(t *testing.T) {
if err != nil {
t.Fatalf("could not decrypt Envelope transformer's encrypted data even once: %v", err)
}
if bytes.Compare(untransformedData, originalText) != 0 {
if !bytes.Equal(untransformedData, originalText) {
t.Fatalf("envelopeTransformer transformed data incorrectly. Expected: %v, got %v", originalText, untransformedData)
}

Expand All @@ -231,7 +231,7 @@ func TestBackwardsCompatibility(t *testing.T) {
if err != nil {
t.Fatalf("could not decrypt Envelope transformer's encrypted data using just cache: %v", err)
}
if bytes.Compare(untransformedData, originalText) != 0 {
if !bytes.Equal(untransformedData, originalText) {
t.Fatalf("envelopeTransformer transformed data incorrectly using cache. Expected: %v, got %v", originalText, untransformedData)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (le *LeaderElector) tryAcquireOrRenew() bool {
}

// 2. Record obtained, check the Identity & Time
if bytes.Compare(le.observedRawRecord, oldLeaderElectionRawRecord) != 0 {
if !bytes.Equal(le.observedRawRecord, oldLeaderElectionRawRecord) {
le.observedRecord = *oldLeaderElectionRecord
le.observedRawRecord = oldLeaderElectionRawRecord
le.observedTime = le.clock.Now()
Expand Down