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 ioutil with os/io packages #2900

Merged
merged 1 commit into from
Nov 2, 2021
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
1 change: 0 additions & 1 deletion api/v1alpha3/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (r *AWSClusterList) ConvertFrom(srcRaw conversion.Hub) error {
return Convert_v1beta1_AWSClusterList_To_v1alpha3_AWSClusterList(src, r, nil)
}


// Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint .
func Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in *clusterv1alpha3.APIEndpoint, out *clusterv1.APIEndpoint, s apiconversion.Scope) error {
return clusterv1alpha3.Convert_v1alpha3_APIEndpoint_To_v1beta1_APIEndpoint(in, out, s)
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha3/awsidentity_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (r *AWSClusterControllerIdentityList) ConvertFrom(srcRaw conversion.Hub) er
return Convert_v1beta1_AWSClusterControllerIdentityList_To_v1alpha3_AWSClusterControllerIdentityList(src, r, nil)
}


// Convert_v1alpha3_AWSClusterStaticIdentitySpec_To_v1beta1_AWSClusterStaticIdentitySpec .
func Convert_v1alpha3_AWSClusterStaticIdentitySpec_To_v1beta1_AWSClusterStaticIdentitySpec(in *AWSClusterStaticIdentitySpec, out *infrav1.AWSClusterStaticIdentitySpec, s apiconversion.Scope) error {
return autoConvert_v1alpha3_AWSClusterStaticIdentitySpec_To_v1beta1_AWSClusterStaticIdentitySpec(in, out, s)
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha3/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (r *AWSMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
return Convert_v1beta1_AWSMachineTemplateList_To_v1alpha3_AWSMachineTemplateList(src, r, nil)
}


// Convert_v1beta1_Volume_To_v1alpha3_Volume .
func Convert_v1beta1_Volume_To_v1alpha3_Volume(in *infrav1.Volume, out *Volume, s apiconversion.Scope) error {
return autoConvert_v1beta1_Volume_To_v1alpha3_Volume(in, out, s)
Expand Down
2 changes: 0 additions & 2 deletions api/v1alpha4/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error {
return Convert_v1beta1_AWSCluster_To_v1alpha4_AWSCluster(src, r, nil)
}


// ConvertTo converts the v1alpha3 AWSCluster receiver to a v1beta1 AWSCluster.
func (r *AWSClusterTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.AWSClusterTemplate)
Expand Down Expand Up @@ -89,7 +88,6 @@ func Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in *clusterv1.APIEndpoi
return clusterv1alpha4.Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in, out, s)
}


// ConvertTo converts the v1alpha4 AWSClusterList receiver to a v1beta1 AWSClusterList.
func (src *AWSClusterList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.AWSClusterList)
Expand Down
13 changes: 6 additions & 7 deletions api/v1alpha4/awsidentity_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (src *AWSClusterControllerIdentity) ConvertTo(dstRaw conversion.Hub) error
}

// ConvertFrom converts the v1beta1 AWSClusterControllerIdentity to a v1alpha4 AWSClusterControllerIdentity.
func (dst *AWSClusterControllerIdentity) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterControllerIdentity) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterControllerIdentity)

return Convert_v1beta1_AWSClusterControllerIdentity_To_v1alpha4_AWSClusterControllerIdentity(src, dst, nil)
Expand All @@ -41,7 +41,7 @@ func (src *AWSClusterControllerIdentityList) ConvertTo(dstRaw conversion.Hub) er
}

// ConvertFrom converts the v1beta1 AWSClusterControllerIdentityList to a v1alpha4 AWSClusterControllerIdentityList.
func (dst *AWSClusterControllerIdentityList) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterControllerIdentityList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterControllerIdentityList)

return Convert_v1beta1_AWSClusterControllerIdentityList_To_v1alpha4_AWSClusterControllerIdentityList(src, dst, nil)
Expand All @@ -54,7 +54,7 @@ func (src *AWSClusterRoleIdentity) ConvertTo(dstRaw conversion.Hub) error {
}

// ConvertFrom converts the v1beta1 AWSClusterRoleIdentity to a v1alpha4 AWSClusterRoleIdentity.
func (dst *AWSClusterRoleIdentity) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterRoleIdentity) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterRoleIdentity)

