From ce24847798030f6310c0b113444ec8b08e5829c8 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Wed, 15 Jul 2020 23:56:57 -0400 Subject: [PATCH 1/4] cmd/helm-operator/main.go: add --metrics-addr flag --- changelog/fragments/helm-metrics-addr.yaml | 14 ++++++++++++++ cmd/helm-operator/main.go | 5 +---- .../templates/metricsauth/auth_proxy_patch.go | 7 +++---- pkg/helm/flags/flag.go | 6 ++++++ 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 changelog/fragments/helm-metrics-addr.yaml diff --git a/changelog/fragments/helm-metrics-addr.yaml b/changelog/fragments/helm-metrics-addr.yaml new file mode 100644 index 0000000000..6d3589cbf1 --- /dev/null +++ b/changelog/fragments/helm-metrics-addr.yaml @@ -0,0 +1,14 @@ +entries: + - description: > + Added `--metrics-addr` flag to helm operator to make it configurable, and + changed the default from `:8383` to `:8080` + + kind: "change" + + # Is this a breaking change? + breaking: true + + migration: + header: Default helm operator metrics port changed + body: > + To continue using port 8383, specify `--metrics-addr=:8383` when you start the operator. diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index e97bb124ff..cd4a3bc6aa 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -49,7 +49,6 @@ import ( var ( metricsHost = "0.0.0.0" - metricsPort int32 = 8383 operatorMetricsPort int32 = 8686 log = logf.Log.WithName("cmd") @@ -77,7 +76,7 @@ func main() { // Set default manager options options := manager.Options{ - MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort), + MetricsBindAddress: f.MetricsAddress, NewClient: func(cache cache.Cache, config *rest.Config, options crclient.Options) (crclient.Client, error) { c, err := crclient.New(config, options) if err != nil { @@ -184,8 +183,6 @@ func addMetrics(ctx context.Context, cfg *rest.Config, gvks []schema.GroupVersio // Add to the below struct any other metrics ports you want to expose. servicePorts := []v1.ServicePort{ - {Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, - TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}}, {Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}}, } diff --git a/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go b/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go index 1ea25886b0..9c3c72ce25 100644 --- a/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go +++ b/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go @@ -47,9 +47,6 @@ func (f *AuthProxyPatch) SetTemplateDefaults() error { // todo(camilamacedo86): add the arg --enable-leader-election for the manager // More info: https://github.com/operator-framework/operator-sdk/issues/3356 -// todo(camilamacedo86): add the arg --metrics-addr for the manager -// More info: https://github.com/operator-framework/operator-sdk/issues/3358 - const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the # controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. apiVersion: apps/v1 @@ -65,11 +62,13 @@ spec: image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 args: - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8383/" + - "--upstream=http://127.0.0.1:8080/" - "--logtostderr=true" - "--v=10" ports: - containerPort: 8443 name: https - name: manager + args: + - "--metrics-addr=127.0.0.1:8080" ` diff --git a/pkg/helm/flags/flag.go b/pkg/helm/flags/flag.go index b19fef2825..3e392e3e6f 100644 --- a/pkg/helm/flags/flag.go +++ b/pkg/helm/flags/flag.go @@ -28,6 +28,7 @@ type Flags struct { ReconcilePeriod time.Duration WatchesFile string MaxWorkers int + MetricsAddress string } // AddTo - Add the helm operator flags to the the flagset @@ -48,4 +49,9 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) { runtime.NumCPU(), "Maximum number of workers to use", ) + flagSet.StringVar(&f.MetricsAddress, + "metrics-addr", + ":8080", + "The address the metric endpoint binds to", + ) } From 706d68e60ad81d29feef1012fdf7e79c1a6e63ec Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 16 Jul 2020 09:30:30 -0400 Subject: [PATCH 2/4] internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go: fix indent --- .../v1/scaffolds/templates/metricsauth/auth_proxy_patch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go b/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go index 9c3c72ce25..c1009a52bd 100644 --- a/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go +++ b/internal/plugins/helm/v1/scaffolds/templates/metricsauth/auth_proxy_patch.go @@ -69,6 +69,6 @@ spec: - containerPort: 8443 name: https - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" + args: + - "--metrics-addr=127.0.0.1:8080" ` From 79e388209989776a9947b49fa333acf3ef64415d Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 16 Jul 2020 09:30:47 -0400 Subject: [PATCH 3/4] internal/plugins/helm/v1/scaffolds/templates/manager/config.go: remove invalid arg --- .../plugins/helm/v1/scaffolds/templates/manager/config.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/plugins/helm/v1/scaffolds/templates/manager/config.go b/internal/plugins/helm/v1/scaffolds/templates/manager/config.go index 880d495b4d..7cf792331e 100644 --- a/internal/plugins/helm/v1/scaffolds/templates/manager/config.go +++ b/internal/plugins/helm/v1/scaffolds/templates/manager/config.go @@ -87,9 +87,7 @@ spec: control-plane: controller-manager spec: containers: - - args: - - manager - image: {{ .Image }} + - image: {{ .Image }} name: manager resources: limits: From 85989b9f060eadc304e35fee9625c9e21c77b408 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 16 Jul 2020 11:44:31 -0400 Subject: [PATCH 4/4] empty commit to force ci to start again