Skip to content

Commit

Permalink
Upgrade golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Parraga <[email protected]>
  • Loading branch information
Sovietaced committed Jan 3, 2025
1 parent b7e6959 commit b11205f
Show file tree
Hide file tree
Showing 111 changed files with 782 additions and 1,099 deletions.
277 changes: 145 additions & 132 deletions boilerplate/flyte/golang_support_tools/go.mod

Large diffs are not rendered by default.

1,024 changes: 343 additions & 681 deletions boilerplate/flyte/golang_support_tools/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion boilerplate/flyte/golang_test_targets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ generate: download_tooling #generate go code

.PHONY: lint
lint: download_tooling #lints the package for common code smells
GL_DEBUG=linters_output,env golangci-lint run $(LINT_FLAGS) --deadline=5m --exclude deprecated -v
GL_DEBUG=linters_output,env golangci-lint run $(LINT_FLAGS) --timeout=5m --exclude deprecated -v

.PHONY: lint-fix
lint-fix: LINT_FLAGS=--fix
Expand Down
4 changes: 0 additions & 4 deletions boilerplate/flyte/golangci_file/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gas
- gci
- goconst
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
gci:
Expand Down
7 changes: 3 additions & 4 deletions datacatalog/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gas
- gci
- goconst
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
gci:
Expand All @@ -38,6 +34,9 @@ linters-settings:
- default
- prefix(github.com/flyteorg)
skip-generated: true
gosec:
excludes:
- G601 # disable the rule G601 since its not relevant in go 1.22+
issues:
exclude:
- copylocks
6 changes: 3 additions & 3 deletions datacatalog/pkg/manager/impl/validators/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const invalidArgFormat = "invalid value for %s, value:[%s]"
const invalidFilterFormat = "%s cannot be filtered by %s properties"

func NewMissingArgumentError(field string) error {
return errors.NewDataCatalogErrorf(codes.InvalidArgument, fmt.Sprintf(missingFieldFormat, field))
return errors.NewDataCatalogErrorf(codes.InvalidArgument, "%s", fmt.Sprintf(missingFieldFormat, field))
}

func NewInvalidArgumentError(field string, value string) error {
return errors.NewDataCatalogErrorf(codes.InvalidArgument, fmt.Sprintf(invalidArgFormat, field, value))
return errors.NewDataCatalogErrorf(codes.InvalidArgument, "%s", fmt.Sprintf(invalidArgFormat, field, value))
}

func NewInvalidFilterError(entity common.Entity, propertyEntity common.Entity) error {
return errors.NewDataCatalogErrorf(codes.InvalidArgument, fmt.Sprintf(invalidFilterFormat, entity, propertyEntity))
return errors.NewDataCatalogErrorf(codes.InvalidArgument, "%s", fmt.Sprintf(invalidFilterFormat, entity, propertyEntity))
}
2 changes: 1 addition & 1 deletion datacatalog/pkg/repositories/errors/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *postgresErrorTransformer) ToDataCatalogError(err error) error {
case undefinedTable:
return catalogErrors.NewDataCatalogErrorf(codes.InvalidArgument, unsupportedTableOperation, pqError.Message)
default:
return catalogErrors.NewDataCatalogErrorf(codes.Unknown, fmt.Sprintf(defaultPgError, pqError.Code, pqError.Message))
return catalogErrors.NewDataCatalogErrorf(codes.Unknown, "%s", fmt.Sprintf(defaultPgError, pqError.Code, pqError.Message))
}
}

Expand Down
7 changes: 3 additions & 4 deletions flyteadmin/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gas
- gci
- goconst
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
gci:
Expand All @@ -35,6 +31,9 @@ linters-settings:
- default
- prefix(github.com/flyteorg)
skip-generated: true
gosec:
excludes:
- G601 # disable the rule G601 since its not relevant in go 1.22+
issues:
exclude:
- copylocks
3 changes: 2 additions & 1 deletion flyteadmin/auth/authzserver/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func newMockResourceServer(t testing.TB, publicKey rsa.PublicKey) (resourceServe
}

