diff --git a/.golangci.yaml b/.golangci.yaml index 0e5f1707e0..38783894c5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -98,6 +98,9 @@ linters: - pkg: errors alias: stderrors + - pkg: github.com/argoproj/argo-cd/v3/util/io + alias: utilio + nolintlint: require-specific: true diff --git a/applicationset/services/repo_service.go b/applicationset/services/repo_service.go index 5a8241677f..dd218f3092 100644 --- a/applicationset/services/repo_service.go +++ b/applicationset/services/repo_service.go @@ -7,7 +7,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/reposerver/apiclient" "github.com/argoproj/argo-cd/v3/util/db" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) type argoCDService struct { @@ -36,7 +36,7 @@ func NewArgoCDService(db db.ArgoDB, submoduleEnabled bool, repoClientset apiclie if err != nil { return nil, fmt.Errorf("error initializing new repo server client: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) return client.GetGitFiles(ctx, fileRequest) }, getGitDirectoriesFromRepoServer: func(ctx context.Context, dirRequest *apiclient.GitDirectoriesRequest) (*apiclient.GitDirectoriesResponse, error) { @@ -44,7 +44,7 @@ func NewArgoCDService(db db.ArgoDB, submoduleEnabled bool, repoClientset apiclie if err != nil { return nil, fmt.Errorf("error initialising new repo server client: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) return client.GetGitDirectories(ctx, dirRequest) }, } diff --git a/cmd/argocd-commit-server/commands/argocd_commit_server.go b/cmd/argocd-commit-server/commands/argocd_commit_server.go index ae33f41e7f..7feed03381 100644 --- a/cmd/argocd-commit-server/commands/argocd_commit_server.go +++ b/cmd/argocd-commit-server/commands/argocd_commit_server.go @@ -23,7 +23,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/env" "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/healthz" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // NewCommand returns a new instance of an argocd-commit-server command @@ -71,7 +71,7 @@ func NewCommand() *cobra.Command { if err != nil { return err } - defer ioutil.Close(conn) + defer utilio.Close(conn) client := grpc_health_v1.NewHealthClient(conn) res, err := client.Check(r.Context(), &grpc_health_v1.HealthCheckRequest{}) if err != nil { diff --git a/cmd/argocd-git-ask-pass/commands/argocd_git_ask_pass.go b/cmd/argocd-git-ask-pass/commands/argocd_git_ask_pass.go index 48909b3aa3..b4780e2515 100644 --- a/cmd/argocd-git-ask-pass/commands/argocd_git_ask_pass.go +++ b/cmd/argocd-git-ask-pass/commands/argocd_git_ask_pass.go @@ -12,7 +12,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/askpass" "github.com/argoproj/argo-cd/v3/util/errors" grpc_util "github.com/argoproj/argo-cd/v3/util/grpc" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) const ( @@ -37,7 +37,7 @@ func NewCommand() *cobra.Command { } conn, err := grpc_util.BlockingDial(ctx, "unix", askpass.SocketPath, nil, grpc.WithTransportCredentials(insecure.NewCredentials())) errors.CheckError(err) - defer io.Close(conn) + defer utilio.Close(conn) client := askpass.NewAskPassServiceClient(conn) creds, err := client.GetCredentials(ctx, &askpass.CredentialsRequest{Nonce: nonce}) diff --git a/cmd/argocd-repo-server/commands/argocd_repo_server.go b/cmd/argocd-repo-server/commands/argocd_repo_server.go index 91ac0e2113..fd8e0bd0be 100644 --- a/cmd/argocd-repo-server/commands/argocd_repo_server.go +++ b/cmd/argocd-repo-server/commands/argocd_repo_server.go @@ -33,7 +33,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/gpg" "github.com/argoproj/argo-cd/v3/util/healthz" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/tls" traceutil "github.com/argoproj/argo-cd/v3/util/trace" ) @@ -172,7 +172,7 @@ func NewCommand() *cobra.Command { if err != nil { return err } - defer ioutil.Close(conn) + defer utilio.Close(conn) client := grpc_health_v1.NewHealthClient(conn) res, err := client.Check(r.Context(), &grpc_health_v1.HealthCheckRequest{}) if err != nil { diff --git a/cmd/argocd/commands/account.go b/cmd/argocd/commands/account.go index 236c8e0c2c..d4b4a14c50 100644 --- a/cmd/argocd/commands/account.go +++ b/cmd/argocd/commands/account.go @@ -25,7 +25,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apiclient/session" "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/localconfig" sessionutil "github.com/argoproj/argo-cd/v3/util/session" "github.com/argoproj/argo-cd/v3/util/templates" @@ -94,7 +94,7 @@ has appropriate RBAC permissions to change other accounts. } acdClient := headless.NewClientOrDie(clientOpts, c) conn, usrIf := acdClient.NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) userInfo := getCurrentAccount(ctx, acdClient) @@ -173,7 +173,7 @@ func NewAccountGetUserInfoCommand(clientOpts *argocdclient.ClientOptions) *cobra } conn, client := headless.NewClientOrDie(clientOpts, c).NewSessionClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) response, err := client.GetUserInfo(ctx, &session.GetUserInfoRequest{}) errors.CheckError(err) @@ -229,7 +229,7 @@ Resources: %v } conn, client := headless.NewClientOrDie(clientOpts, c).NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) response, err := client.CanI(ctx, &accountpkg.CanIRequest{ Action: args[0], @@ -267,7 +267,7 @@ func NewAccountListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman ctx := c.Context() conn, client := headless.NewClientOrDie(clientOpts, c).NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) response, err := client.ListAccounts(ctx, &accountpkg.ListAccountRequest{}) @@ -291,7 +291,7 @@ func NewAccountListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman func getCurrentAccount(ctx context.Context, clientset argocdclient.Client) session.GetUserInfoResponse { conn, client := clientset.NewSessionClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) userInfo, err := client.GetUserInfo(ctx, &session.GetUserInfoRequest{}) errors.CheckError(err) return *userInfo @@ -320,7 +320,7 @@ argocd account get --account `, } conn, client := clientset.NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) acc, err := client.GetAccount(ctx, &accountpkg.GetAccountRequest{Name: account}) @@ -388,7 +388,7 @@ argocd account generate-token --account `, clientset := headless.NewClientOrDie(clientOpts, c) conn, client := clientset.NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) if account == "" { account = getCurrentAccount(ctx, clientset).Username } @@ -430,7 +430,7 @@ argocd account delete-token --account ID`, clientset := headless.NewClientOrDie(clientOpts, c) conn, client := clientset.NewAccountClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) if account == "" { account = getCurrentAccount(ctx, clientset).Username } diff --git a/cmd/argocd/commands/admin/app.go b/cmd/argocd/commands/admin/app.go index ac51bf539b..e457ad1733 100644 --- a/cmd/argocd/commands/admin/app.go +++ b/cmd/argocd/commands/admin/app.go @@ -41,7 +41,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/config" "github.com/argoproj/argo-cd/v3/util/db" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" kubeutil "github.com/argoproj/argo-cd/v3/util/kube" "github.com/argoproj/argo-cd/v3/util/settings" ) @@ -121,7 +121,7 @@ func NewGenAppSpecCommand() *cobra.Command { } out, closer, err := getOutWriter(inline, fileURL) errors.CheckError(err) - defer io.Close(closer) + defer utilio.Close(closer) errors.CheckError(PrintResources(outputFormat, out, app)) }, diff --git a/cmd/argocd/commands/admin/generatespec_utils.go b/cmd/argocd/commands/admin/generatespec_utils.go index 414a57d508..71b2883a98 100644 --- a/cmd/argocd/commands/admin/generatespec_utils.go +++ b/cmd/argocd/commands/admin/generatespec_utils.go @@ -11,12 +11,12 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func getOutWriter(inline bool, filePath string) (io.Writer, io.Closer, error) { if !inline { - return os.Stdout, ioutil.NopCloser, nil + return os.Stdout, utilio.NopCloser, nil } if filePath == "" { diff --git a/cmd/argocd/commands/admin/generatespec_utils_test.go b/cmd/argocd/commands/admin/generatespec_utils_test.go index 4097afe0aa..5598f89018 100644 --- a/cmd/argocd/commands/admin/generatespec_utils_test.go +++ b/cmd/argocd/commands/admin/generatespec_utils_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,7 +16,7 @@ import ( func TestGetOutWriter_InlineOff(t *testing.T) { out, closer, err := getOutWriter(false, "") require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) assert.Equal(t, os.Stdout, out) } @@ -29,7 +29,7 @@ func TestGetOutWriter_InlineOn(t *testing.T) { out, closer, err := getOutWriter(true, tmpFile) require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) assert.Equal(t, tmpFile, out.(*os.File).Name()) _, err = os.Stat(tmpFile + ".back") diff --git a/cmd/argocd/commands/admin/project.go b/cmd/argocd/commands/admin/project.go index aeb6e5e222..9381ed4ad2 100644 --- a/cmd/argocd/commands/admin/project.go +++ b/cmd/argocd/commands/admin/project.go @@ -14,7 +14,7 @@ import ( appclient "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned/typed/application/v1alpha1" "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/templates" "github.com/argoproj/gitops-engine/pkg/utils/kube" @@ -66,7 +66,7 @@ func NewGenProjectSpecCommand() *cobra.Command { out, closer, err := getOutWriter(inline, fileURL) errors.CheckError(err) - defer io.Close(closer) + defer utilio.Close(closer) errors.CheckError(PrintResources(outputFormat, out, proj)) }, diff --git a/cmd/argocd/commands/admin/settings_test.go b/cmd/argocd/commands/admin/settings_test.go index 19362a8128..7418d61cb6 100644 --- a/cmd/argocd/commands/admin/settings_test.go +++ b/cmd/argocd/commands/admin/settings_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/argoproj/argo-cd/v3/common" - utils "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/settings" "github.com/stretchr/testify/assert" @@ -31,7 +31,7 @@ func captureStdout(callback func()) (string, error) { }() callback() - utils.Close(w) + utilio.Close(w) data, err := io.ReadAll(r) if err != nil { @@ -94,7 +94,7 @@ metadata: data: url: https://myargocd.com`) require.NoError(t, err) - defer utils.Close(closer) + defer utilio.Close(closer) opts := settingsOpts{argocdCMPath: f} settingsManager, err := opts.createSettingsManager(ctx) @@ -243,7 +243,7 @@ func tempFile(content string) (string, io.Closer, error) { panic(err) } }() - return f.Name(), utils.NewCloser(func() error { + return f.Name(), utilio.NewCloser(func() error { return os.Remove(f.Name()) }), nil } @@ -264,7 +264,7 @@ func TestValidateSettingsCommand_NoErrors(t *testing.T) { func TestResourceOverrideIgnoreDifferences(t *testing.T) { f, closer, err := tempFile(testDeploymentYAML) require.NoError(t, err) - defer utils.Close(closer) + defer utilio.Close(closer) t.Run("NoOverridesConfigured", func(t *testing.T) { cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{})) @@ -297,7 +297,7 @@ func TestResourceOverrideIgnoreDifferences(t *testing.T) { func TestResourceOverrideHealth(t *testing.T) { f, closer, err := tempFile(testCustomResourceYAML) require.NoError(t, err) - defer utils.Close(closer) + defer utilio.Close(closer) t.Run("NoHealthAssessment", func(t *testing.T) { cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{ @@ -348,11 +348,11 @@ func TestResourceOverrideHealth(t *testing.T) { func TestResourceOverrideAction(t *testing.T) { f, closer, err := tempFile(testDeploymentYAML) require.NoError(t, err) - defer utils.Close(closer) + defer utilio.Close(closer) cronJobFile, closer, err := tempFile(testCronJobYAML) require.NoError(t, err) - defer utils.Close(closer) + defer utilio.Close(closer) t.Run("NoActions", func(t *testing.T) { cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{ diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 94071f1566..ed24152a62 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -55,7 +55,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/git" "github.com/argoproj/argo-cd/v3/util/grpc" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" logutils "github.com/argoproj/argo-cd/v3/util/log" "github.com/argoproj/argo-cd/v3/util/manifeststream" "github.com/argoproj/argo-cd/v3/util/templates" @@ -170,7 +170,7 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra. app.Finalizers = append(app.Finalizers, "resources-finalizer.argocd.argoproj.io") } conn, appIf := argocdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appCreateRequest := application.ApplicationCreateRequest{ Application: app, Upsert: &upsert, @@ -392,7 +392,7 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com } acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) @@ -468,7 +468,7 @@ func NewApplicationGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com } pConn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(pConn) + defer utilio.Close(pConn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: app.Spec.Project}) errors.CheckError(err) @@ -586,7 +586,7 @@ func NewApplicationLogsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co } acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], "") retry := true @@ -776,7 +776,7 @@ func appURLDefault(acdClient argocdclient.Client, appName string) string { // getAppURL returns the URL of an application func getAppURL(ctx context.Context, acdClient argocdclient.Client, appName string) string { conn, settingsIf := acdClient.NewSettingsClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) argoSettings, err := settingsIf.Get(ctx, &settings.SettingsQuery{}) errors.CheckError(err) @@ -877,7 +877,7 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) argocdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := argocdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appIf.Get(ctx, &application.ApplicationQuery{Name: &appName, AppNamespace: &appNs}) errors.CheckError(err) @@ -992,7 +992,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appIf.Get(ctx, &application.ApplicationQuery{Name: &appName, AppNamespace: &appNs}) errors.CheckError(err) @@ -1314,7 +1314,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co clientset := headless.NewClientOrDie(clientOpts, c) conn, appIf := clientset.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) app, err := appIf.Get(ctx, &application.ApplicationQuery{ Name: &appName, @@ -1338,7 +1338,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co resources, err := appIf.ManagedResources(ctx, &application.ResourcesQuery{ApplicationName: &appName, AppNamespace: &appNs}) errors.CheckError(err) conn, settingsIf := clientset.NewSettingsClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) argoSettings, err := settingsIf.Get(ctx, &settings.SettingsQuery{}) errors.CheckError(err) diffOption := &DifferenceOption{} @@ -1388,7 +1388,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co } else { fmt.Fprintf(os.Stderr, "Warning: local diff without --server-side-generate is deprecated and does not work with plugins. Server-side generation will be the default in v2.7.") conn, clusterIf := clientset.NewClusterClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) cluster, err := clusterIf.Get(ctx, &clusterpkg.ClusterQuery{Name: app.Spec.Destination.Name, Server: app.Spec.Destination.Server}) errors.CheckError(err) @@ -1589,7 +1589,7 @@ func NewApplicationDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra. } acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) isTerminal := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) promptFlag := c.Flag("yes") if promptFlag.Changed && promptFlag.Value.String() == "true" { @@ -1726,7 +1726,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co ctx := c.Context() conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) apps, err := appIf.List(ctx, &application.ApplicationQuery{ Selector: ptr.To(selector), AppNamespace: &appNamespace, @@ -1923,7 +1923,7 @@ func NewApplicationWaitCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co appNames := args acdClient := headless.NewClientOrDie(clientOpts, c) closer, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(closer) + defer utilio.Close(closer) if selector != "" { list, err := appIf.List(ctx, &application.ApplicationQuery{Selector: ptr.To(selector)}) errors.CheckError(err) @@ -2082,7 +2082,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) selectedLabels, err := label.Parse(labels) errors.CheckError(err) @@ -2212,13 +2212,13 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co conn, settingsIf := acdClient.NewSettingsClientOrDie() argoSettings, err := settingsIf.Get(ctx, &settings.SettingsQuery{}) errors.CheckError(err) - argoio.Close(conn) + utilio.Close(conn) conn, clusterIf := acdClient.NewClusterClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) cluster, err := clusterIf.Get(ctx, &clusterpkg.ClusterQuery{Name: app.Spec.Destination.Name, Server: app.Spec.Destination.Server}) errors.CheckError(err) - argoio.Close(conn) + utilio.Close(conn) proj := getProject(ctx, c, clientOpts, app.Spec.Project) localObjsStrings = getLocalObjectsString(ctx, app, proj.Project, local, localRepoRoot, argoSettings.AppLabelKey, cluster.Info.ServerVersion, cluster.Info.APIVersions, argoSettings.KustomizeOptions, argoSettings.TrackingMethod) @@ -2290,7 +2290,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co }) errors.CheckError(err) conn, settingsIf := acdClient.NewSettingsClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) argoSettings, err := settingsIf.Get(ctx, &settings.SettingsQuery{}) errors.CheckError(err) foundDiffs := false @@ -2692,7 +2692,7 @@ func waitOnApplicationStatus(ctx context.Context, acdClient argocdclient.Client, prevStates := make(map[string]*resourceState) conn, appClient := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appClient.Get(ctx, &application.ApplicationQuery{ Name: &appRealName, AppNamespace: &appNs, @@ -2901,7 +2901,7 @@ func NewApplicationHistoryCommand(clientOpts *argocdclient.ClientOptions) *cobra os.Exit(1) } conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) app, err := appIf.Get(ctx, &application.ApplicationQuery{ Name: &appName, @@ -2964,7 +2964,7 @@ func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobr } acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appIf.Get(ctx, &application.ApplicationQuery{ Name: &appName, AppNamespace: &appNs, @@ -3083,7 +3083,7 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob appName, appNs := argo.ParseFromQualifiedName(args[0], "") clientset := headless.NewClientOrDie(clientOpts, c) conn, appIf := clientset.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appIf.Get(context.Background(), &application.ApplicationQuery{ Name: &appName, @@ -3115,12 +3115,12 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob switch { case local != "": settingsConn, settingsIf := clientset.NewSettingsClientOrDie() - defer argoio.Close(settingsConn) + defer utilio.Close(settingsConn) argoSettings, err := settingsIf.Get(context.Background(), &settings.SettingsQuery{}) errors.CheckError(err) clusterConn, clusterIf := clientset.NewClusterClientOrDie() - defer argoio.Close(clusterConn) + defer utilio.Close(clusterConn) cluster, err := clusterIf.Get(context.Background(), &clusterpkg.ClusterQuery{Name: app.Spec.Destination.Name, Server: app.Spec.Destination.Server}) errors.CheckError(err) @@ -3202,7 +3202,7 @@ func NewApplicationTerminateOpCommand(clientOpts *argocdclient.ClientOptions) *c } appName, appNs := argo.ParseFromQualifiedName(args[0], "") conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) _, err := appIf.TerminateOperation(ctx, &application.OperationTerminateRequest{ Name: &appName, AppNamespace: &appNs, @@ -3229,7 +3229,7 @@ func NewApplicationEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) app, err := appIf.Get(ctx, &application.ApplicationQuery{ Name: &appName, AppNamespace: &appNs, @@ -3299,7 +3299,7 @@ func NewApplicationPatchCommand(clientOpts *argocdclient.ClientOptions) *cobra.C } appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) patchedApp, err := appIf.Patch(ctx, &application.ApplicationPatchRequest{ Name: &appName, @@ -3341,7 +3341,7 @@ func NewApplicationAddSourceCommand(clientOpts *argocdclient.ClientOptions) *cob argocdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := argocdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) @@ -3414,7 +3414,7 @@ func NewApplicationRemoveSourceCommand(clientOpts *argocdclient.ClientOptions) * argocdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := argocdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) @@ -3489,7 +3489,7 @@ func NewApplicationConfirmDeletionCommand(clientOpts *argocdclient.ClientOptions argocdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := argocdClient.NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appName, appNs := argo.ParseFromQualifiedName(args[0], appNamespace) diff --git a/cmd/argocd/commands/app_actions.go b/cmd/argocd/commands/app_actions.go index 8c0d266b4a..b445011bae 100644 --- a/cmd/argocd/commands/app_actions.go +++ b/cmd/argocd/commands/app_actions.go @@ -24,7 +24,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/util/argo" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) type DisplayedAction struct { @@ -83,7 +83,7 @@ func NewApplicationResourceActionsListCommand(clientOpts *argocdclient.ClientOpt } appName, appNs := argo.ParseFromQualifiedName(args[0], "") conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) resources, err := getActionableResourcesForApplication(ctx, appIf, &appNs, &appName) errors.CheckError(err) filteredObjects, err := util.FilterResources(command.Flags().Changed("group"), resources, group, kind, namespace, resourceName, true) @@ -175,7 +175,7 @@ func NewApplicationResourceActionsRunCommand(clientOpts *argocdclient.ClientOpti actionName := args[1] conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) resources, err := getActionableResourcesForApplication(ctx, appIf, &appNs, &appName) errors.CheckError(err) filteredObjects, err := util.FilterResources(command.Flags().Changed("group"), resources, group, kind, namespace, resourceName, all) diff --git a/cmd/argocd/commands/app_resources.go b/cmd/argocd/commands/app_resources.go index d1b6e103d2..f2a6cd4a32 100644 --- a/cmd/argocd/commands/app_resources.go +++ b/cmd/argocd/commands/app_resources.go @@ -19,7 +19,7 @@ import ( applicationpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/application" "github.com/argoproj/argo-cd/v3/util/argo" "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { @@ -58,7 +58,7 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions) appName, appNs := argo.ParseFromQualifiedName(args[0], "") conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) resources, err := appIf.ManagedResources(ctx, &applicationpkg.ResourcesQuery{ ApplicationName: &appName, AppNamespace: &appNs, @@ -123,7 +123,7 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions) appName, appNs := argo.ParseFromQualifiedName(args[0], "") conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) resources, err := appIf.ManagedResources(ctx, &applicationpkg.ResourcesQuery{ ApplicationName: &appName, AppNamespace: &appNs, @@ -272,7 +272,7 @@ func NewApplicationListResourcesCommand(clientOpts *argocdclient.ClientOptions) listAll := !c.Flag("orphaned").Changed appName, appNs := argo.ParseFromQualifiedName(args[0], "") conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appResourceTree, err := appIf.ResourceTree(ctx, &applicationpkg.ResourcesQuery{ ApplicationName: &appName, AppNamespace: &appNs, diff --git a/cmd/argocd/commands/applicationset.go b/cmd/argocd/commands/applicationset.go index fc8b787140..97ce8c5d8e 100644 --- a/cmd/argocd/commands/applicationset.go +++ b/cmd/argocd/commands/applicationset.go @@ -21,7 +21,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/argo" "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/grpc" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/templates" ) @@ -80,7 +80,7 @@ func NewApplicationSetGetCommand(clientOpts *argocdclient.ClientOptions) *cobra. } acdClient := headless.NewClientOrDie(clientOpts, c) conn, appIf := acdClient.NewApplicationSetClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appSetName, appSetNs := argo.ParseFromQualifiedName(args[0], "") @@ -150,7 +150,7 @@ func NewApplicationSetCreateCommand(clientOpts *argocdclient.ClientOptions) *cob } conn, appIf := argocdClient.NewApplicationSetClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) // Get app before creating to see if it is being updated or no change existing, err := appIf.Get(ctx, &applicationset.ApplicationSetGetQuery{Name: appset.Name, AppsetNamespace: appset.Namespace}) @@ -241,7 +241,7 @@ func NewApplicationSetGenerateCommand(clientOpts *argocdclient.ClientOptions) *c } conn, appIf := argocdClient.NewApplicationSetClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) req := applicationset.ApplicationSetGenerateRequest{ ApplicationSet: appset, @@ -296,7 +296,7 @@ func NewApplicationSetListCommand(clientOpts *argocdclient.ClientOptions) *cobra ctx := c.Context() conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationSetClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) appsets, err := appIf.List(ctx, &applicationset.ApplicationSetListQuery{Selector: selector, Projects: projects, AppsetNamespace: appSetNamespace}) errors.CheckError(err) @@ -341,7 +341,7 @@ func NewApplicationSetDeleteCommand(clientOpts *argocdclient.ClientOptions) *cob os.Exit(1) } conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationSetClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) isTerminal := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()) numOfApps := len(args) promptFlag := c.Flag("yes") diff --git a/cmd/argocd/commands/cert.go b/cmd/argocd/commands/cert.go index b7c19fa89c..3cd9b3b21c 100644 --- a/cmd/argocd/commands/cert.go +++ b/cmd/argocd/commands/cert.go @@ -18,7 +18,7 @@ import ( appsv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" certutil "github.com/argoproj/argo-cd/v3/util/cert" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // NewCertCommand returns a new instance of an `argocd repo` command @@ -69,7 +69,7 @@ func NewCertAddTLSCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command ctx := c.Context() conn, certIf := headless.NewClientOrDie(clientOpts, c).NewCertClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) if len(args) != 1 { c.HelpFunc()(c, args) @@ -152,7 +152,7 @@ func NewCertAddSSHCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command ctx := c.Context() conn, certIf := headless.NewClientOrDie(clientOpts, c).NewCertClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) var sshKnownHostsLists []string var err error @@ -226,7 +226,7 @@ func NewCertRemoveCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command os.Exit(1) } conn, certIf := headless.NewClientOrDie(clientOpts, c).NewCertClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) hostNamePattern := args[0] // Prevent the user from specifying a wildcard as hostname as precaution @@ -289,7 +289,7 @@ func NewCertListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { } conn, certIf := headless.NewClientOrDie(clientOpts, c).NewCertClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) certificates, err := certIf.ListCertificates(ctx, &certificatepkg.RepositoryCertificateQuery{HostNamePattern: hostNamePattern, CertType: certType}) errors.CheckError(err) diff --git a/cmd/argocd/commands/cluster.go b/cmd/argocd/commands/cluster.go index 6dc7016d26..e41a8f8e6d 100644 --- a/cmd/argocd/commands/cluster.go +++ b/cmd/argocd/commands/cluster.go @@ -27,7 +27,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/clusterauth" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/text/label" ) @@ -162,7 +162,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie errors.CheckError(err) conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) if clusterOpts.Name != "" { contextName = clusterOpts.Name } @@ -254,7 +254,7 @@ func NewClusterSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command // name of the cluster whose fields have to be updated. clusterName = args[0] conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) // checks the fields that needs to be updated updatedFields := checkFieldsToUpdate(clusterOptions, labels, annotations) namespaces := clusterOptions.Namespaces @@ -336,7 +336,7 @@ argocd cluster get in-cluster`, os.Exit(1) } conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) clusters := make([]argoappv1.Cluster, 0) for _, clusterSelector := range args { clst, err := clusterIf.Get(ctx, getQueryBySelector(clusterSelector)) @@ -412,7 +412,7 @@ argocd cluster rm cluster-name`, os.Exit(1) } conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) numOfClusters := len(args) var isConfirmAll bool @@ -510,7 +510,7 @@ func NewClusterListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman ctx := c.Context() conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) clusters, err := clusterIf.List(ctx, &clusterpkg.ClusterQuery{}) errors.CheckError(err) switch output { @@ -562,7 +562,7 @@ argocd cluster rotate-auth cluster-name`, os.Exit(1) } conn, clusterIf := headless.NewClientOrDie(clientOpts, c).NewClusterClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) cluster := args[0] clusterQuery := getQueryBySelector(cluster) diff --git a/cmd/argocd/commands/gpg.go b/cmd/argocd/commands/gpg.go index 27ef839d1e..3150c5cfe8 100644 --- a/cmd/argocd/commands/gpg.go +++ b/cmd/argocd/commands/gpg.go @@ -15,7 +15,7 @@ import ( gpgkeypkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/gpgkey" appsv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/templates" ) @@ -58,7 +58,7 @@ func NewGPGListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { ctx := c.Context() conn, gpgIf := headless.NewClientOrDie(clientOpts, c).NewGPGKeyClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) keys, err := gpgIf.List(ctx, &gpgkeypkg.GnuPGPublicKeyQuery{}) errors.CheckError(err) switch output { @@ -100,7 +100,7 @@ func NewGPGGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { errors.Fatal(errors.ErrorGeneric, "Missing KEYID argument") } conn, gpgIf := headless.NewClientOrDie(clientOpts, c).NewGPGKeyClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) key, err := gpgIf.Get(ctx, &gpgkeypkg.GnuPGPublicKeyQuery{KeyID: args[0]}) errors.CheckError(err) switch output { @@ -144,7 +144,7 @@ func NewGPGAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { errors.CheckError(err) } conn, gpgIf := headless.NewClientOrDie(clientOpts, c).NewGPGKeyClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) resp, err := gpgIf.Create(ctx, &gpgkeypkg.GnuPGPublicKeyCreateRequest{Publickey: &appsv1.GnuPGPublicKey{KeyData: string(keyData)}}) errors.CheckError(err) fmt.Printf("Created %d key(s) from input file", len(resp.Created.Items)) @@ -173,7 +173,7 @@ func NewGPGDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command keyId := args[0] conn, gpgIf := headless.NewClientOrDie(clientOpts, c).NewGPGKeyClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) canDelete := promptUtil.Confirm(fmt.Sprintf("Are you sure you want to remove '%s'? [y/n] ", keyId)) diff --git a/cmd/argocd/commands/headless/headless.go b/cmd/argocd/commands/headless/headless.go index ed90c0fab7..07630b406f 100644 --- a/cmd/argocd/commands/headless/headless.go +++ b/cmd/argocd/commands/headless/headless.go @@ -36,7 +36,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/cache" appstatecache "github.com/argoproj/argo-cd/v3/util/cache/appstate" "github.com/argoproj/argo-cd/v3/util/cli" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" kubeutil "github.com/argoproj/argo-cd/v3/util/kube" "github.com/argoproj/argo-cd/v3/util/localconfig" ) @@ -122,7 +122,7 @@ type forwardRepoClientset struct { kubeClientset kubernetes.Interface } -func (c *forwardRepoClientset) NewRepoServerClient() (io.Closer, repoapiclient.RepoServerServiceClient, error) { +func (c *forwardRepoClientset) NewRepoServerClient() (utilio.Closer, repoapiclient.RepoServerServiceClient, error) { c.init.Do(func() { overrides := clientcmd.ConfigOverrides{ CurrentContext: c.context, @@ -164,7 +164,7 @@ func testAPI(ctx context.Context, clientOpts *apiclient.ClientOptions) error { if err != nil { return fmt.Errorf("failed to create version client: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) _, err = versionClient.Version(ctx, &empty.Empty{}) if err != nil { return fmt.Errorf("failed to get version: %w", err) @@ -218,7 +218,7 @@ func MaybeStartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOpti return fmt.Errorf("failed to listen on %q: %w", addr, err) } port = &ln.Addr().(*net.TCPAddr).Port - io.Close(ln) + utilio.Close(ln) } restConfig, err := clientConfig.ClientConfig() diff --git a/cmd/argocd/commands/login.go b/cmd/argocd/commands/login.go index fff0bba2d0..07854f2aaf 100644 --- a/cmd/argocd/commands/login.go +++ b/cmd/argocd/commands/login.go @@ -27,7 +27,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/errors" grpc_util "github.com/argoproj/argo-cd/v3/util/grpc" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/localconfig" oidcutil "github.com/argoproj/argo-cd/v3/util/oidc" "github.com/argoproj/argo-cd/v3/util/rand" @@ -126,7 +126,7 @@ argocd login cd.argoproj.io --core`, if !globalClientOpts.Core { acdClient := headless.NewClientOrDie(&clientOpts, c) setConn, setIf := acdClient.NewSettingsClientOrDie() - defer io.Close(setConn) + defer utilio.Close(setConn) if !sso { tokenString = passwordLogin(ctx, acdClient, username, password) } else { @@ -360,7 +360,7 @@ func oauth2Login( func passwordLogin(ctx context.Context, acdClient argocdclient.Client, username, password string) string { username, password = cli.PromptCredentials(username, password) sessConn, sessionIf := acdClient.NewSessionClientOrDie() - defer io.Close(sessConn) + defer utilio.Close(sessConn) sessionRequest := sessionpkg.SessionCreateRequest{ Username: username, Password: password, diff --git a/cmd/argocd/commands/login_test.go b/cmd/argocd/commands/login_test.go index b5d6af48f8..43cbf1febf 100644 --- a/cmd/argocd/commands/login_test.go +++ b/cmd/argocd/commands/login_test.go @@ -6,7 +6,7 @@ import ( "testing" claimsutil "github.com/argoproj/argo-cd/v3/util/claims" - utils "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" @@ -27,7 +27,7 @@ func captureStdout(callback func()) (string, error) { }() callback() - utils.Close(w) + utilio.Close(w) data, err := io.ReadAll(r) if err != nil { diff --git a/cmd/argocd/commands/project.go b/cmd/argocd/commands/project.go index 3366e2ffcd..3477d3eecb 100644 --- a/cmd/argocd/commands/project.go +++ b/cmd/argocd/commands/project.go @@ -27,7 +27,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/git" "github.com/argoproj/argo-cd/v3/util/gpg" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/templates" ) @@ -122,7 +122,7 @@ func NewProjectCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comm errors.CheckError(err) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) _, err = projIf.Create(ctx, &projectpkg.ProjectCreateRequest{Project: proj, Upsert: upsert}) errors.CheckError(err) }, @@ -159,7 +159,7 @@ func NewProjectSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command } projName := args[0] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -202,7 +202,7 @@ func NewProjectAddSignatureKeyCommand(clientOpts *argocdclient.ClientOptions) *c } conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -240,7 +240,7 @@ func NewProjectRemoveSignatureKeyCommand(clientOpts *argocdclient.ClientOptions) signatureKey := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -296,7 +296,7 @@ func NewProjectAddDestinationCommand(clientOpts *argocdclient.ClientOptions) *co namespace := args[2] destination := buildApplicationDestination(args[1], namespace, nameInsteadServer) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -337,7 +337,7 @@ func NewProjectRemoveDestinationCommand(clientOpts *argocdclient.ClientOptions) server := args[1] namespace := args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -385,7 +385,7 @@ func NewProjectAddOrphanedIgnoreCommand(clientOpts *argocdclient.ClientOptions) group := args[1] kind := args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -435,7 +435,7 @@ func NewProjectRemoveOrphanedIgnoreCommand(clientOpts *argocdclient.ClientOption group := args[1] kind := args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -483,7 +483,7 @@ func NewProjectAddSourceCommand(clientOpts *argocdclient.ClientOptions) *cobra.C projName := args[0] url := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -525,7 +525,7 @@ func NewProjectAddSourceNamespace(clientOpts *argocdclient.ClientOptions) *cobra projName := args[0] srcNamespace := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -563,7 +563,7 @@ func NewProjectRemoveSourceNamespace(clientOpts *argocdclient.ClientOptions) *co projName := args[0] srcNamespace := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -639,7 +639,7 @@ func modifyResourceListCmd(cmdUse, cmdDesc, examples string, clientOpts *argocdc } projName, group, kind := args[0], args[1], args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -737,7 +737,7 @@ func NewProjectRemoveSourceCommand(clientOpts *argocdclient.ClientOptions) *cobr projName := args[0] url := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -782,7 +782,7 @@ func NewProjectDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comm promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) for _, name := range args { canDelete := promptUtil.Confirm(fmt.Sprintf("Are you sure you want to delete %s? [y/n]", name)) if canDelete { @@ -831,7 +831,7 @@ func NewProjectListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman ctx := c.Context() conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) projects, err := projIf.List(ctx, &projectpkg.ProjectQuery{}) errors.CheckError(err) switch output { @@ -1042,7 +1042,7 @@ func NewProjectGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command func getProject(ctx context.Context, c *cobra.Command, clientOpts *argocdclient.ClientOptions, projName string) *projectpkg.DetailedProjectsResponse { conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) detailedProject, err := projIf.GetDetailedProject(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) return detailedProject @@ -1065,7 +1065,7 @@ func NewProjectEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman } projName := args[0] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) projData, err := json.Marshal(proj.Spec) @@ -1150,7 +1150,7 @@ func NewProjectAddDestinationServiceAccountCommand(clientOpts *argocdclient.Clie destinationServiceAccount := buildApplicationDestinationServiceAccount(server, namespace, serviceAccount, serviceAccountNamespace) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -1192,7 +1192,7 @@ func NewProjectRemoveDestinationServiceAccountCommand(clientOpts *argocdclient.C namespace := args[2] serviceAccount := args[3] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) diff --git a/cmd/argocd/commands/project_role.go b/cmd/argocd/commands/project_role.go index 2bf1779f48..f8715c3c38 100644 --- a/cmd/argocd/commands/project_role.go +++ b/cmd/argocd/commands/project_role.go @@ -18,7 +18,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" claimsutil "github.com/argoproj/argo-cd/v3/util/claims" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/jwt" "github.com/argoproj/argo-cd/v3/util/templates" ) @@ -91,7 +91,7 @@ ID ISSUED-AT EXPIRES-AT projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -150,7 +150,7 @@ ID ISSUED-AT EXPIRES-AT projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -207,7 +207,7 @@ func NewProjectRoleCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra. projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -244,7 +244,7 @@ func NewProjectRoleDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra. projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) @@ -308,7 +308,7 @@ Create token succeeded for proj:test-project:test-role. projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) if expiresIn == "" { expiresIn = "0s" } @@ -383,7 +383,7 @@ fa9d3517-c52d-434c-9bff-215b38508842 2023-10-08T11:08:18+01:00 Never roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -466,7 +466,7 @@ $ argocd proj role delete-token test-project test-role 1696769937 promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) canDelete := promptUtil.Confirm(fmt.Sprintf("Are you sure you want to delete '%s' project token? [y/n]", tokenId)) if canDelete { @@ -521,7 +521,7 @@ func NewProjectRoleListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co } projName := args[0] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) project, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -567,7 +567,7 @@ ID ISSUED-AT EXPIRES-AT projName := args[0] roleName := args[1] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -611,7 +611,7 @@ func NewProjectRoleAddGroupCommand(clientOpts *argocdclient.ClientOptions) *cobr } projName, roleName, groupName := args[0], args[1], args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) updated, err := proj.AddGroupToRole(roleName, groupName) @@ -642,7 +642,7 @@ func NewProjectRoleRemoveGroupCommand(clientOpts *argocdclient.ClientOptions) *c } projName, roleName, groupName := args[0], args[1], args[2] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) updated, err := proj.RemoveGroupFromRole(roleName, groupName) diff --git a/cmd/argocd/commands/projectwindows.go b/cmd/argocd/commands/projectwindows.go index efc8b27567..239b9e2c85 100644 --- a/cmd/argocd/commands/projectwindows.go +++ b/cmd/argocd/commands/projectwindows.go @@ -15,7 +15,7 @@ import ( projectpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/project" "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // NewProjectWindowsCommand returns a new instance of the `argocd proj windows` command @@ -74,7 +74,7 @@ argocd proj windows disable-manual-sync default 0`, errors.CheckError(err) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -120,7 +120,7 @@ argocd proj windows enable-manual-sync my-app-project --message "Manual sync ini errors.CheckError(err) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -184,7 +184,7 @@ argocd proj windows add PROJECT \ } projName := args[0] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -234,7 +234,7 @@ argocd proj windows delete new-project 1`, errors.CheckError(err) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -287,7 +287,7 @@ argocd proj windows update PROJECT ID \ errors.CheckError(err) conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) @@ -339,7 +339,7 @@ argocd proj windows list test-project`, } projName := args[0] conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName}) errors.CheckError(err) diff --git a/cmd/argocd/commands/relogin.go b/cmd/argocd/commands/relogin.go index 9d847ebc87..5eec14a581 100644 --- a/cmd/argocd/commands/relogin.go +++ b/cmd/argocd/commands/relogin.go @@ -12,7 +12,7 @@ import ( argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient" settingspkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/settings" "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/localconfig" "github.com/argoproj/argo-cd/v3/util/session" ) @@ -65,7 +65,7 @@ func NewReloginCommand(globalClientOpts *argocdclient.ClientOptions) *cobra.Comm } else { fmt.Println("Reinitiating SSO login") setConn, setIf := acdClient.NewSettingsClientOrDie() - defer argoio.Close(setConn) + defer utilio.Close(setConn) httpClient, err := acdClient.HTTPClient() errors.CheckError(err) ctx = oidc.ClientContext(ctx, httpClient) diff --git a/cmd/argocd/commands/repo.go b/cmd/argocd/commands/repo.go index d726e9fdd1..3619cc1b62 100644 --- a/cmd/argocd/commands/repo.go +++ b/cmd/argocd/commands/repo.go @@ -19,7 +19,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/git" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // NewRepoCommand returns a new instance of an `argocd repo` command @@ -188,7 +188,7 @@ func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { } conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) // If the user set a username, but didn't supply password via --password, // then we prompt for it @@ -264,7 +264,7 @@ func NewRepoRemoveCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command os.Exit(1) } conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) for _, repoURL := range args { @@ -320,7 +320,7 @@ func NewRepoListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { ctx := c.Context() conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) forceRefresh := false switch refresh { case "": @@ -372,7 +372,7 @@ func NewRepoGetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { // Repository URL repoURL := args[0] conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) forceRefresh := false switch refresh { case "": diff --git a/cmd/argocd/commands/repocreds.go b/cmd/argocd/commands/repocreds.go index e62ad98aeb..213a7c7d8d 100644 --- a/cmd/argocd/commands/repocreds.go +++ b/cmd/argocd/commands/repocreds.go @@ -19,7 +19,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/cli" "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/git" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/templates" ) @@ -159,7 +159,7 @@ func NewRepoCredsAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comma } conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoCredsClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) // If the user set a username, but didn't supply password via --password, // then we prompt for it @@ -221,7 +221,7 @@ func NewRepoCredsRemoveCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co os.Exit(1) } conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoCredsClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) @@ -283,7 +283,7 @@ func NewRepoCredsListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comm ctx := c.Context() conn, repoIf := headless.NewClientOrDie(clientOpts, c).NewRepoCredsClientOrDie() - defer io.Close(conn) + defer utilio.Close(conn) repos, err := repoIf.ListRepositoryCredentials(ctx, &repocredspkg.RepoCredsQuery{}) errors.CheckError(err) switch output { diff --git a/cmd/argocd/commands/version.go b/cmd/argocd/commands/version.go index 6c59f76aad..47766d0240 100644 --- a/cmd/argocd/commands/version.go +++ b/cmd/argocd/commands/version.go @@ -13,7 +13,7 @@ import ( argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient" "github.com/argoproj/argo-cd/v3/pkg/apiclient/version" "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // NewVersionCmd returns a new `version` command to be used as a sub-command to root @@ -94,7 +94,7 @@ func NewVersionCmd(clientOpts *argocdclient.ClientOptions, serverVersion *versio func getServerVersion(ctx context.Context, options *argocdclient.ClientOptions, c *cobra.Command) *version.VersionMessage { conn, versionIf := headless.NewClientOrDie(options, c).NewVersionClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) v, err := versionIf.Version(ctx, &empty.Empty{}) errors.CheckError(err) diff --git a/cmpserver/apiclient/clientset.go b/cmpserver/apiclient/clientset.go index b79e19cfe0..fb751850e6 100644 --- a/cmpserver/apiclient/clientset.go +++ b/cmpserver/apiclient/clientset.go @@ -14,7 +14,7 @@ import ( "google.golang.org/grpc/credentials/insecure" grpc_util "github.com/argoproj/argo-cd/v3/util/grpc" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // MaxGRPCMessageSize contains max grpc message size @@ -22,14 +22,14 @@ var MaxGRPCMessageSize = env.ParseNumFromEnv(common.EnvGRPCMaxSizeMB, 100, 0, ma // Clientset represents config management plugin server api clients type Clientset interface { - NewConfigManagementPluginClient() (io.Closer, ConfigManagementPluginServiceClient, error) + NewConfigManagementPluginClient() (utilio.Closer, ConfigManagementPluginServiceClient, error) } type clientSet struct { address string } -func (c *clientSet) NewConfigManagementPluginClient() (io.Closer, ConfigManagementPluginServiceClient, error) { +func (c *clientSet) NewConfigManagementPluginClient() (utilio.Closer, ConfigManagementPluginServiceClient, error) { conn, err := NewConnection(c.address) if err != nil { return nil, nil, err diff --git a/commitserver/apiclient/clientset.go b/commitserver/apiclient/clientset.go index 7148ef88c9..0726c86434 100644 --- a/commitserver/apiclient/clientset.go +++ b/commitserver/apiclient/clientset.go @@ -7,12 +7,12 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // Clientset represents commit server api clients type Clientset interface { - NewCommitServerClient() (io.Closer, CommitServiceClient, error) + NewCommitServerClient() (utilio.Closer, CommitServiceClient, error) } type clientSet struct { @@ -20,7 +20,7 @@ type clientSet struct { } // NewCommitServerClient creates new instance of commit server client -func (c *clientSet) NewCommitServerClient() (io.Closer, CommitServiceClient, error) { +func (c *clientSet) NewCommitServerClient() (utilio.Closer, CommitServiceClient, error) { conn, err := NewConnection(c.address) if err != nil { return nil, nil, fmt.Errorf("failed to open a new connection to commit server: %w", err) diff --git a/controller/hydrator/hydrator.go b/controller/hydrator/hydrator.go index b919bc6fd9..023fb360f4 100644 --- a/controller/hydrator/hydrator.go +++ b/controller/hydrator/hydrator.go @@ -14,7 +14,7 @@ import ( appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/reposerver/apiclient" applog "github.com/argoproj/argo-cd/v3/util/app/log" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // Dependencies is the interface for the dependencies of the Hydrator. It serves two purposes: 1) it prevents the @@ -320,7 +320,7 @@ func (h *Hydrator) hydrate(logCtx *log.Entry, apps []*appv1.Application) (string if err != nil { return targetRevision, "", fmt.Errorf("failed to create commit service: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) resp, err := commitService.CommitHydratedManifests(context.Background(), &manifestsRequest) if err != nil { return targetRevision, "", fmt.Errorf("failed to commit hydrated manifests: %w", err) diff --git a/controller/state.go b/controller/state.go index bdbe5dc0bd..b0a63d1b81 100644 --- a/controller/state.go +++ b/controller/state.go @@ -42,7 +42,7 @@ import ( appstatecache "github.com/argoproj/argo-cd/v3/util/cache/appstate" "github.com/argoproj/argo-cd/v3/util/db" "github.com/argoproj/argo-cd/v3/util/gpg" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/settings" "github.com/argoproj/argo-cd/v3/util/stats" ) @@ -192,7 +192,7 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp if err != nil { return nil, nil, false, fmt.Errorf("failed to connect to repo server: %w", err) } - defer io.Close(conn) + defer utilio.Close(conn) manifestInfos := make([]*apiclient.ManifestResponse, 0) targetObjs := make([]*unstructured.Unstructured, 0) @@ -337,7 +337,7 @@ func (m *appStateManager) ResolveGitRevision(repoURL string, revision string) (s if err != nil { return "", fmt.Errorf("failed to connect to repo server: %w", err) } - defer io.Close(conn) + defer utilio.Close(conn) repo, err := m.db.GetRepository(context.Background(), repoURL, "") if err != nil { diff --git a/pkg/apiclient/apiclient.go b/pkg/apiclient/apiclient.go index c1af2c6a7b..12c1d92d4f 100644 --- a/pkg/apiclient/apiclient.go +++ b/pkg/apiclient/apiclient.go @@ -48,7 +48,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/env" grpc_util "github.com/argoproj/argo-cd/v3/util/grpc" http_util "github.com/argoproj/argo-cd/v3/util/http" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/kube" "github.com/argoproj/argo-cd/v3/util/localconfig" oidcutil "github.com/argoproj/argo-cd/v3/util/oidc" @@ -287,13 +287,13 @@ func NewClient(opts *ClientOptions) (Client, error) { // if a call to grpc failed, then try again with GRPCWeb conn, versionIf, err := c.NewVersionClient() if err == nil { - defer argoio.Close(conn) + defer utilio.Close(conn) _, err = versionIf.Version(context.Background(), &empty.Empty{}) } if err != nil { c.GRPCWeb = true conn, versionIf := c.NewVersionClientOrDie() - defer argoio.Close(conn) + defer utilio.Close(conn) _, err := versionIf.Version(context.Background(), &empty.Empty{}) if err == nil { @@ -544,7 +544,7 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) { } conn, e := grpc_util.BlockingDial(ctx, network, serverAddr, creds, dialOpts...) closers = append(closers, conn) - return conn, argoio.NewCloser(func() error { + return conn, utilio.NewCloser(func() error { var firstErr error for i := range closers { err := closers[i].Close() diff --git a/pkg/apiclient/grpcproxy.go b/pkg/apiclient/grpcproxy.go index 37b4453cb9..9cfe4b8fa0 100644 --- a/pkg/apiclient/grpcproxy.go +++ b/pkg/apiclient/grpcproxy.go @@ -20,7 +20,7 @@ import ( "github.com/argoproj/argo-cd/v3/common" argocderrors "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/rand" ) @@ -144,9 +144,9 @@ func (c *client) startGRPCProxy() (*grpc.Server, net.Listener, error) { go func() { <-stream.Context().Done() - argoio.Close(resp.Body) + utilio.Close(resp.Body) }() - defer argoio.Close(resp.Body) + defer utilio.Close(resp.Body) c.httpClient.CloseIdleConnections() for { @@ -199,7 +199,7 @@ func (c *client) useGRPCProxy() (net.Addr, io.Closer, error) { } c.proxyUsersCount = c.proxyUsersCount + 1 - return c.proxyListener.Addr(), argoio.NewCloser(func() error { + return c.proxyListener.Addr(), utilio.NewCloser(func() error { c.proxyMutex.Lock() defer c.proxyMutex.Unlock() c.proxyUsersCount = c.proxyUsersCount - 1 diff --git a/reposerver/apiclient/clientset.go b/reposerver/apiclient/clientset.go index eaefd47411..2243caf45e 100644 --- a/reposerver/apiclient/clientset.go +++ b/reposerver/apiclient/clientset.go @@ -18,7 +18,7 @@ import ( "google.golang.org/grpc/credentials/insecure" argogrpc "github.com/argoproj/argo-cd/v3/util/grpc" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // MaxGRPCMessageSize contains max grpc message size @@ -36,7 +36,7 @@ type TLSConfiguration struct { // Clientset represents repository server api clients type Clientset interface { - NewRepoServerClient() (io.Closer, RepoServerServiceClient, error) + NewRepoServerClient() (utilio.Closer, RepoServerServiceClient, error) } type clientSet struct { @@ -45,7 +45,7 @@ type clientSet struct { tlsConfig TLSConfiguration } -func (c *clientSet) NewRepoServerClient() (io.Closer, RepoServerServiceClient, error) { +func (c *clientSet) NewRepoServerClient() (utilio.Closer, RepoServerServiceClient, error) { conn, err := NewConnection(c.address, c.timeoutSeconds, &c.tlsConfig) if err != nil { return nil, nil, fmt.Errorf("failed to open a new connection to repo server: %w", err) diff --git a/reposerver/apiclient/mocks/Clientset.go b/reposerver/apiclient/mocks/Clientset.go index 54869a3901..4c727b8d2a 100644 --- a/reposerver/apiclient/mocks/Clientset.go +++ b/reposerver/apiclient/mocks/Clientset.go @@ -2,13 +2,13 @@ package mocks import ( "github.com/argoproj/argo-cd/v3/reposerver/apiclient" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) type Clientset struct { RepoServerServiceClient apiclient.RepoServerServiceClient } -func (c *Clientset) NewRepoServerClient() (io.Closer, apiclient.RepoServerServiceClient, error) { - return io.NopCloser, c.RepoServerServiceClient, nil +func (c *Clientset) NewRepoServerClient() (utilio.Closer, apiclient.RepoServerServiceClient, error) { + return utilio.NopCloser, c.RepoServerServiceClient, nil } diff --git a/reposerver/repository/lock.go b/reposerver/repository/lock.go index 726a58e2a4..e180773023 100644 --- a/reposerver/repository/lock.go +++ b/reposerver/repository/lock.go @@ -5,7 +5,7 @@ import ( "io" "sync" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func NewRepositoryLock() *repositoryLock { @@ -27,7 +27,7 @@ func (r *repositoryLock) Lock(path string, revision string, allowConcurrent bool } r.lock.Unlock() - closer := ioutil.NewCloser(func() error { + closer := utilio.NewCloser(func() error { state.cond.L.Lock() notify := false state.processCount-- diff --git a/reposerver/repository/lock_test.go b/reposerver/repository/lock_test.go index 01e9fd1519..799476eaac 100644 --- a/reposerver/repository/lock_test.go +++ b/reposerver/repository/lock_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // execute given action and return false if action have not completed within 1 second @@ -29,7 +29,7 @@ func lockQuickly(action func() (io.Closer, error)) (io.Closer, bool) { func numberOfInits(initializedTimes *int) func() (io.Closer, error) { return func() (io.Closer, error) { *initializedTimes++ - return util.NopCloser, nil + return utilio.NopCloser, nil } } @@ -55,9 +55,9 @@ func TestLock_SameRevision(t *testing.T) { assert.Equal(t, 1, initializedTimes) - util.Close(closer1) + utilio.Close(closer1) - util.Close(closer2) + utilio.Close(closer2) } func TestLock_DifferentRevisions(t *testing.T) { @@ -81,7 +81,7 @@ func TestLock_DifferentRevisions(t *testing.T) { return } - util.Close(closer1) + utilio.Close(closer1) _, done = lockQuickly(func() (io.Closer, error) { return lock.Lock("myRepo", "2", true, init) @@ -113,7 +113,7 @@ func TestLock_NoConcurrentWithSameRevision(t *testing.T) { return } - util.Close(closer1) + utilio.Close(closer1) } func TestLock_FailedInitialization(t *testing.T) { @@ -121,7 +121,7 @@ func TestLock_FailedInitialization(t *testing.T) { closer1, done := lockQuickly(func() (io.Closer, error) { return lock.Lock("myRepo", "1", true, func() (io.Closer, error) { - return util.NopCloser, errors.New("failed") + return utilio.NopCloser, errors.New("failed") }) }) @@ -133,7 +133,7 @@ func TestLock_FailedInitialization(t *testing.T) { closer2, done := lockQuickly(func() (io.Closer, error) { return lock.Lock("myRepo", "1", true, func() (io.Closer, error) { - return util.NopCloser, nil + return utilio.NopCloser, nil }) }) @@ -141,7 +141,7 @@ func TestLock_FailedInitialization(t *testing.T) { return } - util.Close(closer2) + utilio.Close(closer2) } func TestLock_SameRevisionFirstNotConcurrent(t *testing.T) { @@ -166,5 +166,5 @@ func TestLock_SameRevisionFirstNotConcurrent(t *testing.T) { assert.Equal(t, 1, initializedTimes) - util.Close(closer1) + utilio.Close(closer1) } diff --git a/reposerver/repository/repository.go b/reposerver/repository/repository.go index a023c994cb..0ec90e19c6 100644 --- a/reposerver/repository/repository.go +++ b/reposerver/repository/repository.go @@ -53,7 +53,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/gpg" "github.com/argoproj/argo-cd/v3/util/grpc" "github.com/argoproj/argo-cd/v3/util/helm" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/io/files" pathutil "github.com/argoproj/argo-cd/v3/util/io/path" "github.com/argoproj/argo-cd/v3/util/kustomize" @@ -76,8 +76,8 @@ var ErrExceededMaxCombinedManifestFileSize = errors.New("exceeded max combined m type Service struct { gitCredsStore git.CredsStore rootDir string - gitRepoPaths io.TempPaths - chartPaths io.TempPaths + gitRepoPaths utilio.TempPaths + chartPaths utilio.TempPaths gitRepoInitializer func(rootPath string) goio.Closer repoLock *repositoryLock cache *cache.Cache @@ -118,8 +118,8 @@ func NewService(metricsServer *metrics.MetricsServer, cache *cache.Cache, initCo parallelismLimitSemaphore = semaphore.NewWeighted(initConstants.ParallelismLimit) } repoLock := NewRepositoryLock() - gitRandomizedPaths := io.NewRandomizedTempPaths(rootDir) - helmRandomizedPaths := io.NewRandomizedTempPaths(rootDir) + gitRandomizedPaths := utilio.NewRandomizedTempPaths(rootDir) + helmRandomizedPaths := utilio.NewRandomizedTempPaths(rootDir) return &Service{ parallelismLimitSemaphore: parallelismLimitSemaphore, repoLock: repoLock, @@ -169,7 +169,7 @@ func (s *Service) Init() error { s.gitRepoPaths.Add(git.NormalizeGitURL(remotes[0].Config().URLs[0]), fullPath) } } - io.Close(closer) + utilio.Close(closer) } // remove read permissions since no-one should be able to list the directories return os.Chmod(s.rootDir, 0o300) @@ -219,7 +219,7 @@ func (s *Service) ListApps(ctx context.Context, q *apiclient.ListAppsRequest) (* return nil, fmt.Errorf("error acquiring repository lock: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) apps, err := discovery.Discover(ctx, gitClient.Root(), gitClient.Root(), q.EnabledSourceTypes, s.initConstants.CMPTarExcludedGlobs, []string{}) if err != nil { return nil, fmt.Errorf("error discovering applications: %w", err) @@ -351,7 +351,7 @@ func (s *Service) runRepoOperation( if err != nil { return err } - defer io.Close(closer) + defer utilio.Close(closer) if !s.initConstants.AllowOutOfBoundsSymlinks { err := apppathutil.CheckOutOfBoundsSymlinks(chartPath) if err != nil { @@ -379,7 +379,7 @@ func (s *Service) runRepoOperation( return err } - defer io.Close(closer) + defer utilio.Close(closer) if !s.initConstants.AllowOutOfBoundsSymlinks { err := apppathutil.CheckOutOfBoundsSymlinks(gitClient.Root()) @@ -1087,7 +1087,7 @@ func isSourcePermitted(url string, repos []string) bool { return p.IsSourcePermitted(v1alpha1.ApplicationSource{RepoURL: url}) } -func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclient.ManifestRequest, isLocal bool, gitRepoPaths io.TempPaths) ([]*unstructured.Unstructured, string, error) { +func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclient.ManifestRequest, isLocal bool, gitRepoPaths utilio.TempPaths) ([]*unstructured.Unstructured, string, error) { // We use the app name as Helm's release name property, which must not // contain any underscore characters and must not exceed 53 characters. // We are not interested in the fully qualified application name while @@ -1244,7 +1244,7 @@ func helmTemplate(appPath string, repoRoot string, env *v1alpha1.Env, q *apiclie // redactPaths removes temp repo paths, since those paths are randomized (and therefore not helpful for the user) and // sensitive (so not suitable for logging). It also replaces the path of the randomly-named values file which is used // to hold the `spec.source.helm.values` or `valuesObject` contents. -func redactPaths(s string, paths io.TempPaths, extraValuesPath pathutil.ResolvedFilePath) string { +func redactPaths(s string, paths utilio.TempPaths, extraValuesPath pathutil.ResolvedFilePath) string { if paths == nil { return s } @@ -1265,7 +1265,7 @@ func getResolvedValueFiles( allowedValueFilesSchemas []string, rawValueFiles []string, refSources map[string]*v1alpha1.RefTarget, - gitRepoPaths io.TempPaths, + gitRepoPaths utilio.TempPaths, ignoreMissingValueFiles bool, ) ([]pathutil.ResolvedFilePath, error) { var resolvedValueFiles []pathutil.ResolvedFilePath @@ -1309,7 +1309,7 @@ func getResolvedRefValueFile( env *v1alpha1.Env, allowedValueFilesSchemas []string, refSourceRepo string, - gitRepoPaths io.TempPaths, + gitRepoPaths utilio.TempPaths, ) (pathutil.ResolvedFilePath, error) { pathStrings := strings.Split(rawValueFile, "/") repoPath := gitRepoPaths.GetPathIfExists(git.NormalizeGitURL(refSourceRepo)) @@ -1389,7 +1389,7 @@ func WithCMPUseManifestGeneratePaths(enabled bool) GenerateManifestOpt { } // GenerateManifests generates manifests from a path. Overrides are applied as a side effect on the given ApplicationSource. -func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string, q *apiclient.ManifestRequest, isLocal bool, gitCredsStore git.CredsStore, maxCombinedManifestQuantity resource.Quantity, gitRepoPaths io.TempPaths, opts ...GenerateManifestOpt) (*apiclient.ManifestResponse, error) { +func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string, q *apiclient.ManifestRequest, isLocal bool, gitCredsStore git.CredsStore, maxCombinedManifestQuantity resource.Quantity, gitRepoPaths utilio.TempPaths, opts ...GenerateManifestOpt) (*apiclient.ManifestResponse, error) { opt := newGenerateManifestOpt(opts...) var targetObjs []*unstructured.Unstructured @@ -1961,7 +1961,7 @@ func runConfigManagementPluginSidecars(ctx context.Context, appPath, repoPath, p if err != nil { return nil, err } - defer io.Close(conn) + defer utilio.Close(conn) rootPath := repoPath if useManifestGeneratePaths { @@ -2087,7 +2087,7 @@ func (s *Service) createGetAppDetailsCacheHandler(res *apiclient.RepoAppDetailsR } } -func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath string, repoRoot string, q *apiclient.RepoServerAppDetailsQuery, gitRepoPaths io.TempPaths) error { +func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath string, repoRoot string, q *apiclient.RepoServerAppDetailsQuery, gitRepoPaths utilio.TempPaths) error { var selectedValueFiles []string var availableValueFiles []string @@ -2234,7 +2234,7 @@ func populatePluginAppDetails(ctx context.Context, res *apiclient.RepoAppDetails if err != nil { return fmt.Errorf("failed to detect CMP for app: %w", err) } - defer io.Close(conn) + defer utilio.Close(conn) parametersAnnouncementStream, err := cmpClient.GetParametersAnnouncement(ctx, grpc_retry.Disable()) if err != nil { @@ -2299,7 +2299,7 @@ func (s *Service) GetRevisionMetadata(_ context.Context, q *apiclient.RepoServer return nil, fmt.Errorf("error acquiring repo lock: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) m, err := gitClient.RevisionMetadata(q.Revision) if err != nil { @@ -2352,7 +2352,7 @@ func (s *Service) GetRevisionChartDetails(_ context.Context, q *apiclient.RepoSe if err != nil { return nil, fmt.Errorf("error extracting chart: %w", err) } - defer io.Close(closer) + defer utilio.Close(closer) helmCmd, err := helm.NewCmdWithVersion(chartPath, q.Repo.EnableOCI, q.Repo.Proxy, q.Repo.NoProxy) if err != nil { return nil, fmt.Errorf("error creating helm cmd: %w", err) @@ -2448,7 +2448,7 @@ func directoryPermissionInitializer(rootPath string) goio.Closer { } } - return io.NewCloser(func() error { + return utilio.NewCloser(func() error { if err := os.Chmod(rootPath, 0o000); err != nil { log.Warnf("Failed to remove permissions on %s: %v", rootPath, err) } else { @@ -2674,7 +2674,7 @@ func (s *Service) GetGitFiles(_ context.Context, request *apiclient.GitFilesRequ if err != nil { return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s pattern %s: %v", repo.Repo, revision, gitPath, err) } - defer io.Close(closer) + defer utilio.Close(closer) gitFiles, err := gitClient.LsFiles(gitPath, enableNewGitFileGlobbing) if err != nil { @@ -2756,7 +2756,7 @@ func (s *Service) GetGitDirectories(_ context.Context, request *apiclient.GitDir if err != nil { return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s: %v", repo.Repo, revision, err) } - defer io.Close(closer) + defer utilio.Close(closer) repoRoot := gitClient.Root() var paths []string @@ -2848,7 +2848,7 @@ func (s *Service) UpdateRevisionForPaths(_ context.Context, request *apiclient.U if err != nil { return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s: %v", repo.Repo, revision, err) } - defer io.Close(closer) + defer utilio.Close(closer) if err := s.fetch(gitClient, []string{syncedRevision}); err != nil { return nil, status.Errorf(codes.Internal, "unable to fetch git repo %s with syncedRevisions %s: %v", repo.Repo, syncedRevision, err) diff --git a/reposerver/repository/repository_test.go b/reposerver/repository/repository_test.go index 60b5a31f94..82414b18e7 100644 --- a/reposerver/repository/repository_test.go +++ b/reposerver/repository/repository_test.go @@ -46,7 +46,7 @@ import ( gitmocks "github.com/argoproj/argo-cd/v3/util/git/mocks" "github.com/argoproj/argo-cd/v3/util/helm" helmmocks "github.com/argoproj/argo-cd/v3/util/helm/mocks" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" iomocks "github.com/argoproj/argo-cd/v3/util/io/mocks" ) @@ -127,8 +127,8 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git oobChart: {{Version: "1.0.0"}, {Version: version}}, }}, nil) helmClient.On("GetTags", mock.Anything, mock.Anything).Return(nil, nil) - helmClient.On("ExtractChart", chart, version, false, int64(0), false).Return("./testdata/my-chart", io.NopCloser, nil) - helmClient.On("ExtractChart", oobChart, version, false, int64(0), false).Return("./testdata2/out-of-bounds-chart", io.NopCloser, nil) + helmClient.On("ExtractChart", chart, version, false, int64(0), false).Return("./testdata/my-chart", utilio.NopCloser, nil) + helmClient.On("ExtractChart", oobChart, version, false, int64(0), false).Return("./testdata2/out-of-bounds-chart", utilio.NopCloser, nil) helmClient.On("CleanChartCache", chart, version).Return(nil) helmClient.On("CleanChartCache", oobChart, version).Return(nil) helmClient.On("DependencyBuild").Return(nil) @@ -157,7 +157,7 @@ func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *git return helmClient } service.gitRepoInitializer = func(_ string) goio.Closer { - return io.NopCloser + return utilio.NopCloser } service.gitRepoPaths = paths return service, gitClient, cacheMocks @@ -2918,7 +2918,7 @@ func TestDirectoryPermissionInitializer(t *testing.T) { file, err := os.CreateTemp(dir, "") require.NoError(t, err) - io.Close(file) + utilio.Close(file) // remove read permissions require.NoError(t, os.Chmod(dir, 0o000)) @@ -2935,7 +2935,7 @@ func TestDirectoryPermissionInitializer(t *testing.T) { require.NoError(t, err) // make sure permission are removed by closer - io.Close(closer) + utilio.Close(closer) _, err = os.ReadFile(file.Name()) require.Error(t, err) } @@ -3170,7 +3170,7 @@ func Test_walkHelmValueFilesInPath(t *testing.T) { } func Test_populateHelmAppDetails(t *testing.T) { - emptyTempPaths := io.NewRandomizedTempPaths(t.TempDir()) + emptyTempPaths := utilio.NewRandomizedTempPaths(t.TempDir()) res := apiclient.RepoAppDetailsResponse{} q := apiclient.RepoServerAppDetailsQuery{ Repo: &v1alpha1.Repository{}, @@ -3187,7 +3187,7 @@ func Test_populateHelmAppDetails(t *testing.T) { } func Test_populateHelmAppDetails_values_symlinks(t *testing.T) { - emptyTempPaths := io.NewRandomizedTempPaths(t.TempDir()) + emptyTempPaths := utilio.NewRandomizedTempPaths(t.TempDir()) t.Run("inbound", func(t *testing.T) { res := apiclient.RepoAppDetailsResponse{} q := apiclient.RepoServerAppDetailsQuery{Repo: &v1alpha1.Repository{}, Source: &v1alpha1.ApplicationSource{}} @@ -3269,7 +3269,7 @@ func TestGetHelmRepo_NamedReposAlias(t *testing.T) { func Test_getResolvedValueFiles(t *testing.T) { tempDir := t.TempDir() - paths := io.NewRandomizedTempPaths(tempDir) + paths := utilio.NewRandomizedTempPaths(tempDir) paths.Add(git.NormalizeGitURL("https://github.com/org/repo1"), path.Join(tempDir, "repo1")) diff --git a/server/application/application.go b/server/application/application.go index d7c279d6dd..b9f1d38ce0 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -54,7 +54,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/db" "github.com/argoproj/argo-cd/v3/util/env" "github.com/argoproj/argo-cd/v3/util/git" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/lua" "github.com/argoproj/argo-cd/v3/util/manifeststream" "github.com/argoproj/argo-cd/v3/util/rbac" @@ -417,7 +417,7 @@ func (s *Server) queryRepoServer(ctx context.Context, proj *v1alpha1.AppProject, if err != nil { return fmt.Errorf("error creating repo server client: %w", err) } - defer ioutil.Close(closer) + defer utilio.Close(closer) helmRepos, err := s.db.ListHelmRepositories(ctx) if err != nil { @@ -1568,7 +1568,7 @@ func (s *Server) RevisionMetadata(ctx context.Context, q *application.RevisionMe if err != nil { return nil, fmt.Errorf("error creating repo server client: %w", err) } - defer ioutil.Close(conn) + defer utilio.Close(conn) return repoClient.GetRevisionMetadata(ctx, &apiclient.RepoServerRevisionMetadataRequest{ Repo: repo, Revision: q.GetRevision(), @@ -1599,7 +1599,7 @@ func (s *Server) RevisionChartDetails(ctx context.Context, q *application.Revisi if err != nil { return nil, fmt.Errorf("error creating repo server client: %w", err) } - defer ioutil.Close(conn) + defer utilio.Close(conn) return repoClient.GetRevisionChartDetails(ctx, &apiclient.RepoServerRevisionChartDetailsRequest{ Repo: repo, Name: source.Chart, @@ -1796,7 +1796,7 @@ func (s *Server) PodLogs(q *application.ApplicationPodLogsQuery, ws application. podName := pod.Name logStream := make(chan logEntry) if err == nil { - defer ioutil.Close(stream) + defer utilio.Close(stream) } streams = append(streams, logStream) @@ -2290,7 +2290,7 @@ func (s *Server) resolveRevision(ctx context.Context, app *v1alpha1.Application, if err != nil { return "", "", fmt.Errorf("error getting repo server client: %w", err) } - defer ioutil.Close(conn) + defer utilio.Close(conn) source := app.Spec.GetSourcePtrByIndex(sourceIndex) if !source.IsHelm() { diff --git a/server/repository/repository.go b/server/repository/repository.go index 65e3e2f428..cb7f1eeb9a 100644 --- a/server/repository/repository.go +++ b/server/repository/repository.go @@ -26,7 +26,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/db" "github.com/argoproj/argo-cd/v3/util/errors" "github.com/argoproj/argo-cd/v3/util/git" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/rbac" "github.com/argoproj/argo-cd/v3/util/settings" ) @@ -252,7 +252,7 @@ func (s *Server) ListRefs(ctx context.Context, q *repositorypkg.RepoQuery) (*api if err != nil { return nil, err } - defer io.Close(conn) + defer utilio.Close(conn) return repoClient.ListRefs(ctx, &apiclient.ListRefsRequest{ Repo: repo, @@ -290,7 +290,7 @@ func (s *Server) ListApps(ctx context.Context, q *repositorypkg.RepoAppsQuery) ( if err != nil { return nil, err } - defer io.Close(conn) + defer utilio.Close(conn) apps, err := repoClient.ListApps(ctx, &apiclient.ListAppsRequest{ Repo: repo, @@ -353,7 +353,7 @@ func (s *Server) GetAppDetails(ctx context.Context, q *repositorypkg.RepoAppDeta if err != nil { return nil, err } - defer io.Close(conn) + defer utilio.Close(conn) helmRepos, err := s.db.ListHelmRepositories(ctx) if err != nil { return nil, err @@ -404,7 +404,7 @@ func (s *Server) GetHelmCharts(ctx context.Context, q *repositorypkg.RepoQuery) if err != nil { return nil, err } - defer io.Close(conn) + defer utilio.Close(conn) return repoClient.GetHelmCharts(ctx, &apiclient.HelmChartsRequest{Repo: repo}) } @@ -746,7 +746,7 @@ func (s *Server) testRepo(ctx context.Context, repo *v1alpha1.Repository) error if err != nil { return fmt.Errorf("failed to connect to repo-server: %w", err) } - defer io.Close(conn) + defer utilio.Close(conn) _, err = repoClient.TestRepository(ctx, &apiclient.TestRepositoryRequest{ Repo: repo, diff --git a/server/server.go b/server/server.go index 8d27516105..4894561d20 100644 --- a/server/server.go +++ b/server/server.go @@ -114,7 +114,7 @@ import ( grpc_util "github.com/argoproj/argo-cd/v3/util/grpc" "github.com/argoproj/argo-cd/v3/util/healthz" httputil "github.com/argoproj/argo-cd/v3/util/http" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/io/files" jwtutil "github.com/argoproj/argo-cd/v3/util/jwt" kubeutil "github.com/argoproj/argo-cd/v3/util/kube" @@ -340,7 +340,7 @@ func NewServer(ctx context.Context, opts ArgoCDServerOpts, appsetOpts Applicatio errorsutil.CheckError(err) } } else { - staticFS = io.NewComposableFS(staticFS, root.FS()) + staticFS = utilio.NewComposableFS(staticFS, root.FS()) } argocdService, err := service.NewArgoCDService(opts.KubeClientset, opts.Namespace, opts.RepoClientset) @@ -509,7 +509,7 @@ func (server *ArgoCDServer) Listen() (*Listeners, error) { } metricsLn, err := startListener(server.ListenHost, server.MetricsPort) if err != nil { - io.Close(mainLn) + utilio.Close(mainLn) return nil, err } var dOpts []grpc.DialOption @@ -535,8 +535,8 @@ func (server *ArgoCDServer) Listen() (*Listeners, error) { //nolint:staticcheck conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", server.ListenPort), dOpts...) if err != nil { - io.Close(mainLn) - io.Close(metricsLn) + utilio.Close(mainLn) + utilio.Close(metricsLn) return nil, err } return &Listeners{Main: mainLn, Metrics: metricsLn, GatewayConn: conn}, nil @@ -1013,7 +1013,7 @@ func newArgoCDServiceSet(a *ArgoCDServer) *ArgoCDServiceSet { clusterService := cluster.NewServer(a.db, a.enf, a.Cache, kubectl) repoService := repository.NewServer(a.RepoClientset, a.db, a.enf, a.Cache, a.appLister, a.projInformer, a.Namespace, a.settingsMgr, a.HydratorEnabled) repoCredsService := repocreds.NewServer(a.RepoClientset, a.db, a.enf, a.settingsMgr) - var loginRateLimiter func() (io.Closer, error) + var loginRateLimiter func() (utilio.Closer, error) if maxConcurrentLoginRequestsCount > 0 { loginRateLimiter = session.NewLoginRateLimiter(maxConcurrentLoginRequestsCount) } @@ -1318,7 +1318,7 @@ func (server *ArgoCDServer) serveExtensions(extensionsSharedPath string, w http. if err != nil { return fmt.Errorf("failed to open file '%s': %w", filePath, err) } - defer io.Close(f) + defer utilio.Close(f) if _, err := goio.Copy(w, f); err != nil { return fmt.Errorf("failed to copy file '%s': %w", filePath, err) @@ -1426,7 +1426,7 @@ func (server *ArgoCDServer) uiAssetExists(filename string) bool { if err != nil { return false } - defer io.Close(f) + defer utilio.Close(f) stat, err := f.Stat() if err != nil { return false @@ -1472,7 +1472,7 @@ func (server *ArgoCDServer) newStaticAssetsHandler() func(http.ResponseWriter, * if err != nil { modTime = time.Now() } - http.ServeContent(w, r, "index.html", modTime, io.NewByteReadSeeker(data)) + http.ServeContent(w, r, "index.html", modTime, utilio.NewByteReadSeeker(data)) } else { if isMainJsBundle(r.URL) { cacheControl := "public, max-age=31536000, immutable" diff --git a/server/session/ratelimiter.go b/server/session/ratelimiter.go index 698a8ea753..2ffa44a2dc 100644 --- a/server/session/ratelimiter.go +++ b/server/session/ratelimiter.go @@ -1,21 +1,21 @@ package session import ( - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/session" log "github.com/sirupsen/logrus" "golang.org/x/sync/semaphore" ) -func NewLoginRateLimiter(maxNumber int) func() (util.Closer, error) { +func NewLoginRateLimiter(maxNumber int) func() (utilio.Closer, error) { semaphore := semaphore.NewWeighted(int64(maxNumber)) - return func() (util.Closer, error) { + return func() (utilio.Closer, error) { if !semaphore.TryAcquire(1) { log.Warnf("Exceeded number of concurrent login requests") return nil, session.InvalidLoginErr } - return util.NewCloser(func() error { + return utilio.NewCloser(func() error { defer semaphore.Release(1) return nil }), nil diff --git a/server/session/ratelimiter_test.go b/server/session/ratelimiter_test.go index e7a39cb293..0c2a19034c 100644 --- a/server/session/ratelimiter_test.go +++ b/server/session/ratelimiter_test.go @@ -6,12 +6,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/session" ) func TestRateLimiter(t *testing.T) { - var closers []util.Closer + var closers []utilio.Closer limiter := NewLoginRateLimiter(10) for i := 0; i < 10; i++ { closer, err := limiter() diff --git a/server/session/session.go b/server/session/session.go index 3b9980351e..8ba56f042f 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -12,7 +12,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apiclient/session" "github.com/argoproj/argo-cd/v3/server/rbacpolicy" - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" sessionmgr "github.com/argoproj/argo-cd/v3/util/session" ) @@ -22,7 +22,7 @@ type Server struct { settingsMgr *settings.SettingsManager authenticator Authenticator policyEnf *rbacpolicy.RBACPolicyEnforcer - limitLoginAttempts func() (util.Closer, error) + limitLoginAttempts func() (utilio.Closer, error) } type Authenticator interface { @@ -30,7 +30,7 @@ type Authenticator interface { } // NewServer returns a new instance of the Session service -func NewServer(mgr *sessionmgr.SessionManager, settingsMgr *settings.SettingsManager, authenticator Authenticator, policyEnf *rbacpolicy.RBACPolicyEnforcer, rateLimiter func() (util.Closer, error)) *Server { +func NewServer(mgr *sessionmgr.SessionManager, settingsMgr *settings.SettingsManager, authenticator Authenticator, policyEnf *rbacpolicy.RBACPolicyEnforcer, rateLimiter func() (utilio.Closer, error)) *Server { return &Server{mgr, settingsMgr, authenticator, policyEnf, rateLimiter} } @@ -42,7 +42,7 @@ func (s *Server) Create(_ context.Context, q *session.SessionCreateRequest) (*se if err != nil { return nil, err } - defer util.Close(closer) + defer utilio.Close(closer) } if q.Token != "" { diff --git a/server/settings/settings.go b/server/settings/settings.go index e65b51e2ce..c2776949d7 100644 --- a/server/settings/settings.go +++ b/server/settings/settings.go @@ -8,7 +8,7 @@ import ( "sigs.k8s.io/yaml" "github.com/argoproj/argo-cd/v3/reposerver/apiclient" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" sessionmgr "github.com/argoproj/argo-cd/v3/util/session" @@ -165,7 +165,7 @@ func (s *Server) plugins(ctx context.Context) ([]*settingspkg.Plugin, error) { if err != nil { return nil, fmt.Errorf("error creating repo server client: %w", err) } - defer ioutil.Close(closer) + defer utilio.Close(closer) pluginList, err := client.ListPlugins(ctx, &empty.Empty{}) if err != nil { diff --git a/test/e2e/accounts_test.go b/test/e2e/accounts_test.go index 7dec34db54..b5047b718d 100644 --- a/test/e2e/accounts_test.go +++ b/test/e2e/accounts_test.go @@ -15,7 +15,7 @@ import ( . "github.com/argoproj/argo-cd/v3/test/e2e/fixture" accountFixture "github.com/argoproj/argo-cd/v3/test/e2e/fixture/account" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func TestCreateAndUseAccount(t *testing.T) { @@ -107,7 +107,7 @@ test true login, apiKey`, output) testAccountClientset := headless.NewClientOrDie(&clientOpts, &cobra.Command{}) closer, client := testAccountClientset.NewSessionClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) info, err := client.GetUserInfo(t.Context(), &session.GetUserInfoRequest{}) require.NoError(t, err) @@ -119,7 +119,7 @@ func TestLoginBadCredentials(t *testing.T) { EnsureCleanState(t) closer, sessionClient := ArgoCDClientset.NewSessionClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) requests := []session.SessionCreateRequest{{ Username: "user-does-not-exist", Password: "some-password", diff --git a/test/e2e/app_management_ns_test.go b/test/e2e/app_management_ns_test.go index f920164596..508dcd354a 100644 --- a/test/e2e/app_management_ns_test.go +++ b/test/e2e/app_management_ns_test.go @@ -37,7 +37,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apis/application" . "github.com/argoproj/argo-cd/v3/util/argo" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/settings" ) @@ -544,7 +544,7 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) _, err = client.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{ Name: &app.Name, @@ -563,7 +563,7 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) { func TestNamespacedAppWithSecrets(t *testing.T) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) ctx := Given(t) ctx. @@ -861,7 +861,7 @@ func TestNamespacedResourceAction(t *testing.T) { And(func(app *Application) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{ Name: &app.Name, @@ -1034,7 +1034,7 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) { } closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{}) require.NoError(t, err) @@ -1154,7 +1154,7 @@ func TestNamespacedPermissions(t *testing.T) { Expect(Condition(ApplicationConditionInvalidSpecError, sourceError)). And(func(app *Application) { closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) tree, err := cdClient.ResourceTree(t.Context(), &applicationpkg.ResourcesQuery{ApplicationName: &app.Name, AppNamespace: &app.Namespace}) require.NoError(t, err) assert.Empty(t, tree.Nodes) diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index 71e7854ee7..766084f54d 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -37,7 +37,7 @@ import ( "github.com/argoproj/argo-cd/v3/test/e2e/testdata" "github.com/argoproj/argo-cd/v3/util/argo" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/settings" "github.com/argoproj/argo-cd/v3/pkg/apis/application" @@ -733,7 +733,7 @@ func TestManipulateApplicationResources(t *testing.T) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) _, err = client.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{ Name: &app.Name, @@ -776,7 +776,7 @@ func assetSecretDataHidden(t *testing.T, manifest string) { func TestAppWithSecrets(t *testing.T) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) Given(t). Path("secrets"). @@ -1073,7 +1073,7 @@ func TestOldStyleResourceAction(t *testing.T) { And(func(app *Application) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{ Name: &app.Name, @@ -1179,7 +1179,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) { And(func(app *Application) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{ Name: &app.Name, @@ -1291,7 +1291,7 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) { And(func(app *Application) { closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{ Name: &app.Name, @@ -1468,7 +1468,7 @@ func assertResourceActions(t *testing.T, appName string, successful bool) { } closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{}) require.NoError(t, err) @@ -1580,7 +1580,7 @@ func TestPermissions(t *testing.T) { Expect(Condition(ApplicationConditionInvalidSpecError, sourceError)). And(func(app *Application) { closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie() - defer io.Close(closer) + defer utilio.Close(closer) appName, appNs := argo.ParseFromQualifiedName(app.Name, "") fmt.Printf("APP NAME: %s\n", appName) tree, err := cdClient.ResourceTree(t.Context(), &applicationpkg.ResourcesQuery{ApplicationName: &appName, AppNamespace: &appNs}) diff --git a/test/e2e/fixture/account/consequences.go b/test/e2e/fixture/account/consequences.go index d59008b1ba..ea98242b2a 100644 --- a/test/e2e/fixture/account/consequences.go +++ b/test/e2e/fixture/account/consequences.go @@ -11,7 +11,7 @@ import ( "github.com/argoproj/argo-cd/v3/pkg/apiclient/account" "github.com/argoproj/argo-cd/v3/test/e2e/fixture" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // this implements the "then" part of given/when/then @@ -56,7 +56,7 @@ func (c *Consequences) getCurrentUser() (*session.GetUserInfoResponse, error) { c.context.t.Helper() closer, client, err := fixture.ArgoCDClientset.NewSessionClient() require.NoError(c.context.t, err) - defer io.Close(closer) + defer utilio.Close(closer) return client.GetUserInfo(context.Background(), &session.GetUserInfoRequest{}) } diff --git a/test/e2e/fixture/app/consequences.go b/test/e2e/fixture/app/consequences.go index c3d4d6c0c2..985e5a8126 100644 --- a/test/e2e/fixture/app/consequences.go +++ b/test/e2e/fixture/app/consequences.go @@ -13,7 +13,7 @@ import ( applicationpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/application" "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/test/e2e/fixture" - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) // this implements the "then" part of given/when/then @@ -120,7 +120,7 @@ func (c *Consequences) resource(kind, name, namespace string) v1alpha1.ResourceS c.context.t.Helper() closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() require.NoError(c.context.t, err) - defer util.Close(closer) + defer utilio.Close(closer) app, err := client.Get(context.Background(), &applicationpkg.ApplicationQuery{ Name: ptr.To(c.context.AppName()), Projects: []string{c.context.project}, diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index c982742d2e..76e9e769c9 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -35,7 +35,7 @@ import ( "github.com/argoproj/argo-cd/v3/util/env" "github.com/argoproj/argo-cd/v3/util/errors" grpcutil "github.com/argoproj/argo-cd/v3/util/grpc" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/rand" "github.com/argoproj/argo-cd/v3/util/settings" ) @@ -247,7 +247,7 @@ func loginAs(username, password string) error { if err != nil { return err } - defer io.Close(closer) + defer utilio.Close(closer) userInfoResponse, err := client.GetUserInfo(context.Background(), &sessionpkg.GetUserInfoRequest{}) if err != nil { diff --git a/test/e2e/repo_management_test.go b/test/e2e/repo_management_test.go index 88ab7dda46..5d5b25b39d 100644 --- a/test/e2e/repo_management_test.go +++ b/test/e2e/repo_management_test.go @@ -12,7 +12,7 @@ import ( "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app" "github.com/argoproj/argo-cd/v3/test/e2e/fixture/repos" "github.com/argoproj/argo-cd/v3/util/errors" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func TestAddRemovePublicRepo(t *testing.T) { @@ -23,7 +23,7 @@ func TestAddRemovePublicRepo(t *testing.T) { conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() require.NoError(t, err) - defer argoio.Close(conn) + defer utilio.Close(conn) repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{}) @@ -66,7 +66,7 @@ func TestGetRepoWithInheritedCreds(t *testing.T) { // Then, we remove username/password so that the repo inherits the credentials from our repocreds conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() require.NoError(t, err) - defer argoio.Close(conn) + defer utilio.Close(conn) _, err = repoClient.UpdateRepository(t.Context(), &repositorypkg.RepoUpdateRequest{ Repo: &v1alpha1.Repository{ @@ -112,7 +112,7 @@ func TestAddRemoveHelmRepo(t *testing.T) { conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() require.NoError(t, err) - defer argoio.Close(conn) + defer utilio.Close(conn) repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{}) @@ -158,7 +158,7 @@ func TestAddHelmRepoInsecureSkipVerify(t *testing.T) { conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() require.NoError(t, err) - defer argoio.Close(conn) + defer utilio.Close(conn) repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{}) diff --git a/util/app/discovery/discovery.go b/util/app/discovery/discovery.go index fd5a425908..8c734bc308 100644 --- a/util/app/discovery/discovery.go +++ b/util/app/discovery/discovery.go @@ -19,7 +19,7 @@ import ( "github.com/argoproj/argo-cd/v3/common" "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/util/cmp" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/kustomize" ) @@ -41,7 +41,7 @@ func Discover(ctx context.Context, appPath, repoPath string, enableGenerateManif conn, _, err := DetectConfigManagementPlugin(ctx, appPath, repoPath, "", env, tarExcludedGlobs) if err == nil { // Found CMP - io.Close(conn) + utilio.Close(conn) apps["."] = string(v1alpha1.ApplicationSourceTypePlugin) return apps, nil @@ -88,8 +88,8 @@ func AppType(ctx context.Context, appPath, repoPath string, enableGenerateManife // check cmpSupports() // if supported return conn for the cmp-server -func DetectConfigManagementPlugin(ctx context.Context, appPath, repoPath, pluginName string, env []string, tarExcludedGlobs []string) (io.Closer, pluginclient.ConfigManagementPluginServiceClient, error) { - var conn io.Closer +func DetectConfigManagementPlugin(ctx context.Context, appPath, repoPath, pluginName string, env []string, tarExcludedGlobs []string) (utilio.Closer, pluginclient.ConfigManagementPluginServiceClient, error) { + var conn utilio.Closer var cmpClient pluginclient.ConfigManagementPluginServiceClient var connFound bool @@ -145,7 +145,7 @@ func matchRepositoryCMP(ctx context.Context, appPath, repoPath string, client pl return resp.GetIsSupported(), resp.GetIsDiscoveryEnabled(), nil } -func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fileName string, env []string, tarExcludedGlobs []string, namedPlugin bool) (io.Closer, pluginclient.ConfigManagementPluginServiceClient, bool) { +func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fileName string, env []string, tarExcludedGlobs []string, namedPlugin bool) (utilio.Closer, pluginclient.ConfigManagementPluginServiceClient, bool) { absPluginSockFilePath, err := filepath.Abs(pluginSockFilePath) if err != nil { log.Errorf("error getting absolute path for plugin socket dir %v, %v", pluginSockFilePath, err) @@ -171,7 +171,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fil cfg, err := cmpClient.CheckPluginConfiguration(ctx, &empty.Empty{}) if err != nil { log.Errorf("error checking plugin configuration %s, %v", fileName, err) - io.Close(conn) + utilio.Close(conn) return nil, nil, false } @@ -180,7 +180,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fil if namedPlugin { return conn, cmpClient, true } - io.Close(conn) + utilio.Close(conn) return nil, nil, false } @@ -190,7 +190,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fil common.SecurityField: common.SecurityMedium, common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor, }).Errorf("repository %s is not the match because %v", repoPath, err) - io.Close(conn) + utilio.Close(conn) return nil, nil, false } @@ -203,7 +203,7 @@ func cmpSupports(ctx context.Context, pluginSockFilePath, appPath, repoPath, fil common.SecurityField: common.SecurityLow, common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor, }).Debugf("Response from socket file %s does not support %v", fileName, repoPath) - io.Close(conn) + utilio.Close(conn) return nil, nil, false } return conn, cmpClient, true diff --git a/util/argo/argo.go b/util/argo/argo.go index bbe758a282..15ab607970 100644 --- a/util/argo/argo.go +++ b/util/argo/argo.go @@ -31,7 +31,7 @@ import ( "github.com/argoproj/argo-cd/v3/reposerver/apiclient" "github.com/argoproj/argo-cd/v3/util/db" "github.com/argoproj/argo-cd/v3/util/glob" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/settings" ) @@ -303,7 +303,7 @@ func ValidateRepo( if err != nil { return nil, fmt.Errorf("error instantiating new repo server client: %w", err) } - defer io.Close(conn) + defer utilio.Close(conn) helmOptions, err := settingsMgr.GetHelmSettings() if err != nil { diff --git a/util/askpass/server.go b/util/askpass/server.go index 67aebdb7c4..65204a1651 100644 --- a/util/askpass/server.go +++ b/util/askpass/server.go @@ -13,7 +13,7 @@ import ( "google.golang.org/grpc/status" "github.com/argoproj/argo-cd/v3/util/git" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) type Server interface { @@ -61,7 +61,7 @@ func (s *server) GetCredentials(_ context.Context, q *CredentialsRequest) (*Cred return &CredentialsResponse{Username: creds.Username, Password: creds.Password}, nil } -func (s *server) Start(path string) (io.Closer, error) { +func (s *server) Start(path string) (utilio.Closer, error) { _ = os.Remove(path) listener, err := net.Listen("unix", path) if err != nil { @@ -72,7 +72,7 @@ func (s *server) Start(path string) (io.Closer, error) { go func() { _ = server.Serve(listener) }() - return io.NewCloser(listener.Close), nil + return utilio.NewCloser(listener.Close), nil } func (s *server) Run() error { diff --git a/util/cache/redis.go b/util/cache/redis.go index 4d75d8cb7c..c60bdcbc2f 100644 --- a/util/cache/redis.go +++ b/util/cache/redis.go @@ -12,7 +12,7 @@ import ( "sync" "time" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" rediscache "github.com/go-redis/cache/v9" "github.com/redis/go-redis/v9" @@ -149,7 +149,7 @@ func (r *redisCache) Delete(key string) error { func (r *redisCache) OnUpdated(ctx context.Context, key string, callback func() error) error { pubsub := r.client.Subscribe(ctx, key) - defer ioutil.Close(pubsub) + defer utilio.Close(pubsub) ch := pubsub.Channel() for { diff --git a/util/cli/cli.go b/util/cli/cli.go index 2a5bafe0f2..3c6b0cfa6f 100644 --- a/util/cli/cli.go +++ b/util/cli/cli.go @@ -28,7 +28,7 @@ import ( "github.com/argoproj/argo-cd/v3/common" "github.com/argoproj/argo-cd/v3/util/errors" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" utillog "github.com/argoproj/argo-cd/v3/util/log" ) @@ -204,7 +204,7 @@ func SetGLogLevel(glogLevel int) { func writeToTempFile(pattern string, data []byte) string { f, err := os.CreateTemp("", pattern) errors.CheckError(err) - defer io.Close(f) + defer utilio.Close(f) _, err = f.Write(data) errors.CheckError(err) return f.Name() diff --git a/util/git/creds.go b/util/git/creds.go index cfa0ad467b..4657c4a209 100644 --- a/util/git/creds.go +++ b/util/git/creds.go @@ -31,7 +31,7 @@ import ( "github.com/argoproj/argo-cd/v3/common" argoutils "github.com/argoproj/argo-cd/v3/util" certutil "github.com/argoproj/argo-cd/v3/util/cert" - argoioutils "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/workloadidentity" ) @@ -252,7 +252,7 @@ func (creds HTTPSCreds) Environ() (io.Closer, []string, error) { } nonce := creds.store.Add(text.FirstNonEmpty(creds.username, githubAccessTokenUsername), creds.password) env = append(env, creds.store.Environ(nonce)...) - return argoioutils.NewCloser(func() error { + return utilio.NewCloser(func() error { creds.store.Remove(nonce) return httpCloser.Close() }), env, nil @@ -455,7 +455,7 @@ func (g GitHubAppCreds) Environ() (io.Closer, []string, error) { } nonce := g.store.Add(githubAccessTokenUsername, token) env = append(env, g.store.Environ(nonce)...) - return argoioutils.NewCloser(func() error { + return utilio.NewCloser(func() error { g.store.Remove(nonce) return httpCloser.Close() }), env, nil @@ -625,7 +625,7 @@ func (c GoogleCloudCreds) Environ() (io.Closer, []string, error) { nonce := c.store.Add(username, token) env := c.store.Environ(nonce) - return argoioutils.NewCloser(func() error { + return utilio.NewCloser(func() error { c.store.Remove(nonce) return NopCloser{}.Close() }), env, nil @@ -720,7 +720,7 @@ func (creds AzureWorkloadIdentityCreds) Environ() (io.Closer, []string, error) { nonce := creds.store.Add("", token) env := creds.store.Environ(nonce) - return argoioutils.NewCloser(func() error { + return utilio.NewCloser(func() error { creds.store.Remove(nonce) return nil }), env, nil diff --git a/util/git/creds_test.go b/util/git/creds_test.go index 422a129d4e..d3f3b704b6 100644 --- a/util/git/creds_test.go +++ b/util/git/creds_test.go @@ -18,7 +18,7 @@ import ( argoio "github.com/argoproj/gitops-engine/pkg/utils/io" "github.com/argoproj/argo-cd/v3/util/cert" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/workloadidentity" "github.com/argoproj/argo-cd/v3/util/workloadidentity/mocks" ) @@ -55,7 +55,7 @@ func TestHTTPSCreds_Environ_no_cert_cleanup(t *testing.T) { closer, _, err := creds.Environ() require.NoError(t, err) credsLenBefore := len(store.creds) - io.Close(closer) + utilio.Close(closer) assert.Len(t, store.creds, credsLenBefore-1) } @@ -63,7 +63,7 @@ func TestHTTPSCreds_Environ_insecure_true(t *testing.T) { creds := NewHTTPSCreds("", "", "", "", "", true, "", "", &NoopCredsStore{}, false) closer, env, err := creds.Environ() t.Cleanup(func() { - io.Close(closer) + utilio.Close(closer) }) require.NoError(t, err) found := false @@ -80,7 +80,7 @@ func TestHTTPSCreds_Environ_insecure_false(t *testing.T) { creds := NewHTTPSCreds("", "", "", "", "", false, "", "", &NoopCredsStore{}, false) closer, env, err := creds.Environ() t.Cleanup(func() { - io.Close(closer) + utilio.Close(closer) }) require.NoError(t, err) found := false @@ -212,7 +212,7 @@ func TestHTTPSCreds_Environ_clientCert(t *testing.T) { assert.Equal(t, "clientCertKey", string(keyBytes)) require.NoError(t, err) - io.Close(closer) + utilio.Close(closer) _, err = os.Stat(cert) require.ErrorIs(t, err, os.ErrNotExist) @@ -248,7 +248,7 @@ func Test_SSHCreds_Environ(t *testing.T) { assert.Regexp(t, envRegex, env[1]) privateKeyFile := envRegex.FindStringSubmatch(env[1])[1] assert.FileExists(t, privateKeyFile) - io.Close(closer) + utilio.Close(closer) assert.NoFileExists(t, privateKeyFile) } } @@ -282,7 +282,7 @@ func Test_SSHCreds_Environ_WithProxy(t *testing.T) { assert.Regexp(t, envRegex, env[1]) privateKeyFile := envRegex.FindStringSubmatch(env[1])[1] assert.FileExists(t, privateKeyFile) - io.Close(closer) + utilio.Close(closer) assert.NoFileExists(t, privateKeyFile) } } @@ -318,7 +318,7 @@ func Test_SSHCreds_Environ_WithProxyUserNamePassword(t *testing.T) { assert.Regexp(t, envRegex, env[1]) privateKeyFile := envRegex.FindStringSubmatch(env[1])[1] assert.FileExists(t, privateKeyFile) - io.Close(closer) + utilio.Close(closer) assert.NoFileExists(t, privateKeyFile) } } @@ -326,7 +326,7 @@ func Test_SSHCreds_Environ_WithProxyUserNamePassword(t *testing.T) { func Test_SSHCreds_Environ_TempFileCleanupOnInvalidProxyURL(t *testing.T) { // Previously, if the proxy URL was invalid, a temporary file would be left in /dev/shm. This ensures the file is cleaned up in this case. - // countDev returns the number of files in /dev/shm (argoio.TempDir) + // countDev returns the number of files in /dev/shm (argoutilio.TempDir) countFilesInDevShm := func() int { entries, err := os.ReadDir(argoio.TempDir) require.NoError(t, err) @@ -407,7 +407,7 @@ func TestGoogleCloudCreds_Environ_cleanup(t *testing.T) { closer, _, err := googleCloudCreds.Environ() require.NoError(t, err) credsLenBefore := len(store.creds) - io.Close(closer) + utilio.Close(closer) assert.Len(t, store.creds, credsLenBefore-1) } @@ -434,7 +434,7 @@ func TestAzureWorkloadIdentityCreds_Environ_cleanup(t *testing.T) { closer, _, err := creds.Environ() require.NoError(t, err) credsLenBefore := len(store.creds) - io.Close(closer) + utilio.Close(closer) assert.Len(t, store.creds, credsLenBefore-1) } diff --git a/util/helm/client.go b/util/helm/client.go index 0006fb8185..66cc59a129 100644 --- a/util/helm/client.go +++ b/util/helm/client.go @@ -28,7 +28,7 @@ import ( "oras.land/oras-go/v2/registry/remote/credentials" "github.com/argoproj/argo-cd/v3/util/cache" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/io/files" "github.com/argoproj/argo-cd/v3/util/proxy" ) @@ -47,7 +47,7 @@ type indexCache interface { type Client interface { CleanChartCache(chart string, version string) error - ExtractChart(chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, argoio.Closer, error) + ExtractChart(chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, utilio.Closer, error) GetIndex(noCache bool, maxIndexSize int64) (*Index, error) GetTags(chart string, noCache bool) ([]string, error) TestHelmOCI() (bool, error) @@ -61,7 +61,7 @@ func WithIndexCache(indexCache indexCache) ClientOpts { } } -func WithChartPaths(chartPaths argoio.TempPaths) ClientOpts { +func WithChartPaths(chartPaths utilio.TempPaths) ClientOpts { return func(c *nativeHelmChart) { c.chartCachePaths = chartPaths } @@ -79,7 +79,7 @@ func NewClientWithLock(repoURL string, creds Creds, repoLock sync.KeyLock, enabl enableOci: enableOci, proxy: proxy, noProxy: noProxy, - chartCachePaths: argoio.NewRandomizedTempPaths(os.TempDir()), + chartCachePaths: utilio.NewRandomizedTempPaths(os.TempDir()), } for i := range opts { opts[i](c) @@ -90,7 +90,7 @@ func NewClientWithLock(repoURL string, creds Creds, repoLock sync.KeyLock, enabl var _ Client = &nativeHelmChart{} type nativeHelmChart struct { - chartCachePaths argoio.TempPaths + chartCachePaths utilio.TempPaths repoURL string creds Creds repoLock sync.KeyLock @@ -138,7 +138,7 @@ func untarChart(tempDir string, cachedChartPath string, manifestMaxExtractedSize return files.Untgz(tempDir, reader, manifestMaxExtractedSize, false) } -func (c *nativeHelmChart) ExtractChart(chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, argoio.Closer, error) { +func (c *nativeHelmChart) ExtractChart(chart string, version string, passCredentials bool, manifestMaxExtractedSize int64, disableManifestMaxExtractedSize bool) (string, utilio.Closer, error) { // always use Helm V3 since we don't have chart content to determine correct Helm version helmCmd, err := NewCmdWithVersion("", c.enableOci, c.proxy, c.noProxy) if err != nil { @@ -230,7 +230,7 @@ func (c *nativeHelmChart) ExtractChart(chart string, version string, passCredent _ = os.RemoveAll(tempDir) return "", nil, fmt.Errorf("error untarring chart: %w", err) } - return path.Join(tempDir, normalizeChartName(chart)), argoio.NewCloser(func() error { + return path.Join(tempDir, normalizeChartName(chart)), utilio.NewCloser(func() error { return os.RemoveAll(tempDir) }), nil } diff --git a/util/helm/client_test.go b/util/helm/client_test.go index 06b36e916b..5d7bf6281a 100644 --- a/util/helm/client_test.go +++ b/util/helm/client_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" "github.com/argoproj/argo-cd/v3/util/workloadidentity/mocks" ) @@ -86,7 +86,7 @@ func Test_nativeHelmChart_ExtractChart(t *testing.T) { client := NewClient("https://argoproj.github.io/argo-helm", HelmCreds{}, false, "", "") path, closer, err := client.ExtractChart("argo-cd", "0.7.1", false, math.MaxInt64, true) require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) info, err := os.Stat(path) require.NoError(t, err) assert.True(t, info.IsDir()) @@ -102,7 +102,7 @@ func Test_nativeHelmChart_ExtractChart_insecure(t *testing.T) { client := NewClient("https://argoproj.github.io/argo-helm", HelmCreds{InsecureSkipVerify: true}, false, "", "") path, closer, err := client.ExtractChart("argo-cd", "0.7.1", false, math.MaxInt64, true) require.NoError(t, err) - defer io.Close(closer) + defer utilio.Close(closer) info, err := os.Stat(path) require.NoError(t, err) assert.True(t, info.IsDir()) diff --git a/util/helm/cmd.go b/util/helm/cmd.go index 81d25b17ac..0300b19693 100644 --- a/util/helm/cmd.go +++ b/util/helm/cmd.go @@ -14,7 +14,7 @@ import ( "github.com/argoproj/argo-cd/v3/common" executil "github.com/argoproj/argo-cd/v3/util/exec" - argoio "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" pathutil "github.com/argoproj/argo-cd/v3/util/io/path" "github.com/argoproj/argo-cd/v3/util/proxy" ) @@ -101,7 +101,7 @@ func (c *Cmd) RegistryLogin(repo string, creds Creds) (string, error) { if err != nil { return "", fmt.Errorf("failed to write certificate data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--cert-file", filePath) } @@ -110,7 +110,7 @@ func (c *Cmd) RegistryLogin(repo string, creds Creds) (string, error) { if err != nil { return "", fmt.Errorf("failed to write key data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--key-file", filePath) } @@ -202,7 +202,7 @@ func (c *Cmd) RepoAdd(name string, url string, opts Creds, passCredentials bool) return out, err } -func writeToTmp(data []byte) (string, argoio.Closer, error) { +func writeToTmp(data []byte) (string, utilio.Closer, error) { file, err := os.CreateTemp("", "") if err != nil { return "", nil, fmt.Errorf("failed to create temporary file: %w", err) @@ -220,7 +220,7 @@ func writeToTmp(data []byte) (string, argoio.Closer, error) { }).Errorf("error closing file %q: %v", file.Name(), err) } }() - return file.Name(), argoio.NewCloser(func() error { + return file.Name(), utilio.NewCloser(func() error { return os.RemoveAll(file.Name()) }), nil } @@ -255,7 +255,7 @@ func (c *Cmd) Fetch(repo, chartName, version, destination string, creds Creds, p if err != nil { return "", fmt.Errorf("failed to write certificate data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--cert-file", filePath) } if len(creds.GetKeyData()) > 0 { @@ -263,7 +263,7 @@ func (c *Cmd) Fetch(repo, chartName, version, destination string, creds Creds, p if err != nil { return "", fmt.Errorf("failed to write key data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--key-file", filePath) } if passCredentials { @@ -293,7 +293,7 @@ func (c *Cmd) PullOCI(repo string, chart string, version string, destination str if err != nil { return "", fmt.Errorf("failed to write certificate data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--cert-file", filePath) } @@ -302,7 +302,7 @@ func (c *Cmd) PullOCI(repo string, chart string, version string, destination str if err != nil { return "", fmt.Errorf("failed to write key data to temporary file: %w", err) } - defer argoio.Close(closer) + defer utilio.Close(closer) args = append(args, "--key-file", filePath) } diff --git a/util/kube/portforwarder.go b/util/kube/portforwarder.go index 5b77ff2ce7..9a0698abd4 100644 --- a/util/kube/portforwarder.go +++ b/util/kube/portforwarder.go @@ -18,7 +18,7 @@ import ( cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/util/podutils" - "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) func selectPodForPortForward(clientSet kubernetes.Interface, namespace string, podSelectors ...string) (*corev1.Pod, error) { @@ -99,7 +99,7 @@ func PortForward(targetPort int, namespace string, overrides *clientcmd.ConfigOv return -1, err } port := ln.Addr().(*net.TCPAddr).Port - io.Close(ln) + utilio.Close(ln) forwarder, err := portforward.NewOnAddresses(dialer, []string{"localhost"}, []string{fmt.Sprintf("%d:%d", port, targetPort)}, context.Background().Done(), readyChan, out, errOut) if err != nil { return -1, err diff --git a/util/session/state.go b/util/session/state.go index 5e48829236..ff121733b6 100644 --- a/util/session/state.go +++ b/util/session/state.go @@ -9,7 +9,7 @@ import ( "github.com/redis/go-redis/v9" log "github.com/sirupsen/logrus" - util "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) const ( @@ -55,7 +55,7 @@ func (storage *userStateStorage) Init(ctx context.Context) { func (storage *userStateStorage) watchRevokedTokens(ctx context.Context) { pubsub := storage.redis.Subscribe(ctx, newRevokedTokenKey) - defer util.Close(pubsub) + defer utilio.Close(pubsub) ch := pubsub.Channel() for {