return Convert_v1beta1_AWSClusterRoleIdentity_To_v1alpha4_AWSClusterRoleIdentity(src, dst, nil)
Expand All @@ -67,21 +67,20 @@ func (src *AWSClusterRoleIdentityList) ConvertTo(dstRaw conversion.Hub) error {
}

// ConvertFrom converts the v1beta1 AWSClusterRoleIdentityList to a v1alpha4 AWSClusterRoleIdentityList.
func (dst *AWSClusterRoleIdentityList) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterRoleIdentityList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterRoleIdentityList)

return Convert_v1beta1_AWSClusterRoleIdentityList_To_v1alpha4_AWSClusterRoleIdentityList(src, dst, nil)
}


// ConvertTo converts the v1alpha4 AWSClusterStaticIdentity receiver to a v1beta1 AWSClusterStaticIdentity.
func (src *AWSClusterStaticIdentity) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.AWSClusterStaticIdentity)
return Convert_v1alpha4_AWSClusterStaticIdentity_To_v1beta1_AWSClusterStaticIdentity(src, dst, nil)
}

// ConvertFrom converts the v1beta1 AWSClusterStaticIdentity to a v1alpha4 AWSClusterStaticIdentity.
func (dst *AWSClusterStaticIdentity) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterStaticIdentity) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterStaticIdentity)

return Convert_v1beta1_AWSClusterStaticIdentity_To_v1alpha4_AWSClusterStaticIdentity(src, dst, nil)
Expand All @@ -94,7 +93,7 @@ func (src *AWSClusterStaticIdentityList) ConvertTo(dstRaw conversion.Hub) error
}

// ConvertFrom converts the v1beta1 AWSClusterStaticIdentityList to a v1alpha4 AWSClusterStaticIdentityList.
func (dst *AWSClusterStaticIdentityList) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSClusterStaticIdentityList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterStaticIdentityList)

return Convert_v1beta1_AWSClusterStaticIdentityList_To_v1alpha4_AWSClusterStaticIdentityList(src, dst, nil)
Expand Down
19 changes: 9 additions & 10 deletions api/v1alpha4/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
}

// ConvertFrom converts the v1beta1 AWSMachine to a v1alpha4 AWSMachine.
func (dst *AWSMachine) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSMachine) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSMachine)

return Convert_v1beta1_AWSMachine_To_v1alpha4_AWSMachine(src, dst, nil)
Expand All @@ -43,7 +43,7 @@ func (src *AWSMachineList) ConvertTo(dstRaw conversion.Hub) error {
}

// ConvertFrom converts the v1beta1 AWSMachineList to a v1alpha4 AWSMachineList.
func (dst *AWSMachineList) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSMachineList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSMachineList)

return Convert_v1beta1_AWSMachineList_To_v1alpha4_AWSMachineList(src, dst, nil)
Expand All @@ -57,13 +57,13 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
return err
}

// Manually restore data.
restored := &infrav1.AWSMachineTemplate{}
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
return err
}
// Manually restore data.
restored := &infrav1.AWSMachineTemplate{}
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
return err
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta

return nil
}
Expand Down Expand Up @@ -91,13 +91,12 @@ func (src *AWSMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
}

// ConvertFrom converts the v1beta1 AWSMachineTemplateList to a v1alpha4 AWSMachineTemplateList.
func (dst *AWSMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error{
func (dst *AWSMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSMachineTemplateList)

return Convert_v1beta1_AWSMachineTemplateList_To_v1alpha4_AWSMachineTemplateList(src, dst, nil)
}


func Convert_v1beta1_AWSMachineTemplateResource_To_v1alpha4_AWSMachineTemplateResource(in *infrav1.AWSMachineTemplateResource, out *AWSMachineTemplateResource, s apiconversion.Scope) error {
return autoConvert_v1beta1_AWSMachineTemplateResource_To_v1alpha4_AWSMachineTemplateResource(in, out, s)
}
8 changes: 4 additions & 4 deletions cmd/clusterawsadm/ami/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ami

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -88,11 +88,11 @@ func latestStableRelease() (string, error) {
return "", err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)

b, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}