w.Header().Set("Content-Type", "application/json")
_, err = io.WriteString(w, string(raw))

_, err = w.Write(raw)

if !assert.NoError(t, err) {
t.FailNow()
Expand Down
6 changes: 3 additions & 3 deletions flyteadmin/auth/init_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ type SecretsSet struct {
}

func writeSecrets(ctx context.Context, secrets SecretsSet, path string) error {
err := ioutil.WriteFile(filepath.Join(path, config.SecretNameClaimSymmetricKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.TokenHashKey)), os.ModePerm)
err := ioutil.WriteFile(filepath.Join(path, config.SecretNameClaimSymmetricKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.TokenHashKey)), os.ModePerm) // #nosec G306
if err != nil {
return fmt.Errorf("failed to persist token hash key. Error: %w", err)
}

logger.Infof(ctx, "wrote %v", config.SecretNameClaimSymmetricKey)

err = ioutil.WriteFile(filepath.Join(path, config.SecretNameCookieHashKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.CookieHashKey)), os.ModePerm)
err = ioutil.WriteFile(filepath.Join(path, config.SecretNameCookieHashKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.CookieHashKey)), os.ModePerm) // #nosec G306
if err != nil {
return fmt.Errorf("failed to persist cookie hash key. Error: %w", err)
}

logger.Infof(ctx, "wrote %v", config.SecretNameCookieHashKey)

