feat: Add an option to configure the operator metrics endpoint port
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 @@
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 {
- 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()
- },
+func newCmdOperator() (*cobra.Command, *operatorCmdOptions) {
+ options := operatorCmdOptions{
}
- return &cmd
+ cmd := cobra.Command{
+ Use: "operator",
+ Short: "Run the Camel K operator",
+ Long: `Run the Camel K operator`,
+ Hidden: true,
+ PreRunE: decode(&options),
+ Run: options.run,
+ }
+
+ 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 @@
"math/rand"
"os"
"runtime"
+ "strconv"
"time"
"github.com/apache/camel-k/pkg/platform"
@@ -63,7 +64,7 @@
}
// Run starts the Camel K operator
-func Run() {
+func Run(monitoringPort int32) {
rand.Seed(time.Now().UTC().UnixNano())
flag.Parse()
@@ -123,9 +124,9 @@
// 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 @@
"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 @@
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)))