You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/11/10 10:20:21 UTC

[camel-k] 21/25: feat: Add an option to configure the operator metrics endpoint port

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit f70182e2e055fd4eeb40fef658e7bdffff2c8e53
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Oct 28 12:22:27 2020 +0100

    feat: Add an option to configure the operator metrics endpoint port
---
 pkg/cmd/operator.go          | 33 +++++++++++++++++++++++----------
 pkg/cmd/operator/operator.go |  9 +++++----
 pkg/cmd/root.go              |  7 ++++---
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/pkg/cmd/operator.go b/pkg/cmd/operator.go
index 87361fd..2d69d01 100644
--- a/pkg/cmd/operator.go
+++ b/pkg/cmd/operator.go
@@ -18,20 +18,33 @@ limitations under the License.
 package cmd
 
 import (
-	"github.com/apache/camel-k/pkg/cmd/operator"
 	"github.com/spf13/cobra"
+
+	"github.com/apache/camel-k/pkg/cmd/operator"
 )
 
-func newCmdOperator() *cobra.Command {
+func newCmdOperator() (*cobra.Command, *operatorCmdOptions) {
+	options := operatorCmdOptions{
+	}
+
 	cmd := cobra.Command{
-		Use:    "operator",
-		Short:  "Run the Camel K operator",
-		Long:   `Run the Camel K operator`,
-		Hidden: true,
-		Run: func(cmd *cobra.Command, args []string) {
-			operator.Run()
-		},
+		Use:     "operator",
+		Short:   "Run the Camel K operator",
+		Long:    `Run the Camel K operator`,
+		Hidden:  true,
+		PreRunE: decode(&options),
+		Run:     options.run,
 	}
 
-	return &cmd
+	cmd.Flags().Int32("monitoring-port", 8080, "The port of the metrics endpoint")
+
+	return &cmd, &options
+}
+
+type operatorCmdOptions struct {
+	MonitoringPort int32 `mapstructure:"monitoring-port"`
+}
+
+func (o *operatorCmdOptions) run(_ *cobra.Command, _ []string) {
+	operator.Run(o.MonitoringPort)
 }
diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index a858b30..ec59ea1 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -24,6 +24,7 @@ import (
 	"math/rand"
 	"os"
 	"runtime"
+	"strconv"
 	"time"
 
 	"github.com/apache/camel-k/pkg/platform"
@@ -63,7 +64,7 @@ func printVersion() {
 }
 
 // Run starts the Camel K operator
-func Run() {
+func Run(monitoringPort int32) {
 	rand.Seed(time.Now().UTC().UnixNano())
 
 	flag.Parse()
@@ -123,9 +124,9 @@ func Run() {
 
 	// Create a new Cmd to provide shared dependencies and start components
 	mgr, err := ctrl.NewManager(cfg, ctrl.Options{
-		Namespace:        namespace,
-		EventBroadcaster: eventBroadcaster,
-		MetricsBindAddress: ":8080",
+		Namespace:          namespace,
+		EventBroadcaster:   eventBroadcaster,
+		MetricsBindAddress: ":" + strconv.Itoa(int(monitoringPort)),
 	})
 	if err != nil {
 		log.Error(err, "")
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index 2eab1ef..2899a30 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -22,11 +22,12 @@ import (
 	"os"
 	"strings"
 
-	"github.com/apache/camel-k/pkg/client"
-	camelv1 "github.com/apache/camel-k/pkg/client/camel/clientset/versioned/typed/camel/v1"
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
+
+	"github.com/apache/camel-k/pkg/client"
+	camelv1 "github.com/apache/camel-k/pkg/client/camel/clientset/versioned/typed/camel/v1"
 )
 
 const kamelCommandLongDescription = `Apache Camel K is a lightweight integration platform, born on Kubernetes, with serverless
@@ -133,7 +134,7 @@ func addKamelSubcommands(cmd *cobra.Command, options *RootCmdOptions) {
 	cmd.AddCommand(cmdOnly(newCmdReset(options)))
 	cmd.AddCommand(newCmdDescribe(options))
 	cmd.AddCommand(cmdOnly(newCmdRebuild(options)))
-	cmd.AddCommand(newCmdOperator())
+	cmd.AddCommand(cmdOnly(newCmdOperator()))
 	cmd.AddCommand(cmdOnly(newCmdBuilder(options)))
 	cmd.AddCommand(cmdOnly(newCmdInit(options)))
 	cmd.AddCommand(cmdOnly(newCmdDebug(options)))