err = ioutil.WriteFile(filepath.Join(path, config.SecretNameCookieBlockKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.CookieBlockKey)), os.ModePerm)
err = ioutil.WriteFile(filepath.Join(path, config.SecretNameCookieBlockKey), []byte(base64.RawStdEncoding.EncodeToString(secrets.CookieBlockKey)), os.ModePerm) // #nosec G306
if err != nil {
return fmt.Errorf("failed to persist cookie block key. Error: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *CloudEventWrappedPublisher) TransformWorkflowExecutionEvent(ctx context
return nil, err
}
var workflowInterface core.TypedInterface
if workflowModel.TypedInterface != nil && len(workflowModel.TypedInterface) > 0 {
if len(workflowModel.TypedInterface) > 0 {
err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface)
if err != nil {
return nil, fmt.Errorf(
Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *CloudEventWrappedPublisher) getLatestTaskExecutions(ctx context.Context
if err != nil {
return nil, err
}
if output.TaskExecutions == nil || len(output.TaskExecutions) == 0 {
if len(output.TaskExecutions) == 0 {
logger.Debugf(ctx, "no task executions found for node exec id [%+v]", nodeExecutionID)
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/async/schedule/aws/workflow_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func generateExecutionName(launchPlan admin.LaunchPlan, kickoffTime time.Time) s
Domain: launchPlan.Id.Domain,
Name: launchPlan.Id.Name,
})
randomSeed := kickoffTime.UnixNano() + int64(hashedIdentifier)
randomSeed := kickoffTime.UnixNano() + int64(hashedIdentifier) // #nosec G115
return common.GetExecutionName(randomSeed)
}

Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/common/flyte_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func ParseFlyteURLToExecution(flyteURL string) (ParsedExecution, error) {
taskExecID := core.TaskExecutionIdentifier{
NodeExecutionId: &nodeExecID,
// checking for overflow here is probably unreasonable
RetryAttempt: uint32(a),
RetryAttempt: uint32(a), // #nosec G115
}
return ParsedExecution{
PartialTaskExecID: &taskExecID,
Expand Down
16 changes: 8 additions & 8 deletions flyteadmin/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewAlreadyInTerminalStateError(ctx context.Context, errorMsg string, curPha
statusErr, transformationErr := NewFlyteAdminError(codes.FailedPrecondition, errorMsg).WithDetails(reason)
if transformationErr != nil {
logger.Panicf(ctx, "Failed to wrap grpc status in type 'Error': %v", transformationErr)
return NewFlyteAdminErrorf(codes.FailedPrecondition, errorMsg)
return NewFlyteAdminErrorf(codes.FailedPrecondition, "%s", errorMsg)
}
return statusErr
}
Expand All @@ -106,7 +106,7 @@ func NewIncompatibleClusterError(ctx context.Context, errorMsg, curCluster strin
})
if transformationErr != nil {
logger.Panicf(ctx, "Failed to wrap grpc status in type 'Error': %v", transformationErr)
return NewFlyteAdminErrorf(codes.FailedPrecondition, errorMsg)
return NewFlyteAdminErrorf(codes.FailedPrecondition, "%s", errorMsg)
}
return statusErr
}
Expand Down Expand Up @@ -135,13 +135,13 @@ func NewTaskExistsDifferentStructureError(ctx context.Context, request *admin.Ta

errorMsg += strings.Join(rs, "\n")

return NewFlyteAdminErrorf(codes.InvalidArgument, errorMsg)
return NewFlyteAdminErrorf(codes.InvalidArgument, "%s", errorMsg)

}

func NewTaskExistsIdenticalStructureError(ctx context.Context, request *admin.TaskCreateRequest) FlyteAdminError {
errorMsg := "task with identical structure already exists"
return NewFlyteAdminErrorf(codes.AlreadyExists, errorMsg)
return NewFlyteAdminErrorf(codes.AlreadyExists, "%s", errorMsg)
}

func NewWorkflowExistsDifferentStructureError(ctx context.Context, request *admin.WorkflowCreateRequest, oldSpec *core.CompiledWorkflowClosure, newSpec *core.CompiledWorkflowClosure) FlyteAdminError {
Expand All @@ -161,7 +161,7 @@ func NewWorkflowExistsDifferentStructureError(ctx context.Context, request *admi
})
if transformationErr != nil {
logger.Errorf(ctx, "Failed to wrap grpc status in type 'Error': %v", transformationErr)
return NewFlyteAdminErrorf(codes.InvalidArgument, errorMsg)
return NewFlyteAdminErrorf(codes.InvalidArgument, "%s", errorMsg)
}
return statusErr
}
Expand All @@ -177,7 +177,7 @@ func NewWorkflowExistsIdenticalStructureError(ctx context.Context, request *admi
})
if transformationErr != nil {
logger.Errorf(ctx, "Failed to wrap grpc status in type 'Error': %v", transformationErr)
return NewFlyteAdminErrorf(codes.AlreadyExists, errorMsg)
return NewFlyteAdminErrorf(codes.AlreadyExists, "%s", errorMsg)
}
return statusErr
}
Expand All @@ -190,12 +190,12 @@ func NewLaunchPlanExistsDifferentStructureError(ctx context.Context, request *ad

errorMsg += strings.Join(rs, "\n")

return NewFlyteAdminErrorf(codes.InvalidArgument, errorMsg)
return NewFlyteAdminErrorf(codes.InvalidArgument, "%s", errorMsg)
}

func NewLaunchPlanExistsIdenticalStructureError(ctx context.Context, request *admin.LaunchPlanCreateRequest) FlyteAdminError {
errorMsg := "launch plan with identical structure already exists"
return NewFlyteAdminErrorf(codes.AlreadyExists, errorMsg)
return NewFlyteAdminErrorf(codes.AlreadyExists, "%s", errorMsg)
}

func IsDoesNotExistError(err error) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getRandSource(seed string) (rand.Source, error) {
if err != nil {
return nil, err
}
hashedSeed := int64(h.Sum64())
hashedSeed := int64(h.Sum64()) // #nosec G115
return rand.NewSource(hashedSeed), nil
}

