From 3faa5da673707c8a9f4dc067da3d185bbdd1c6a5 Mon Sep 17 00:00:00 2001 From: jannfis Date: Fri, 24 May 2019 21:14:22 +0200 Subject: [PATCH 1/9] Add --listen-port option to argocd-server CLI This option lets you specifiy the TCP port that argocd-server should use to listen for incoming connections. Non-breaking: If not specified, the default value of 8080 will be used as ever since. --- cmd/argocd-server/commands/root.go | 5 ++++- common/common.go | 16 +++++++++++----- server/server.go | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/argocd-server/commands/root.go b/cmd/argocd-server/commands/root.go index 19fa1636e904f..b99f34bd2fef7 100644 --- a/cmd/argocd-server/commands/root.go +++ b/cmd/argocd-server/commands/root.go @@ -23,6 +23,7 @@ import ( func NewCommand() *cobra.Command { var ( insecure bool + listenPort int logLevel string glogLevel int clientConfig clientcmd.ClientConfig @@ -61,6 +62,7 @@ func NewCommand() *cobra.Command { argoCDOpts := server.ArgoCDServerOpts{ Insecure: insecure, + ListenPort: listenPort, Namespace: namespace, StaticAssetsDir: staticAssetsDir, BaseHRef: baseHRef, @@ -81,7 +83,7 @@ func NewCommand() *cobra.Command { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) argocd := server.NewServer(ctx, argoCDOpts) - argocd.Run(ctx, common.PortAPIServer) + argocd.Run(ctx, listenPort) cancel() } }, @@ -97,6 +99,7 @@ func NewCommand() *cobra.Command { command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address") command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication") command.AddCommand(cli.NewVersionCmd(cliName)) + command.Flags().IntVar(&listenPort, "listen-port", common.PortAPIServer, "Listen on given port") tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command) cacheSrc = cache.AddCacheFlagsToCmd(command) return command diff --git a/common/common.go b/common/common.go index 873f2190bd2ea..972d143b58b7e 100644 --- a/common/common.go +++ b/common/common.go @@ -18,13 +18,19 @@ const ( ) const ( - PortAPIServer = 8080 - PortRepoServer = 8081 - PortArgoCDMetrics = 8082 - PortArgoCDAPIServerMetrics = 8083 - PortRepoServerMetrics = 8084 + DefaultPortAPIServer = 8080 + DefaultPortRepoServer = 8081 + DefaultPortArgoCDMetrics = 8082 + DefaultPortArgoCDAPIServerMetrics = 8083 + DefaultPortRepoServerMetrics = 8084 ) +var PortAPIServer = DefaultPortAPIServer +var PortRepoServer = DefaultPortRepoServer +var PortArgoCDMetrics = DefaultPortArgoCDMetrics +var PortArgoCDAPIServerMetrics = DefaultPortArgoCDAPIServerMetrics +var PortRepoServerMetrics = DefaultPortRepoServerMetrics + // Argo CD application related constants const ( // KubernetesInternalAPIServerAddr is address of the k8s API server when accessing internal to the cluster diff --git a/server/server.go b/server/server.go index da9f2d090fcdf..86b8b33c0ed2d 100644 --- a/server/server.go +++ b/server/server.go @@ -122,6 +122,7 @@ type ArgoCDServer struct { type ArgoCDServerOpts struct { DisableAuth bool Insecure bool + ListenPort int Namespace string DexServerAddr string StaticAssetsDir string From 5a7e0622254d55220757e08d4830437c94a96202 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Sat, 25 May 2019 13:12:59 +0200 Subject: [PATCH 2/9] Add --listener-port and --metrics-port Non-breaking: Will use the standard ports as default if parameters are not specified. --- cmd/argocd-repo-server/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/argocd-repo-server/main.go b/cmd/argocd-repo-server/main.go index 32c561dc216f9..d9aeccdd1cc06 100644 --- a/cmd/argocd-repo-server/main.go +++ b/cmd/argocd-repo-server/main.go @@ -31,6 +31,8 @@ func newCommand() *cobra.Command { var ( logLevel string parallelismLimit int64 + listenPort int + metricsPort int cacheSrc func() (*cache.Cache, error) tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error) ) @@ -49,11 +51,11 @@ func newCommand() *cobra.Command { server, err := reposerver.NewServer(git.NewFactory(), cache, tlsConfigCustomizer, parallelismLimit) errors.CheckError(err) grpc := server.CreateGRPC() - listener, err := net.Listen("tcp", fmt.Sprintf(":%d", common.PortRepoServer)) + listener, err := net.Listen("tcp", fmt.Sprintf(":%d", listenPort)) errors.CheckError(err) http.Handle("/metrics", promhttp.Handler()) - go func() { errors.CheckError(http.ListenAndServe(fmt.Sprintf(":%d", common.PortRepoServerMetrics), nil)) }() + go func() { errors.CheckError(http.ListenAndServe(fmt.Sprintf(":%d", metricsPort), nil)) }() log.Infof("argocd-repo-server %s serving on %s", argocd.GetVersion(), listener.Addr()) stats.RegisterStackDumper() @@ -67,6 +69,8 @@ func newCommand() *cobra.Command { command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().Int64Var(¶llelismLimit, "parallelismlimit", 0, "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.") + command.Flags().IntVar(&listenPort, "listen-port", common.DefaultPortRepoServer, "Listen on given port for incoming connections") + command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortRepoServerMetrics, "Start metrics server on given port") tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command) cacheSrc = cache.AddCacheFlagsToCmd(&command) return &command From c1fe4c957611bcbf59b9845f06d7777c505e1b66 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Sun, 26 May 2019 20:14:55 +0200 Subject: [PATCH 3/9] Add --metrics-port option to controller --- cmd/argocd-application-controller/main.go | 5 ++++- controller/appcontroller.go | 3 ++- controller/appcontroller_test.go | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/argocd-application-controller/main.go b/cmd/argocd-application-controller/main.go index e09a2710255f5..d27b055710e07 100644 --- a/cmd/argocd-application-controller/main.go +++ b/cmd/argocd-application-controller/main.go @@ -45,6 +45,7 @@ func newCommand() *cobra.Command { operationProcessors int logLevel string glogLevel int + metricsPort int cacheSrc func() (*cache.Cache, error) ) var command = cobra.Command{ @@ -81,7 +82,8 @@ func newCommand() *cobra.Command { appClient, repoClientset, cache, - resyncDuration) + resyncDuration, + metricsPort) errors.CheckError(err) log.Infof("Application Controller (version: %s) starting (namespace: %s)", argocd.GetVersion(), namespace) @@ -104,6 +106,7 @@ func newCommand() *cobra.Command { command.Flags().IntVar(&operationProcessors, "operation-processors", 1, "Number of application operation processors") command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level") + command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDMetrics, "Start metrics server on given port") cacheSrc = cache.AddCacheFlagsToCmd(&command) return &command } diff --git a/controller/appcontroller.go b/controller/appcontroller.go index 61a3c400343bf..f654dbf795679 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -86,6 +86,7 @@ func NewApplicationController( repoClientset reposerver.Clientset, argoCache *argocache.Cache, appResyncPeriod time.Duration, + metricsPort int, ) (*ApplicationController, error) { db := db.NewDB(namespace, settingsMgr, kubeClientset) settings, err := settingsMgr.GetSettings() @@ -112,7 +113,7 @@ func NewApplicationController( } appInformer, appLister := ctrl.newApplicationInformerAndLister() projInformer := v1alpha1.NewAppProjectInformer(applicationClientset, namespace, appResyncPeriod, cache.Indexers{}) - metricsAddr := fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDMetrics) + metricsAddr := fmt.Sprintf("0.0.0.0:%d", metricsPort) ctrl.metricsServer = metrics.NewMetricsServer(metricsAddr, appLister) stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settings, kubectlCmd, ctrl.metricsServer, ctrl.handleAppUpdated) appStateManager := NewAppStateManager(db, applicationClientset, repoClientset, namespace, kubectlCmd, ctrl.settings, stateCache, projInformer, ctrl.metricsServer) diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index 9c1814baf5328..85cbf59a8d889 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -76,6 +76,7 @@ func newFakeController(data *fakeData) *ApplicationController { &mockRepoClientset, utilcache.NewCache(utilcache.NewInMemoryCache(1*time.Hour)), time.Minute, + 8082, ) if err != nil { panic(err) From 65d140b326895817243046a0e11474d001349b59 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Sun, 26 May 2019 20:15:48 +0200 Subject: [PATCH 4/9] Add --metrics-port option to argocd-server --- cmd/argocd-server/commands/root.go | 7 +++++-- server/server.go | 9 +++++---- server/server_test.go | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/argocd-server/commands/root.go b/cmd/argocd-server/commands/root.go index b99f34bd2fef7..1ed10f62e2ff2 100644 --- a/cmd/argocd-server/commands/root.go +++ b/cmd/argocd-server/commands/root.go @@ -24,6 +24,7 @@ func NewCommand() *cobra.Command { var ( insecure bool listenPort int + metricsPort int logLevel string glogLevel int clientConfig clientcmd.ClientConfig @@ -63,6 +64,7 @@ func NewCommand() *cobra.Command { argoCDOpts := server.ArgoCDServerOpts{ Insecure: insecure, ListenPort: listenPort, + MetricsPort: metricsPort, Namespace: namespace, StaticAssetsDir: staticAssetsDir, BaseHRef: baseHRef, @@ -83,7 +85,7 @@ func NewCommand() *cobra.Command { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) argocd := server.NewServer(ctx, argoCDOpts) - argocd.Run(ctx, listenPort) + argocd.Run(ctx, listenPort, metricsPort) cancel() } }, @@ -99,7 +101,8 @@ func NewCommand() *cobra.Command { command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address") command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication") command.AddCommand(cli.NewVersionCmd(cliName)) - command.Flags().IntVar(&listenPort, "listen-port", common.PortAPIServer, "Listen on given port") + command.Flags().IntVar(&listenPort, "listen-port", common.DefaultPortAPIServer, "Listen on given port") + command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDAPIServerMetrics, "Start metrics on given port") tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command) cacheSrc = cache.AddCacheFlagsToCmd(command) return command diff --git a/server/server.go b/server/server.go index 86b8b33c0ed2d..c03c8ea5e53e8 100644 --- a/server/server.go +++ b/server/server.go @@ -123,6 +123,7 @@ type ArgoCDServerOpts struct { DisableAuth bool Insecure bool ListenPort int + MetricsPort int Namespace string DexServerAddr string StaticAssetsDir string @@ -190,7 +191,7 @@ func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer { // We use k8s.io/code-generator/cmd/go-to-protobuf to generate the .proto files from the API types. // k8s.io/ go-to-protobuf uses protoc-gen-gogo, which comes from gogo/protobuf (a fork of // golang/protobuf). -func (a *ArgoCDServer) Run(ctx context.Context, port int) { +func (a *ArgoCDServer) Run(ctx context.Context, port int, metricsPort int) { grpcS := a.newGRPCServer() grpcWebS := grpcweb.WrapServer(grpcS) var httpS *http.Server @@ -201,7 +202,7 @@ func (a *ArgoCDServer) Run(ctx context.Context, port int) { } else { httpS = a.newHTTPServer(ctx, port, grpcWebS) } - metricsServ := newAPIServerMetricsServer() + metricsServ := newAPIServerMetricsServer(metricsPort) // Start listener var conn net.Listener @@ -619,11 +620,11 @@ func indexFilePath(srcPath string, baseHRef string) (string, error) { } // newAPIServerMetricsServer returns HTTP server which serves prometheus metrics on gRPC requests -func newAPIServerMetricsServer() *http.Server { +func newAPIServerMetricsServer(port int) *http.Server { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) return &http.Server{ - Addr: fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDAPIServerMetrics), + Addr: fmt.Sprintf("0.0.0.0:%d", port), Handler: mux, } } diff --git a/server/server_test.go b/server/server_test.go index 5052a813f8d17..3c9c41be08fd1 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -334,9 +334,11 @@ func TestUserAgent(t *testing.T) { defer cancelInformer() port, err := test.GetFreePort() assert.NoError(t, err) + metricsport, err := test.GetFreePort() + assert.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go s.Run(ctx, port) + go s.Run(ctx, port, metricsport) err = test.WaitForPortListen(fmt.Sprintf("127.0.0.1:%d", port), 10*time.Second) assert.NoError(t, err) From 974ca066eaee1e3c5170d80174f02333045a4a90 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Sun, 26 May 2019 20:16:19 +0200 Subject: [PATCH 5/9] Remove old unused variables --- common/common.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/common/common.go b/common/common.go index 972d143b58b7e..47297c8d1f489 100644 --- a/common/common.go +++ b/common/common.go @@ -17,6 +17,7 @@ const ( ArgoCDRBACConfigMapName = "argocd-rbac-cm" ) +// Default listener ports for ArgoCD components const ( DefaultPortAPIServer = 8080 DefaultPortRepoServer = 8081 @@ -25,12 +26,6 @@ const ( DefaultPortRepoServerMetrics = 8084 ) -var PortAPIServer = DefaultPortAPIServer -var PortRepoServer = DefaultPortRepoServer -var PortArgoCDMetrics = DefaultPortArgoCDMetrics -var PortArgoCDAPIServerMetrics = DefaultPortArgoCDAPIServerMetrics -var PortRepoServerMetrics = DefaultPortRepoServerMetrics - // Argo CD application related constants const ( // KubernetesInternalAPIServerAddr is address of the k8s API server when accessing internal to the cluster From 9ff0c088647f75784c7c74e7b7ae922ddd057681 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Sun, 26 May 2019 21:02:15 +0200 Subject: [PATCH 6/9] Use DefaultPortArgoCDMetrics instead of 8082 --- controller/appcontroller_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index 85cbf59a8d889..8fc7558c96e49 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -76,7 +76,7 @@ func newFakeController(data *fakeData) *ApplicationController { &mockRepoClientset, utilcache.NewCache(utilcache.NewInMemoryCache(1*time.Hour)), time.Minute, - 8082, + common.DefaultPortArgoCDMetrics, ) if err != nil { panic(err) From bd715ee894ce3f9b5cb64e299f34a2e4fafcf0e6 Mon Sep 17 00:00:00 2001 From: Kalisti Date: Tue, 28 May 2019 19:36:32 +0200 Subject: [PATCH 7/9] camelCase variable name --- server/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server_test.go b/server/server_test.go index 3c9c41be08fd1..438fcf62488e9 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -334,7 +334,7 @@ func TestUserAgent(t *testing.T) { defer cancelInformer() port, err := test.GetFreePort() assert.NoError(t, err) - metricsport, err := test.GetFreePort() + metricsPort, err := test.GetFreePort() assert.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) defer cancel() From e7833d7d78b85b9695be7b2ce8e8dd6098734c7b Mon Sep 17 00:00:00 2001 From: Kalisti Date: Tue, 28 May 2019 19:38:47 +0200 Subject: [PATCH 8/9] Change --listen-port parameter name to --port --- cmd/argocd-repo-server/main.go | 2 +- cmd/argocd-server/commands/root.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/argocd-repo-server/main.go b/cmd/argocd-repo-server/main.go index d9aeccdd1cc06..401305b3edca0 100644 --- a/cmd/argocd-repo-server/main.go +++ b/cmd/argocd-repo-server/main.go @@ -69,7 +69,7 @@ func newCommand() *cobra.Command { command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.Flags().Int64Var(¶llelismLimit, "parallelismlimit", 0, "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.") - command.Flags().IntVar(&listenPort, "listen-port", common.DefaultPortRepoServer, "Listen on given port for incoming connections") + command.Flags().IntVar(&listenPort, "port", common.DefaultPortRepoServer, "Listen on given port for incoming connections") command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortRepoServerMetrics, "Start metrics server on given port") tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command) cacheSrc = cache.AddCacheFlagsToCmd(&command) diff --git a/cmd/argocd-server/commands/root.go b/cmd/argocd-server/commands/root.go index 1ed10f62e2ff2..6fd9b6029a45d 100644 --- a/cmd/argocd-server/commands/root.go +++ b/cmd/argocd-server/commands/root.go @@ -101,7 +101,7 @@ func NewCommand() *cobra.Command { command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address") command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication") command.AddCommand(cli.NewVersionCmd(cliName)) - command.Flags().IntVar(&listenPort, "listen-port", common.DefaultPortAPIServer, "Listen on given port") + command.Flags().IntVar(&listenPort, "port", common.DefaultPortAPIServer, "Listen on given port") command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortArgoCDAPIServerMetrics, "Start metrics on given port") tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command) cacheSrc = cache.AddCacheFlagsToCmd(command) From 26e1eda8560e15715cce96409e1acc19bc97245e Mon Sep 17 00:00:00 2001 From: Kalisti Date: Tue, 28 May 2019 19:42:56 +0200 Subject: [PATCH 9/9] camelCase variable name --- server/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server_test.go b/server/server_test.go index 438fcf62488e9..a61a7d556fce9 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -338,7 +338,7 @@ func TestUserAgent(t *testing.T) { assert.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - go s.Run(ctx, port, metricsport) + go s.Run(ctx, port, metricsPort) err = test.WaitForPortListen(fmt.Sprintf("127.0.0.1:%d", port), 10*time.Second) assert.NoError(t, err)