Skip to content

Commit 4936008

Browse files
committed
add --metrics-address and --health-address flags to disable metrics to prevent port conflicts in parallel tests
On-behalf-of: @SAP [email protected]
1 parent a21dfe0 commit 4936008

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

cmd/api-syncagent/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"sigs.k8s.io/controller-runtime/pkg/cluster"
5454
ctrlruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
5555
"sigs.k8s.io/controller-runtime/pkg/manager"
56+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
5657
)
5758

5859
func main() {
@@ -168,9 +169,11 @@ func setupLocalManager(ctx context.Context, opts *Options) (manager.Manager, err
168169
BaseContext: func() context.Context {
169170
return ctx
170171
},
172+
Metrics: metricsserver.Options{BindAddress: opts.MetricsAddr},
171173
LeaderElection: opts.EnableLeaderElection,
172174
LeaderElectionID: "syncagent." + opts.AgentName,
173175
LeaderElectionNamespace: opts.Namespace,
176+
HealthProbeBindAddress: opts.HealthAddr,
174177
})
175178
if err != nil {
176179
return nil, err

cmd/api-syncagent/options.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ type Options struct {
6565
KubeconfigCAFileOverride string
6666

6767
LogOptions log.Options
68+
69+
MetricsAddr string
70+
HealthAddr string
6871
}
6972

7073
func NewOptions() *Options {
7174
return &Options{
7275
LogOptions: log.NewDefaultOptions(),
7376
PublishedResourceSelector: labels.Everything(),
77+
MetricsAddr: "127.0.0.1:8085",
7478
}
7579
}
7680

@@ -83,8 +87,10 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
8387
flags.StringVar(&o.APIExportRef, "apiexport-ref", o.APIExportRef, "name of the APIExport in kcp that this Sync Agent is powering")
8488
flags.StringVar(&o.PublishedResourceSelectorString, "published-resource-selector", o.PublishedResourceSelectorString, "restrict this Sync Agent to only process PublishedResources matching this label selector (optional)")
8589
flags.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "whether to perform leader election")
86-
flags.StringVar(&o.KubeconfigHostOverride, "kubeconfig-host-override", o.KubeconfigHostOverride, "Override the host configured in the local kubeconfig")
87-
flags.StringVar(&o.KubeconfigCAFileOverride, "kubeconfig-ca-file-override", o.KubeconfigCAFileOverride, "Override the server CA file configured in the local kubeconfig")
90+
flags.StringVar(&o.KubeconfigHostOverride, "kubeconfig-host-override", o.KubeconfigHostOverride, "override the host configured in the local kubeconfig")
91+
flags.StringVar(&o.KubeconfigCAFileOverride, "kubeconfig-ca-file-override", o.KubeconfigCAFileOverride, "override the server CA file configured in the local kubeconfig")
92+
flags.StringVar(&o.MetricsAddr, "metrics-address", o.MetricsAddr, "host and port to serve Prometheus metrics via /metrics (HTTP)")
93+
flags.StringVar(&o.HealthAddr, "health-address", o.HealthAddr, "host and port to serve probes via /readyz and /healthz (HTTP)")
8894
}
8995

9096
func (o *Options) Validate() error {

test/utils/process.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func RunAgent(
8888
"--kcp-kubeconfig", kcpKubeconfig,
8989
"--namespace", "kube-system",
9090
"--log-format", "Console",
91+
"--health-address", "0",
92+
"--metrics-address", "0",
9193
}
9294

9395
logFile := filepath.Join(ArtifactsDirectory(t), uniqueLogfile(t, ""))

0 commit comments

Comments
 (0)