Skip to content

Commit

Permalink
Refactor: Avoid conversion to []byte by using WriteString (istio#46565)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Aug 18, 2023
1 parent 220eebf commit 1fd3aac
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion istioctl/pkg/multicluster/remote_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func writeToTempFile(content string) (string, error) {
}
defer func() { _ = outFile.Close() }()

if _, err := outFile.Write([]byte(content)); err != nil {
if _, err := outFile.WriteString(content); err != nil {
return "", fmt.Errorf("failed writing manifest file: %v", err)
}
return outFile.Name(), nil
Expand Down
2 changes: 1 addition & 1 deletion istioctl/pkg/tag/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func writeToTempFile(content string) (string, error) {
}
defer func() { _ = outFile.Close() }()

if _, err := outFile.Write([]byte(content)); err != nil {
if _, err := outFile.WriteString(content); err != nil {
return "", fmt.Errorf("failed writing manifest file: %w", err)
}
return outFile.Name(), nil
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/object/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (os K8sObjects) YAMLManifest() (string, error) {
if _, err := b.Write(ym); err != nil {
return "", err
}
if _, err := b.Write([]byte(YAMLSeparator)); err != nil {
if _, err := b.WriteString(YAMLSeparator); err != nil {
return "", err
}

Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/gateway/deploymentcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestConfigureIstioGateway(t *testing.T) {
return err
}
buf.Write(b)
buf.Write([]byte("---\n"))
buf.WriteString("---\n")
return nil
}
client.RunAndWait(stop)
Expand Down
2 changes: 1 addition & 1 deletion pkg/bootstrap/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestGolden(t *testing.T) {
}
defer os.Remove(annoFile.Name())
for k, v := range c.annotations {
annoFile.Write([]byte(fmt.Sprintf("%s=%q\n", k, v)))
annoFile.WriteString(fmt.Sprintf("%s=%q\n", k, v))
}

node, err := GetNodeMetaData(MetadataOptions{
Expand Down
4 changes: 2 additions & 2 deletions pkg/collateral/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ _complete istio 2>/dev/null
defer func() { _ = outFile.Close() }()

// Concatenate the head, initialization, generated bash, and tail to the file
if _, err = outFile.Write([]byte(zshInitialization)); err != nil {
if _, err = outFile.WriteString(zshInitialization); err != nil {
return fmt.Errorf("unable to output zsh initialization: %v", err)
}
if err = root.GenBashCompletion(outFile); err != nil {
return fmt.Errorf("unable to output zsh completion file: %v", err)
}
if _, err = outFile.Write([]byte(zshTail)); err != nil {
if _, err = outFile.WriteString(zshTail); err != nil {
return fmt.Errorf("unable to output zsh tail: %v", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/framework/components/echo/kube/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,15 +707,15 @@ func customizeVMEnvironment(ctx resource.Context, cfg echo.Config, clusterEnv st
if cfg.VMEnvironment != nil {
for k, v := range cfg.VMEnvironment {
addition := fmt.Sprintf("%s=%s\n", k, v)
_, err = f.Write([]byte(addition))
_, err = f.WriteString(addition)
if err != nil {
return fmt.Errorf("failed writing %q to %s: %v", addition, clusterEnv, err)
}
}
}
if !ctx.Environment().(*kube.Environment).Settings().LoadBalancerSupported {
// customize cluster.env with NodePort mapping
_, err = f.Write([]byte(fmt.Sprintf("ISTIO_PILOT_PORT=%d\n", istiodAddr.Port())))
_, err = f.WriteString(fmt.Sprintf("ISTIO_PILOT_PORT=%d\n", istiodAddr.Port()))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion security/pkg/nodeagent/caclient/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func writeToTempFile(content, fileNamePrefix string) (string, error) {
}
defer func() { _ = outFile.Close() }()

if _, err := outFile.Write([]byte(content)); err != nil {
if _, err := outFile.WriteString(content); err != nil {
return "", fmt.Errorf("failed writing to the temp file: %v", err)
}
return outFile.Name(), nil
Expand Down

0 comments on commit 1fd3aac

Please sign in to comment.