latestVersion := strings.TrimSpace(string(b))
tagPrefix := "v"
latestVersionSemVer, err := semver.Make(strings.TrimPrefix(latestVersion, tagPrefix))
Expand All @@ -110,7 +110,7 @@ func latestStableRelease() (string, error) {
return "", err
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterawsadm/cloudformation/bootstrap/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bootstrap

import (
"fmt"
"io/ioutil"
"os"
"path"

"sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/converters"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (t Template) GenerateManagedIAMPolicyDocuments(policyDocDir string) error {
}

fn := path.Join(policyDocDir, fmt.Sprintf("%s.json", pn))
err = ioutil.WriteFile(fn, []byte(pds), 0o600)
err = os.WriteFile(fn, []byte(pds), 0o600)
if err != nil {
return fmt.Errorf("failed to generate policy document for ManagedIAMPolicy %q: %w", pn, err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/clusterawsadm/cloudformation/bootstrap/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package bootstrap

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"

Expand Down Expand Up @@ -171,7 +171,7 @@ func Test_RenderCloudformation(t *testing.T) {

for _, c := range cases {
cfn := cloudformation.Template{}
data, err := ioutil.ReadFile(path.Join("fixtures", c.fixture+".yaml"))
data, err := os.ReadFile(path.Join("fixtures", c.fixture+".yaml"))
if err != nil {
t.Fatal(err)
}
Expand All @@ -184,7 +184,7 @@ func Test_RenderCloudformation(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ioutil.WriteFile("/tmp/tmp1", tData, 0600) // nolint:gosec
os.WriteFile("/tmp/tmp1", tData, 0600)

if string(tData) != string(data) {
dmp := diffmatchpatch.New()
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterawsadm/configreader/configreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package configreader

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand Down Expand Up @@ -66,7 +66,7 @@ type fsLoader struct {

// ReadFile reads a file.
func (fsLoader) ReadFile(filename string) ([]byte, error) {
return ioutil.ReadFile(filepath.Clean(filename))
return os.ReadFile(filepath.Clean(filename))
}

// NewFsLoader returns a Loader that loads a AWSIAMConfiguration from the `config file`.
Expand Down
6 changes: 3 additions & 3 deletions exp/api/v1alpha4/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func TestFuzzyConversion(t *testing.T) {
g.Expect(v1beta1.AddToScheme(scheme)).To(Succeed())

t.Run("for AWSMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1beta1.AWSMachinePool{},
Spoke: &AWSMachinePool{},
Scheme: scheme,
Hub: &v1beta1.AWSMachinePool{},
Spoke: &AWSMachinePool{},
}))

t.Run("for AWSManagedMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Expand Down
6 changes: 3 additions & 3 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ limitations under the License.
package tools

import (
_ "embed"
_ "github.com/a8m/envsubst"
_ "github.com/ahmetb/gen-crd-api-reference-docs"
_ "github.com/golang/mock/mockgen"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/itchyny/gojq/cmd/gojq"
_ "github.com/onsi/ginkgo/ginkgo"
_ "k8s.io/apimachinery/pkg/util/intstr"
_ "k8s.io/code-generator"
_ "k8s.io/code-generator/cmd/conversion-gen"
_ "k8s.io/release/cmd/release-notes"
_ "sigs.k8s.io/cluster-api/hack/tools/mdbook/embed"
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
_ "sigs.k8s.io/kind"
_ "sigs.k8s.io/kustomize/kustomize/v4"
_ "sigs.k8s.io/testing_frameworks/integration"
_ "k8s.io/apimachinery/pkg/util/intstr"
_ "embed"
_ "k8s.io/code-generator/cmd/conversion-gen"
)
5 changes: 2 additions & 3 deletions test/e2e/shared/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
b64 "encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -415,7 +414,7 @@ func DumpCloudTrailEvents(e2eCtx *E2EContext) {
}
logPath := filepath.Join(e2eCtx.Settings.ArtifactFolder, "cloudtrail-events.yaml")
dat, err := yaml.Marshal(events)
if err := ioutil.WriteFile(logPath, dat, 0600); err != nil {
if err := os.WriteFile(logPath, dat, 0600); err != nil {
fmt.Fprintf(GinkgoWriter, "couldn't write cloudtrail events to file: file=%s err=%s", logPath, err)
return
}
Expand Down Expand Up @@ -574,7 +573,7 @@ func dumpEKSCluster(cluster *eks.Cluster, logPath string) {
}
defer f.Close()

if err := ioutil.WriteFile(f.Name(), clusterYAML, 0600); err != nil {
if err := os.WriteFile(f.Name(), clusterYAML, 0600); err != nil {
fmt.Fprintf(GinkgoWriter, "couldn't write cluster yaml to file: name=%s file=%s err=%s", *cluster.Name, f.Name(), err)
return
}
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/shared/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -120,7 +119,7 @@ func commandsForMachine(ctx context.Context, e2eCtx *E2EContext, f *os.File, ins
return
}
result, _, err := e.Expect(shellStart, 20*time.Second)
if err := ioutil.WriteFile(logFile, []byte(result), os.ModePerm); err != nil {
if err := os.WriteFile(logFile, []byte(result), os.ModePerm); err != nil {
fmt.Fprintf(f, "error writing log file: err=%s", err)
return
}
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/shared/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package shared
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -58,7 +57,7 @@ func WriteResourceQuotesToFile(logPath string, serviceQuotas map[string]*Service
data, err := yaml.Marshal(resources)
Expect(err).NotTo(HaveOccurred())

err = ioutil.WriteFile(logPath, data, 0644)
err = os.WriteFile(logPath, data, 0644)
Expect(err).NotTo(HaveOccurred())
}

Expand Down Expand Up @@ -86,7 +85,7 @@ func (r *TestResource) WriteRequestedResources(e2eCtx *E2EContext, testName stri
err := fileLock.Lock()
Expect(err).NotTo(HaveOccurred())

requestedResources, err := ioutil.ReadFile(requestedResourceFilePath)
requestedResources, err := os.ReadFile(requestedResourceFilePath)
Expect(err).NotTo(HaveOccurred())

resources := struct {
Expand All @@ -101,7 +100,7 @@ func (r *TestResource) WriteRequestedResources(e2eCtx *E2EContext, testName stri
resources.TestResourceMap[testName] = *r
str, err := yaml.Marshal(resources)
Expect(err).NotTo(HaveOccurred())
Expect(ioutil.WriteFile(requestedResourceFilePath, str, 0644)).To(Succeed())
Expect(os.WriteFile(requestedResourceFilePath, str, 0644)).To(Succeed())
}

func (r *TestResource) doesSatisfy(request *TestResource) bool {
Expand Down Expand Up @@ -164,7 +163,7 @@ func AcquireResources(request *TestResource, nodeNum int, fileLock *flock.Flock)
if err != nil {
continue
}
resourceText, err := ioutil.ReadFile(ResourceQuotaFilePath)
resourceText, err := os.ReadFile(ResourceQuotaFilePath)
if err != nil {
return err
}
Expand All @@ -180,7 +179,7 @@ func AcquireResources(request *TestResource, nodeNum int, fileLock *flock.Flock)
if err != nil {
return err
}
if err := ioutil.WriteFile(ResourceQuotaFilePath, data, 0644); err != nil {
if err := os.WriteFile(ResourceQuotaFilePath, data, 0644); err != nil {
return err
}
Byf("Node %d acquired resources: %s", nodeNum, request.String())
Expand Down Expand Up @@ -213,7 +212,7 @@ func ReleaseResources(request *TestResource, nodeNum int, fileLock *flock.Flock)
if err := fileLock.Lock(); err != nil {
continue
}
resourceText, err := ioutil.ReadFile(ResourceQuotaFilePath)
resourceText, err := os.ReadFile(ResourceQuotaFilePath)
if err != nil {
return err
}
Expand All @@ -226,7 +225,7 @@ func ReleaseResources(request *TestResource, nodeNum int, fileLock *flock.Flock)
if err != nil {
return err
}
if err := ioutil.WriteFile(ResourceQuotaFilePath, data, 0644); err != nil {
if err := os.WriteFile(ResourceQuotaFilePath, data, 0644); err != nil {
return err
}
Byf("Node %d released resources: %s", nodeNum, request.String())
Expand Down