chore(cmd): unify CLI names via common constants and simplify main dispatch (#24486)

Signed-off-by: jaehanbyun <awbrg789@naver.com>
This commit is contained in:
jaehanbyun
2026-02-15 20:03:39 +09:00
committed by GitHub
parent b0b9658e04
commit b48ed499c0
20 changed files with 47 additions and 71 deletions

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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())

View File

@@ -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,

View File

@@ -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")

View File

@@ -1,6 +0,0 @@
package commands
const (
// cliName is the name of the CLI
cliName = "argocd-server"
)

View File

@@ -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 <ARGOCD_SERVER_ADDRESS>
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) {

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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{