diff --git a/cmd/argocd-application-controller/commands/argocd_application_controller.go b/cmd/argocd-application-controller/commands/argocd_application_controller.go index 16a179c1b6..ed443ed9da 100644 --- a/cmd/argocd-application-controller/commands/argocd_application_controller.go +++ b/cmd/argocd-application-controller/commands/argocd_application_controller.go @@ -41,8 +41,6 @@ import ( ) const ( - // CLIName is the name of the CLI - cliName = common.ApplicationController // Default time in seconds for application resync period defaultAppResyncPeriod = 120 // Default time in seconds for application resync period jitter @@ -99,7 +97,7 @@ func NewCommand() *cobra.Command { hydratorEnabled bool ) command := cobra.Command{ - Use: cliName, + Use: common.CommandApplicationController, Short: "Run ArgoCD Application Controller", Long: "ArgoCD application controller is a Kubernetes controller that continuously monitors running applications and compares the current, live state against the desired target state (as specified in the repo). This command runs Application Controller in the foreground. It can be configured by following options.", DisableAutoGenTag: true, diff --git a/cmd/argocd-applicationset-controller/commands/applicationset_controller.go b/cmd/argocd-applicationset-controller/commands/applicationset_controller.go index ccfbbc626b..a9edbab97c 100644 --- a/cmd/argocd-applicationset-controller/commands/applicationset_controller.go +++ b/cmd/argocd-applicationset-controller/commands/applicationset_controller.go @@ -49,10 +49,6 @@ import ( var gitSubmoduleEnabled = env.ParseBoolFromEnv(common.EnvGitSubmoduleEnabled, true) -const ( - cliName = common.ApplicationSetController -) - func NewCommand() *cobra.Command { var ( clientConfig clientcmd.ClientConfig @@ -87,7 +83,7 @@ func NewCommand() *cobra.Command { _ = clientgoscheme.AddToScheme(scheme) _ = appv1alpha1.AddToScheme(scheme) command := cobra.Command{ - Use: cliName, + Use: common.CommandApplicationSetController, Short: "Starts Argo CD ApplicationSet controller", DisableAutoGenTag: true, RunE: func(c *cobra.Command, _ []string) error { diff --git a/cmd/argocd-cmp-server/commands/argocd_cmp_server.go b/cmd/argocd-cmp-server/commands/argocd_cmp_server.go index efb4960fae..85f827b814 100644 --- a/cmd/argocd-cmp-server/commands/argocd_cmp_server.go +++ b/cmd/argocd-cmp-server/commands/argocd_cmp_server.go @@ -18,11 +18,6 @@ import ( traceutil "github.com/argoproj/argo-cd/v3/util/trace" ) -const ( - // CLIName is the name of the CLI - cliName = "argocd-cmp-server" -) - func NewCommand() *cobra.Command { var ( configFilePath string @@ -32,7 +27,7 @@ func NewCommand() *cobra.Command { otlpAttrs []string ) command := cobra.Command{ - Use: cliName, + Use: common.CommandCMPServer, Short: "Run ArgoCD ConfigManagementPlugin Server", Long: "ArgoCD ConfigManagementPlugin Server is an internal service which runs as sidecar container in reposerver deployment. The following configuration options are available:", DisableAutoGenTag: true, diff --git a/cmd/argocd-commit-server/commands/argocd_commit_server.go b/cmd/argocd-commit-server/commands/argocd_commit_server.go index 4d08736364..f973264a22 100644 --- a/cmd/argocd-commit-server/commands/argocd_commit_server.go +++ b/cmd/argocd-commit-server/commands/argocd_commit_server.go @@ -35,7 +35,7 @@ func NewCommand() *cobra.Command { metricsHost string ) command := &cobra.Command{ - Use: "argocd-commit-server", + Use: common.CommandCommitServer, Short: "Run Argo CD Commit Server", Long: "Argo CD Commit Server is an internal service which commits and pushes hydrated manifests to git. This command runs Commit Server in the foreground.", RunE: func(cmd *cobra.Command, _ []string) error { diff --git a/cmd/argocd-dex/commands/argocd_dex.go b/cmd/argocd-dex/commands/argocd_dex.go index b27aed6b7b..23fa983d56 100644 --- a/cmd/argocd-dex/commands/argocd_dex.go +++ b/cmd/argocd-dex/commands/argocd_dex.go @@ -25,13 +25,9 @@ import ( "github.com/argoproj/argo-cd/v3/util/tls" ) -const ( - cliName = "argocd-dex" -) - func NewCommand() *cobra.Command { command := &cobra.Command{ - Use: cliName, + Use: common.CommandDex, Short: "argocd-dex tools used by Argo CD", Long: "argocd-dex has internal utility tools used by Argo CD", DisableAutoGenTag: true, 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 01c7c95f99..298c9e070e 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 @@ -9,20 +9,16 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "github.com/argoproj/argo-cd/v3/common" "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" utilio "github.com/argoproj/argo-cd/v3/util/io" ) -const ( - // cliName is the name of the CLI - cliName = "argocd-git-ask-pass" -) - func NewCommand() *cobra.Command { command := cobra.Command{ - Use: cliName, + Use: common.CommandGitAskPass, Short: "Argo CD git credential helper", DisableAutoGenTag: true, Run: func(c *cobra.Command, _ []string) { diff --git a/cmd/argocd-k8s-auth/commands/argocd_k8s_auth.go b/cmd/argocd-k8s-auth/commands/argocd_k8s_auth.go index 4049d5dc6d..4e1d58f8b7 100644 --- a/cmd/argocd-k8s-auth/commands/argocd_k8s_auth.go +++ b/cmd/argocd-k8s-auth/commands/argocd_k8s_auth.go @@ -2,15 +2,13 @@ package commands import ( "github.com/spf13/cobra" -) -const ( - cliName = "argocd-k8s-auth" + "github.com/argoproj/argo-cd/v3/common" ) func NewCommand() *cobra.Command { command := &cobra.Command{ - Use: cliName, + Use: common.CommandK8sAuth, Short: "argocd-k8s-auth a set of commands to generate k8s auth token", DisableAutoGenTag: true, Run: func(c *cobra.Command, args []string) { diff --git a/cmd/argocd-notification/commands/controller.go b/cmd/argocd-notification/commands/argocd_notification.go similarity index 99% rename from cmd/argocd-notification/commands/controller.go rename to cmd/argocd-notification/commands/argocd_notification.go index df5733ffaa..e59579d811 100644 --- a/cmd/argocd-notification/commands/controller.go +++ b/cmd/argocd-notification/commands/argocd_notification.go @@ -52,7 +52,7 @@ func NewCommand() *cobra.Command { selfServiceNotificationEnabled bool ) command := cobra.Command{ - Use: "controller", + Use: common.CommandNotifications, Short: "Starts Argo CD Notifications controller", RunE: func(_ *cobra.Command, _ []string) error { ctx, cancel := context.WithCancel(context.Background()) diff --git a/cmd/argocd-repo-server/commands/argocd_repo_server.go b/cmd/argocd-repo-server/commands/argocd_repo_server.go index 4203aa9a8c..5ee8a40fa8 100644 --- a/cmd/argocd-repo-server/commands/argocd_repo_server.go +++ b/cmd/argocd-repo-server/commands/argocd_repo_server.go @@ -39,11 +39,6 @@ import ( traceutil "github.com/argoproj/argo-cd/v3/util/trace" ) -const ( - // CLIName is the name of the CLI - cliName = "argocd-repo-server" -) - var ( gnuPGSourcePath = env.StringFromEnv(common.EnvGPGDataPath, "/app/config/gpg/source") pauseGenerationAfterFailedGenerationAttempts = env.ParseNumFromEnv(common.EnvPauseGenerationAfterFailedAttempts, 3, 0, math.MaxInt32) @@ -85,7 +80,7 @@ func NewCommand() *cobra.Command { enableBuiltinGitConfig bool ) command := cobra.Command{ - Use: cliName, + Use: common.CommandRepoServer, Short: "Run ArgoCD Repository Server", Long: "ArgoCD Repository Server is an internal service which maintains a local cache of the Git repository holding the application manifests, and is responsible for generating and returning the Kubernetes manifests. This command runs Repository Server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, diff --git a/cmd/argocd-server/commands/argocd_server.go b/cmd/argocd-server/commands/argocd_server.go index db01b05905..70346c0c45 100644 --- a/cmd/argocd-server/commands/argocd_server.go +++ b/cmd/argocd-server/commands/argocd_server.go @@ -101,7 +101,7 @@ func NewCommand() *cobra.Command { enableK8sEvent []string ) command := &cobra.Command{ - Use: cliName, + Use: common.CommandServer, Short: "Run the ArgoCD API server", Long: "The API server is a gRPC/REST server which exposes the API consumed by the Web UI, CLI, and CI/CD systems. This command runs API server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, @@ -307,7 +307,7 @@ func NewCommand() *cobra.Command { command.Flags().BoolVar(&disableAuth, "disable-auth", env.ParseBoolFromEnv("ARGOCD_SERVER_DISABLE_AUTH", false), "Disable client authentication") command.Flags().StringVar(&contentTypes, "api-content-types", env.StringFromEnv("ARGOCD_API_CONTENT_TYPES", "application/json", env.StringFromEnvOpts{AllowEmpty: true}), "Semicolon separated list of allowed content types for non GET api requests. Any content type is allowed if empty.") command.Flags().BoolVar(&enableGZip, "enable-gzip", env.ParseBoolFromEnv("ARGOCD_SERVER_ENABLE_GZIP", true), "Enable GZIP compression") - command.AddCommand(cli.NewVersionCmd(cliName)) + command.AddCommand(cli.NewVersionCmd(common.CommandServer)) command.Flags().StringVar(&listenHost, "address", env.StringFromEnv("ARGOCD_SERVER_LISTEN_ADDRESS", common.DefaultAddressAPIServer), "Listen on given address") command.Flags().IntVar(&listenPort, "port", common.DefaultPortAPIServer, "Listen on given port") command.Flags().StringVar(&metricsHost, env.StringFromEnv("ARGOCD_SERVER_METRICS_LISTEN_ADDRESS", "metrics-address"), common.DefaultAddressAPIServerMetrics, "Listen for metrics on given address") diff --git a/cmd/argocd-server/commands/common.go b/cmd/argocd-server/commands/common.go deleted file mode 100644 index 3d7848107d..0000000000 --- a/cmd/argocd-server/commands/common.go +++ /dev/null @@ -1,6 +0,0 @@ -package commands - -const ( - // cliName is the name of the CLI - cliName = "argocd-server" -) diff --git a/cmd/argocd/commands/cluster.go b/cmd/argocd/commands/cluster.go index b887197527..7b5ade4d89 100644 --- a/cmd/argocd/commands/cluster.go +++ b/cmd/argocd/commands/cluster.go @@ -91,7 +91,7 @@ func NewClusterAddCommand(clientOpts *argocdclient.ClientOptions, pathOpts *clie ) command := &cobra.Command{ Use: "add CONTEXT", - Short: cliName + " cluster add CONTEXT", + Short: common.CommandCLI + " cluster add CONTEXT", Run: func(c *cobra.Command, args []string) { ctx := c.Context() @@ -549,7 +549,7 @@ argocd cluster list -o server func NewClusterRotateAuthCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { command := &cobra.Command{ Use: "rotate-auth SERVER/NAME", - Short: cliName + " cluster rotate-auth SERVER/NAME", + Short: common.CommandCLI + " cluster rotate-auth SERVER/NAME", Example: `argocd cluster rotate-auth https://12.34.567.89 argocd cluster rotate-auth cluster-name`, Run: func(c *cobra.Command, args []string) { diff --git a/cmd/argocd/commands/common.go b/cmd/argocd/commands/common.go index 9b924e063b..418bda0c7b 100644 --- a/cmd/argocd/commands/common.go +++ b/cmd/argocd/commands/common.go @@ -9,8 +9,6 @@ import ( ) const ( - cliName = "argocd" - // DefaultSSOLocalPort is the localhost port to listen on for the temporary web server performing // the OAuth2 login flow. DefaultSSOLocalPort = 8085 diff --git a/cmd/argocd/commands/root.go b/cmd/argocd/commands/root.go index c4c82cd4d0..0b82e71286 100644 --- a/cmd/argocd/commands/root.go +++ b/cmd/argocd/commands/root.go @@ -37,7 +37,7 @@ func NewCommand() *cobra.Command { ) command := &cobra.Command{ - Use: cliName, + Use: common.CommandCLI, Short: "argocd controls a Argo CD server", Run: func(c *cobra.Command, args []string) { c.HelpFunc()(c, args) diff --git a/cmd/argocd/commands/version.go b/cmd/argocd/commands/version.go index 47766d0240..d7e162bc5e 100644 --- a/cmd/argocd/commands/version.go +++ b/cmd/argocd/commands/version.go @@ -48,7 +48,7 @@ func NewVersionCmd(clientOpts *argocdclient.ClientOptions, serverVersion *versio v := make(map[string]any) if short { - v["client"] = map[string]string{cliName: cv.Version} + v["client"] = map[string]string{common.CommandCLI: cv.Version} } else { v["client"] = cv } @@ -103,7 +103,7 @@ func getServerVersion(ctx context.Context, options *argocdclient.ClientOptions, } func printClientVersion(version *common.Version, short bool) string { - output := fmt.Sprintf("%s: %s\n", cliName, version) + output := fmt.Sprintf("%s: %s\n", common.CommandCLI, version) if short { return output } diff --git a/cmd/main.go b/cmd/main.go index 0d836179dc..0af55af6b8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,6 +20,7 @@ import ( reposerver "github.com/argoproj/argo-cd/v3/cmd/argocd-repo-server/commands" apiserver "github.com/argoproj/argo-cd/v3/cmd/argocd-server/commands" cli "github.com/argoproj/argo-cd/v3/cmd/argocd/commands" + "github.com/argoproj/argo-cd/v3/common" "github.com/argoproj/argo-cd/v3/util/log" ) @@ -43,33 +44,34 @@ func main() { isArgocdCLI := false switch binaryName { - case "argocd", "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe": + case common.CommandCLI: command = cli.NewCommand() isArgocdCLI = true - case "argocd-server": + case common.CommandServer: command = apiserver.NewCommand() - case "argocd-application-controller": + case common.CommandApplicationController: command = appcontroller.NewCommand() - case "argocd-repo-server": + case common.CommandRepoServer: command = reposerver.NewCommand() - case "argocd-cmp-server": + case common.CommandCMPServer: command = cmpserver.NewCommand() isArgocdCLI = true - case "argocd-commit-server": + case common.CommandCommitServer: command = commitserver.NewCommand() - case "argocd-dex": + case common.CommandDex: command = dex.NewCommand() - case "argocd-notifications": + case common.CommandNotifications: command = notification.NewCommand() - case "argocd-git-ask-pass": + case common.CommandGitAskPass: command = gitaskpass.NewCommand() isArgocdCLI = true - case "argocd-applicationset-controller": + case common.CommandApplicationSetController: command = applicationset.NewCommand() - case "argocd-k8s-auth": + case common.CommandK8sAuth: command = k8sauth.NewCommand() isArgocdCLI = true default: + // "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe" are also valid binary names command = cli.NewCommand() isArgocdCLI = true } diff --git a/common/common.go b/common/common.go index 8d5d1f2bd1..262a4fbd2b 100644 --- a/common/common.go +++ b/common/common.go @@ -17,10 +17,19 @@ import ( "k8s.io/client-go/kubernetes" ) -// Component names +// Argo CD component names const ( - ApplicationController = "argocd-application-controller" - ApplicationSetController = "argocd-applicationset-controller" + CommandCLI = "argocd" + CommandApplicationController = "argocd-application-controller" + CommandApplicationSetController = "argocd-applicationset-controller" + CommandServer = "argocd-server" + CommandCMPServer = "argocd-cmp-server" + CommandCommitServer = "argocd-commit-server" + CommandGitAskPass = "argocd-git-ask-pass" + CommandNotifications = "argocd-notifications" + CommandK8sAuth = "argocd-k8s-auth" + CommandDex = "argocd-dex" + CommandRepoServer = "argocd-repo-server" ) // Default service addresses and URLS of Argo CD internal services @@ -108,7 +117,6 @@ const ( // Argo CD application related constants const ( - // ArgoCDAdminUsername is the username of the 'admin' user ArgoCDAdminUsername = "admin" // ArgoCDUserAgentName is the default user-agent name used by the gRPC API client library and grpc-gateway diff --git a/controller/appcontroller.go b/controller/appcontroller.go index 4865113db5..04ad9a48bf 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -206,7 +206,7 @@ func NewApplicationController( statusRefreshJitter: appResyncJitter, refreshRequestedApps: make(map[string]CompareWith), refreshRequestedAppsMutex: &sync.Mutex{}, - auditLogger: argo.NewAuditLogger(kubeClientset, common.ApplicationController, enableK8sEvent), + auditLogger: argo.NewAuditLogger(kubeClientset, common.CommandApplicationController, enableK8sEvent), settingsMgr: settingsMgr, selfHealTimeout: selfHealTimeout, selfHealBackoff: selfHealBackoff, diff --git a/controller/metrics/metrics.go b/controller/metrics/metrics.go index cfd81c2740..1652af7f95 100644 --- a/controller/metrics/metrics.go +++ b/controller/metrics/metrics.go @@ -300,12 +300,12 @@ func (m *MetricsServer) IncKubernetesRequest(app *argoappv1.Application, server, } func (m *MetricsServer) IncRedisRequest(failed bool) { - m.redisRequestCounter.WithLabelValues(m.hostname, common.ApplicationController, strconv.FormatBool(failed)).Inc() + m.redisRequestCounter.WithLabelValues(m.hostname, common.CommandApplicationController, strconv.FormatBool(failed)).Inc() } // ObserveRedisRequestDuration observes redis request duration func (m *MetricsServer) ObserveRedisRequestDuration(duration time.Duration) { - m.redisRequestHistogram.WithLabelValues(m.hostname, common.ApplicationController).Observe(duration.Seconds()) + m.redisRequestHistogram.WithLabelValues(m.hostname, common.CommandApplicationController).Observe(duration.Seconds()) } // ObserveResourceEventsProcessingDuration observes resource events processing duration diff --git a/util/db/db_test.go b/util/db/db_test.go index 50d2e25369..145aecb91e 100644 --- a/util/db/db_test.go +++ b/util/db/db_test.go @@ -566,7 +566,7 @@ func TestGetApplicationControllerReplicas(t *testing.T) { expectedReplicas = int32(3) clientset = getClientset(&appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ - Name: common.ApplicationController, + Name: common.CommandApplicationController, Namespace: testNamespace, }, Spec: appsv1.DeploymentSpec{