Skip to content

Commit

Permalink
chore: Lint master (argoproj#5527)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <[email protected]>
  • Loading branch information
simster7 committed Mar 27, 2021
1 parent a443c53 commit eb6f3a1
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 59 deletions.
3 changes: 2 additions & 1 deletion cmd/argo/commands/server_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package commands

import (
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDefaultSecureMode(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/argo/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
func TestLintFile(t *testing.T) {
file, err := ioutil.TempFile("", "*.yaml")
assert.NoError(t, err)
err = ioutil.WriteFile(file.Name(), lintFileData, 0644)
err = ioutil.WriteFile(file.Name(), lintFileData, 0o644)
assert.NoError(t, err)
defer os.Remove(file.Name())

Expand Down Expand Up @@ -97,7 +97,7 @@ func TestLintFile(t *testing.T) {
func TestLintMultipleKinds(t *testing.T) {
file, err := ioutil.TempFile("", "*.yaml")
assert.NoError(t, err)
err = ioutil.WriteFile(file.Name(), lintFileData, 0644)
err = ioutil.WriteFile(file.Name(), lintFileData, 0o644)
assert.NoError(t, err)
defer os.Remove(file.Name())

Expand Down Expand Up @@ -129,7 +129,7 @@ func TestLintMultipleKinds(t *testing.T) {
func TestLintWithOutput(t *testing.T) {
file, err := ioutil.TempFile("", "*.yaml")
assert.NoError(t, err)
err = ioutil.WriteFile(file.Name(), lintFileData, 0644)
err = ioutil.WriteFile(file.Name(), lintFileData, 0o644)
assert.NoError(t, err)
defer os.Remove(file.Name())

Expand Down
8 changes: 4 additions & 4 deletions cmd/argoexec/commands/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func NewEmissaryCommand() *cobra.Command {
exitCode := 64

defer func() {
err := ioutil.WriteFile(varRunArgo+"/ctr/"+containerName+"/exitcode", []byte(strconv.Itoa(exitCode)), 0600)
err := ioutil.WriteFile(varRunArgo+"/ctr/"+containerName+"/exitcode", []byte(strconv.Itoa(exitCode)), 0o600)
if err != nil {
logger.Error(fmt.Errorf("failed to write exit code: %w", err))
}
}()

// this also indicates we've started
if err := os.MkdirAll(varRunArgo+"/ctr/"+containerName, 0700); err != nil {
if err := os.MkdirAll(varRunArgo+"/ctr/"+containerName, 0o700); err != nil {
return fmt.Errorf("failed to create ctr directory: %w", err)
}

Expand Down Expand Up @@ -190,7 +190,7 @@ func saveArtifact(srcPath string) error {
dstPath := varRunArgo + "/outputs/artifacts/" + srcPath + ".tgz"
logger.Infof("%s -> %s", srcPath, dstPath)
z := filepath.Dir(dstPath)
if err := os.MkdirAll(z, 0700); err != nil { // chmod rwx------
if err := os.MkdirAll(z, 0o700); err != nil { // chmod rwx------
return fmt.Errorf("failed to create directory %s: %w", z, err)
}
dst, err := os.Create(dstPath)
Expand Down Expand Up @@ -224,7 +224,7 @@ func saveParameter(srcPath string) error {
dstPath := varRunArgo + "/outputs/parameters/" + srcPath
logger.Infof("%s -> %s", srcPath, dstPath)
z := filepath.Dir(dstPath)
if err := os.MkdirAll(z, 0700); err != nil { // chmod rwx------
if err := os.MkdirAll(z, 0o700); err != nil { // chmod rwx------
return fmt.Errorf("failed to create directory %s: %w", z, err)
}
dst, err := os.Create(dstPath)
Expand Down
8 changes: 4 additions & 4 deletions cmd/argoexec/commands/emissary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestEmissary(t *testing.T) {

x := filepath.Join(wd, "../../../dist/argosay")

err = ioutil.WriteFile(varRunArgo+"/template", []byte(`{}`), 0600)
err = ioutil.WriteFile(varRunArgo+"/template", []byte(`{}`), 0o600)
assert.NoError(t, err)

t.Run("Exit0", func(t *testing.T) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestEmissary(t *testing.T) {
syscall.SIGTERM: "terminated",
syscall.SIGKILL: "killed",
} {
err := ioutil.WriteFile(varRunArgo+"/ctr/main/signal", []byte(strconv.Itoa(int(signal))), 0600)
err := ioutil.WriteFile(varRunArgo+"/ctr/main/signal", []byte(strconv.Itoa(int(signal))), 0o600)
assert.NoError(t, err)
var wg sync.WaitGroup
wg.Add(1)
Expand All @@ -83,7 +83,7 @@ func TestEmissary(t *testing.T) {
]
}
}
`), 0600)
`), 0o600)
assert.NoError(t, err)
err := run(x, []string{"echo", "hello", "/tmp/artifact"})
assert.NoError(t, err)
Expand All @@ -102,7 +102,7 @@ func TestEmissary(t *testing.T) {
]
}
}
`), 0600)
`), 0o600)
assert.NoError(t, err)
err := run(x, []string{"echo", "hello", "/tmp/parameter"})
assert.NoError(t, err)
Expand Down
30 changes: 14 additions & 16 deletions examples/example-golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ import (
wfclientset "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
)

var (
helloWorldWorkflow = wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "hello-world-",
},
Spec: wfv1.WorkflowSpec{
Entrypoint: "whalesay",
Templates: []wfv1.Template{
{
Name: "whalesay",
Container: &corev1.Container{
Image: "docker/whalesay:latest",
Command: []string{"cowsay", "hello world"},
},
var helloWorldWorkflow = wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "hello-world-",
},
Spec: wfv1.WorkflowSpec{
Entrypoint: "whalesay",
Templates: []wfv1.Template{
{
Name: "whalesay",
Container: &corev1.Container{
Image: "docker/whalesay:latest",
Command: []string{"cowsay", "hello world"},
},
},
},
}
)
},
}

func main() {
// get current user to determine home directory
Expand Down
2 changes: 1 addition & 1 deletion examples/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestValidateExamples(t *testing.T) {
t.Errorf("There was an error: %s", err)
}
if len(failures) > 0 {
var fails = []string{}
fails := []string{}
for path, fail := range failures {
fails = append(fails, fmt.Sprintf("Validation failed - %s: %s", path, strings.Join(fail, "\n")))
}
Expand Down
3 changes: 1 addition & 2 deletions examples/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func contains(s []string, e string) bool {
}

func ValidateArgoYamlRecursively(fromPath string, skipFileNames []string) (map[string][]string, error) {

schemaBytes, err := ioutil.ReadFile("../api/jsonschema/schema.json")
if err != nil {
return nil, err
Expand All @@ -36,7 +35,7 @@ func ValidateArgoYamlRecursively(fromPath string, skipFileNames []string) (map[s
return err
}
if contains(skipFileNames, info.Name()) {
//fmt.Printf("skipping %+v \n", info.Name())
// fmt.Printf("skipping %+v \n", info.Name())
return filepath.SkipDir
}
if info.IsDir() {
Expand Down
4 changes: 2 additions & 2 deletions hack/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func cleanCRD(filename string) {
if err != nil {
panic(err)
}
err = ioutil.WriteFile(filename, data, 0666)
err = ioutil.WriteFile(filename, data, 0o666)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func removeCRDValidation(filename string) {
if err != nil {
panic(err)
}
err = ioutil.WriteFile(filename, data, 0666)
err = ioutil.WriteFile(filename, data, 0o666)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (c *DocGeneratorContext) generate() string {
func generateDocs() {
println("generating docs/fields.md")
c := NewDocGeneratorContext()
err := ioutil.WriteFile("docs/fields.md", []byte(c.generate()), 0644)
err := ioutil.WriteFile("docs/fields.md", []byte(c.generate()), 0o644)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/parse_examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func parseExamples() {
file = linkRegex.ReplaceAll(file, []byte(newLink))
file = detailsRegex.ReplaceAll(file, []byte(newDetails))

err = ioutil.WriteFile("site/fields/index.html", file, 0644)
err = ioutil.WriteFile("site/fields/index.html", file, 0o644)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/swagger/secondaryswaggergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func secondarySwaggerGen() {
panic(err)
}
newContents := strings.ReplaceAll(string(read), "argo-workflows", "argo_workflows")
err = ioutil.WriteFile("pkg/apiclient/_.secondary.swagger.json", []byte(newContents), 0666)
err = ioutil.WriteFile("pkg/apiclient/_.secondary.swagger.json", []byte(newContents), 0o666)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/artifacts/artifact_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type fakeArtifactDriver struct {
}

func (a *fakeArtifactDriver) Load(_ *wfv1.Artifact, path string) error {
return ioutil.WriteFile(path, a.data, 0666)
return ioutil.WriteFile(path, a.data, 0o666)
}

func (a *fakeArtifactDriver) Save(_ string, _ *wfv1.Artifact) error {
Expand Down
2 changes: 1 addition & 1 deletion server/auth/serviceaccount/claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestClaimSetFor(t *testing.T) {
// set-up test
tmp, err := ioutil.TempFile("", "")
assert.NoError(t, err)
err = ioutil.WriteFile(tmp.Name(), []byte(token), 0644)
err = ioutil.WriteFile(tmp.Name(), []byte(token), 0o644)
assert.NoError(t, err)
defer func() { _ = os.Remove(tmp.Name()) }()

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ func (s *CLISuite) TestWorkflowLint() {
data, err := ioutil.ReadFile("smoke/basic.yaml")
s.CheckError(err)
// Write data to dst
err = ioutil.WriteFile(filepath.Join(tmp, "my-workflow.yaml"), data, 0644)
err = ioutil.WriteFile(filepath.Join(tmp, "my-workflow.yaml"), data, 0o644)
s.CheckError(err)
s.Given().
RunCli([]string{"lint", tmp}, func(t *testing.T, output string, err error) {
Expand Down
2 changes: 1 addition & 1 deletion util/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func tempFile(dir, prefix, suffix string) (*os.File, error) {
if dir == "" {
dir = os.TempDir()
} else {
err := os.MkdirAll(dir, 0700)
err := os.MkdirAll(dir, 0o700)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion util/file/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestExistsInTar(t *testing.T) {
var buf bytes.Buffer
writer := tar.NewWriter(&buf)
for _, f := range files {
mode := os.FileMode(0600)
mode := os.FileMode(0o600)
if f.isDir {
mode |= os.ModeDir
}
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GetSecrets(ctx context.Context, clientSet kubernetes.Interface, namespace,

// Write the Terminate message in pod spec
func WriteTeriminateMessage(message string) {
err := ioutil.WriteFile("/dev/termination-log", []byte(message), 0644)
err := ioutil.WriteFile("/dev/termination-log", []byte(message), 0o644)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/artifacts/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func downloadObject(client *storage.Client, bucket, key, objName, path string) e
localPath := filepath.Join(path, relObjPath)
objectDir, _ := filepath.Split(localPath)
if objectDir != "" {
if err := os.MkdirAll(objectDir, 0700); err != nil {
if err := os.MkdirAll(objectDir, 0o700); err != nil {
return fmt.Errorf("mkdir %s: %v", objectDir, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions workflow/artifacts/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g *ArtifactDriver) auth() (func(), transport.AuthMethod, []string, error)
if err != nil {
return nil, nil, nil, err
}
err = ioutil.WriteFile(privateKeyFile.Name(), []byte(g.SSHPrivateKey), 0600)
err = ioutil.WriteFile(privateKeyFile.Name(), []byte(g.SSHPrivateKey), 0o600)
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -77,7 +77,7 @@ case "$1" in
Username*) echo "${GIT_USERNAME}" ;;
Password*) echo "${GIT_PASSWORD}" ;;
esac
`), 0755)
`), 0o755)
if err != nil {
return nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/artifacts/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGitArtifactDriver_Load(t *testing.T) {
driver := &ArtifactDriver{}
path := "/tmp/git-found"
assert.NoError(t, os.RemoveAll(path))
assert.NoError(t, os.MkdirAll(path, 0777))
assert.NoError(t, os.MkdirAll(path, 0o777))
err := driver.Load(&wfv1.Artifact{
ArtifactLocation: wfv1.ArtifactLocation{
Git: &wfv1.GitArtifact{
Expand Down
4 changes: 2 additions & 2 deletions workflow/artifacts/hdfs/hdfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (driver *ArtifactDriver) Load(_ *wfv1.Artifact, path string) error {
dirPath := filepath.Dir(driver.Path)
if dirPath != "." && dirPath != "/" {
// Follow umask for the permission
err = os.MkdirAll(dirPath, 0777)
err = os.MkdirAll(dirPath, 0o777)
if err != nil {
return err
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func (driver *ArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) e
dirPath := filepath.Dir(driver.Path)
if dirPath != "." && dirPath != "/" {
// Follow umask for the permission
err = hdfscli.MkdirAll(dirPath, 0777)
err = hdfscli.MkdirAll(dirPath, 0o777)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func CopyArchive(ctx context.Context, c KubernetesClientInterface, containerName
if err != nil {
return err
}
f, err := os.OpenFile(destPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
f, err := os.OpenFile(destPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o666)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/emissary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func copyBinary() error {
return err
}
defer func() { _ = in.Close() }()
out, err := os.OpenFile("/var/run/argo/argoexec", os.O_RDWR|os.O_CREATE, 0500) // r-x------
out, err := os.OpenFile("/var/run/argo/argoexec", os.O_RDWR|os.O_CREATE, 0o500) // r-x------
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions workflow/executor/emissary/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (e emissary) writeTemplate(t wfv1.Template) error {
if err != nil {
return err
}
return ioutil.WriteFile("/var/run/argo/template", data, 0400) // chmod -r--------
return ioutil.WriteFile("/var/run/argo/template", data, 0o400) // chmod -r--------
}

func (e emissary) GetFileContents(_ string, sourcePath string) (string, error) {
Expand Down Expand Up @@ -137,7 +137,7 @@ func (e emissary) isComplete(containerNames []string) bool {

func (e emissary) Kill(ctx context.Context, containerNames []string, terminationGracePeriodDuration time.Duration) error {
for _, containerName := range containerNames {
if err := ioutil.WriteFile("/var/run/argo/ctr/"+containerName+"/signal", []byte(strconv.Itoa(int(syscall.SIGTERM))), 0600); err != nil {
if err := ioutil.WriteFile("/var/run/argo/ctr/"+containerName+"/signal", []byte(strconv.Itoa(int(syscall.SIGTERM))), 0o600); err != nil {
return err
}
}
Expand All @@ -148,7 +148,7 @@ func (e emissary) Kill(ctx context.Context, containerNames []string, termination
return err
}
for _, containerName := range containerNames {
if err := ioutil.WriteFile("/var/run/argo/ctr/"+containerName+"/signal", []byte(strconv.Itoa(int(syscall.SIGKILL))), 0600); err != nil {
if err := ioutil.WriteFile("/var/run/argo/ctr/"+containerName+"/signal", []byte(strconv.Itoa(int(syscall.SIGKILL))), 0o600); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (we *WorkflowExecutor) StageFiles() error {
default:
return nil
}
err := ioutil.WriteFile(filePath, body, 0644)
err := ioutil.WriteFile(filePath, body, 0o644)
if err != nil {
return errors.InternalWrapError(err)
}
Expand Down
Loading

0 comments on commit eb6f3a1

Please sign in to comment.