Expand Down
5 changes: 2 additions & 3 deletions flyteadmin/pkg/manager/impl/launch_plan_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (m *LaunchPlanManager) CreateLaunchPlan(
return nil, err
}
var workflowInterface core.TypedInterface
if workflowModel.TypedInterface != nil && len(workflowModel.TypedInterface) > 0 {
if len(workflowModel.TypedInterface) > 0 {
err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface)
if err != nil {
logger.Errorf(ctx,
Expand Down Expand Up @@ -303,8 +303,7 @@ func (m *LaunchPlanManager) enableLaunchPlan(ctx context.Context, request admin.
}
logger.Debugf(ctx, "No active launch plan model found to disable with project: %s, domain: %s, name: %s",
request.Id.Project, request.Id.Domain, request.Id.Name)
} else if formerlyActiveLaunchPlanModelOutput.LaunchPlans != nil &&
len(formerlyActiveLaunchPlanModelOutput.LaunchPlans) > 0 {
} else if len(formerlyActiveLaunchPlanModelOutput.LaunchPlans) > 0 {
formerlyActiveLaunchPlanModel = &formerlyActiveLaunchPlanModelOutput.LaunchPlans[0]
err = m.updateLaunchPlanModelState(formerlyActiveLaunchPlanModel, admin.LaunchPlanState_INACTIVE)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/manager/impl/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func ValidateDatetime(literal *core.Literal) error {

err := timestamp.CheckValid()
if err != nil {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument, err.Error())
return errors.NewFlyteAdminErrorf(codes.InvalidArgument, "%s", err.Error())
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/repositories/transformers/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func FromWorkflowModel(workflowModel models.Workflow) (admin.Workflow, error) {
if len(workflowModel.TypedInterface) > 0 {
err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface)
if err != nil {
return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, fmt.Sprintf("failed to unmarshal workflow %v interface. Error message: %v", workflowModel.ID, err.Error()))
return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, "%s", fmt.Sprintf("failed to unmarshal workflow %v interface. Error message: %v", workflowModel.ID, err.Error()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/rpc/adminservice/util/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *RequestMetrics) Success() {
func newResponseCodeMetrics(scope promutils.Scope) responseCodeMetrics {
responseCodeCounters := make(map[codes.Code]prometheus.Counter)
for i := 0; i < maxGRPCStatusCode; i++ {
code := codes.Code(i)
code := codes.Code(i) // #nosec G115
responseCodeCounters[code] = scope.MustNewCounter(code.String(),
fmt.Sprintf("count of responses returning: %s", code.String()))
}
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/workflowengine/impl/k8s_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (e K8sWorkflowExecutor) Abort(ctx context.Context, data interfaces.AbortDat
TargetID: data.Cluster,
})
if err != nil {
return errors.NewFlyteAdminErrorf(codes.Internal, err.Error())
return errors.NewFlyteAdminErrorf(codes.Internal, "%s", err.Error())
}
err = target.FlyteClient.FlyteworkflowV1alpha1().FlyteWorkflows(data.Namespace).Delete(ctx, data.ExecutionID.GetName(), v1.DeleteOptions{
PropagationPolicy: &deletePropagationBackground,
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/workflowengine/impl/prepare_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func addExecutionOverrides(taskPluginOverrides []*admin.PluginOverride,

}
if workflowExecutionConfig != nil {
executionConfig.MaxParallelism = uint32(workflowExecutionConfig.MaxParallelism)
executionConfig.MaxParallelism = uint32(workflowExecutionConfig.MaxParallelism) // #nosec G115

if workflowExecutionConfig.GetInterruptible() != nil {
interruptible := workflowExecutionConfig.GetInterruptible().GetValue()
Expand Down
7 changes: 3 additions & 4 deletions flytecopilot/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gas
- gci
- goconst
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

linters-settings:
gci:
Expand All @@ -38,3 +34,6 @@ linters-settings:
- default
- prefix(github.com/flyteorg)
skip-generated: true
gosec:
excludes:
- G601 # disable the rule G601 since its not relevant in go 1.22+
2 changes: 1 addition & 1 deletion flytecopilot/cmd/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestUploadOptions_Upload(t *testing.T) {
}

success := path.Join(tmpDir, SuccessFile)
assert.NoError(t, ioutil.WriteFile(success, []byte("done"), os.ModePerm))
assert.NoError(t, ioutil.WriteFile(success, []byte("done"), os.ModePerm)) // #nosec G306
ok, err := containerwatcher.FileExists(success)
assert.NoError(t, err)
assert.True(t, ok, "sucessfile not created")
Expand Down
Loading

0 comments on commit b11205f

Please sign in to comment.