Skip to content

Commit b86b35d

Browse files
authored
improve agent performance (#53)
Signed-off-by: Wei Liu <[email protected]>
1 parent 6b5506d commit b86b35d

File tree

74 files changed

+6238
-738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6238
-738
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ WORKDIR ${DIRPATH}
99
COPY . .
1010

1111
# RUN apt-get update && apt-get install net-tools && make vendor
12-
RUN make vendor && \
13-
GOOS=${OS} \
12+
RUN GOOS=${OS} \
1413
GOARCH=${ARCH} \
1514
make build
1615

1716
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
1817
ENV USER_UID=10001
1918

2019
COPY --from=builder /workspace/multicluster-controlplane/bin/multicluster-controlplane /
20+
COPY --from=builder /workspace/multicluster-controlplane/bin/multicluster-agent /
2121

2222
USER ${USER_UID}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ vendor:
2525

2626
build: vendor
2727
mkdir -p $(BINARYDIR)
28-
go build -o bin/multicluster-controlplane cmd/main.go
28+
go build -ldflags="-s -w" -o bin/multicluster-controlplane cmd/manager/manager.go
29+
go build -ldflags="-s -w" -o bin/multicluster-agent cmd/agent/agent.go
2930
.PHONY: build
3031

3132
build-image:

charts/multicluster-controlplane/templates/deployment.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ spec:
2222
imagePullPolicy: {{ .Values.imagePullPolicy }}
2323
args:
2424
- "/multicluster-controlplane"
25-
- "server"
2625
{{- if .Values.features }}
2726
- "--feature-gates={{ .Values.features }}"
2827
{{- end }}

cmd/agent/agent.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
// Copyright Contributors to the Open Cluster Management project
22

3-
package agent
3+
package main
44

55
import (
66
"context"
7+
"os"
78
"path"
89

910
"github.com/spf13/cobra"
10-
"go.uber.org/zap/zapcore"
11+
12+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1113
genericapiserver "k8s.io/apiserver/pkg/server"
14+
"k8s.io/component-base/cli"
1215
"k8s.io/klog/v2"
16+
1317
ctrl "sigs.k8s.io/controller-runtime"
14-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
18+
19+
"open-cluster-management.io/multicluster-controlplane/pkg/features"
1520

1621
"github.com/stolostron/multicluster-controlplane/pkg/agent"
22+
"github.com/stolostron/multicluster-controlplane/pkg/feature"
1723
)
1824

19-
func NewAgent() *cobra.Command {
25+
func init() {
26+
utilruntime.Must(features.DefaultAgentMutableFeatureGate.Add(feature.DefaultControlPlaneFeatureGates))
27+
}
28+
29+
func main() {
2030
agentOptions := agent.NewAgentOptions()
21-
var logLevel string
2231
cmd := &cobra.Command{
23-
Use: "agent",
24-
Short: "Start a Multicluster Controlplane Agent",
32+
Use: "multicluster-agent",
33+
Short: "Start a multicluster agent",
2534
RunE: func(cmd *cobra.Command, args []string) error {
2635
shutdownCtx, cancel := context.WithCancel(context.TODO())
2736

28-
level, _ := zapcore.ParseLevel(logLevel)
29-
opts := &zap.Options{
30-
Level: zapcore.Level(level),
31-
}
32-
// set log level to the controller-runtime logger
33-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(opts)))
37+
ctrl.SetLogger(klog.NewKlogr())
3438

3539
shutdownHandler := genericapiserver.SetupSignalHandler()
3640
go func() {
@@ -92,17 +96,11 @@ func NewAgent() *cobra.Command {
9296
flags.BoolVar(
9397
&agentOptions.EnableMetrics,
9498
"enable-metrics",
95-
true,
99+
false,
96100
"Disable custom metrics collection",
97101
)
98102

99-
flags.StringVar(
100-
&logLevel,
101-
"log-level",
102-
"info",
103-
"Zap level to configure the verbosity of logging.",
104-
)
105-
106103
agentOptions.AddFlags(flags)
107-
return cmd
104+
105+
os.Exit(cli.Run(cmd))
108106
}

cmd/main.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

cmd/manager/manager.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
11
// Copyright Contributors to the Open Cluster Management project
22

3-
package manager
3+
package main
44

55
import (
6+
"os"
7+
68
"github.com/spf13/cobra"
7-
"go.uber.org/zap/zapcore"
9+
810
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
911
genericapiserver "k8s.io/apiserver/pkg/server"
1012
utilfeature "k8s.io/apiserver/pkg/util/feature"
13+
"k8s.io/component-base/cli"
1114
cliflag "k8s.io/component-base/cli/flag"
1215
logsapi "k8s.io/component-base/logs/api/v1"
1316
"k8s.io/component-base/version/verflag"
17+
"k8s.io/klog/v2"
18+
19+
ctrl "sigs.k8s.io/controller-runtime"
20+
21+
"open-cluster-management.io/multicluster-controlplane/pkg/features"
1422
"open-cluster-management.io/multicluster-controlplane/pkg/servers"
1523
"open-cluster-management.io/multicluster-controlplane/pkg/servers/options"
16-
ctrl "sigs.k8s.io/controller-runtime"
17-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1824

1925
controller "github.com/stolostron/multicluster-controlplane/pkg/controllers"
2026
"github.com/stolostron/multicluster-controlplane/pkg/controllers/selfmanagement"
27+
"github.com/stolostron/multicluster-controlplane/pkg/feature"
2128
)
2229

2330
func init() {
24-
utilruntime.Must(logsapi.AddFeatureGates(utilfeature.DefaultMutableFeatureGate)) // register log to featuregate
31+
// register log to featuregate
32+
utilruntime.Must(logsapi.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
33+
// init feature gates
34+
utilruntime.Must(features.DefaultControlplaneMutableFeatureGate.Add(feature.DefaultControlPlaneFeatureGates))
2535
}
2636

27-
func NewManager() *cobra.Command {
37+
func main() {
2838
options := options.NewServerRunOptions()
29-
var logLevel string
3039
cmd := &cobra.Command{
31-
Use: "server",
32-
Short: "Start a Multicluster Controlplane Server",
40+
Use: "multicluster-controlplane",
41+
Short: "Start a multicluster controlplane",
3342
RunE: func(cmd *cobra.Command, args []string) error {
3443
verflag.PrintAndExitIfRequested()
3544
cliflag.PrintFlags(cmd.Flags())
3645

37-
level, _ := zapcore.ParseLevel(logLevel)
38-
opts := &zap.Options{
39-
Level: zapcore.Level(level),
40-
}
41-
// set log level to the controller-runtime logger
42-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(opts)))
46+
ctrl.SetLogger(klog.NewKlogr())
4347

4448
if err := logsapi.ValidateAndApply(options.Logs, utilfeature.DefaultFeatureGate); err != nil {
4549
return err
@@ -62,13 +66,7 @@ func NewManager() *cobra.Command {
6266
},
6367
}
6468

65-
flags := cmd.Flags()
66-
flags.StringVar(
67-
&logLevel,
68-
"log-level",
69-
"info",
70-
"Zap level to configure the verbosity of logging.",
71-
)
72-
options.AddFlags(flags)
73-
return cmd
69+
options.AddFlags(cmd.Flags())
70+
71+
os.Exit(cli.Run(cmd))
7472
}

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/stolostron/multicluster-controlplane
33
go 1.20
44

55
require (
6-
github.com/go-logr/logr v1.2.4
76
github.com/onsi/ginkgo/v2 v2.10.0
87
github.com/onsi/gomega v1.27.8
98
github.com/open-policy-agent/frameworks/constraint v0.0.0-20230411224310-3f237e2710fa
@@ -12,24 +11,22 @@ require (
1211
github.com/spf13/cobra v1.7.0
1312
github.com/stolostron/cluster-lifecycle-api v0.0.0-20230510064049-824d580bc143
1413
github.com/stolostron/kubernetes-dependency-watches v0.2.1
15-
go.uber.org/zap v1.24.0
1614
golang.org/x/net v0.10.0
1715
k8s.io/api v0.27.2
1816
k8s.io/apiextensions-apiserver v0.27.2
1917
k8s.io/apimachinery v0.27.2
2018
k8s.io/apiserver v0.27.2
2119
k8s.io/client-go v12.0.0+incompatible
2220
k8s.io/component-base v0.27.2
23-
k8s.io/klog v1.0.0
2421
k8s.io/klog/v2 v2.100.1
2522
k8s.io/kube-aggregator v0.27.2
2623
k8s.io/utils v0.0.0-20230505201702-9f6742963106
27-
open-cluster-management.io/api v0.11.0
24+
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139
2825
open-cluster-management.io/config-policy-controller v0.11.1-0.20230601150037-7efe2d125208
2926
open-cluster-management.io/governance-policy-framework-addon v0.11.1-0.20230609150423-d788045bf097
3027
open-cluster-management.io/governance-policy-propagator v0.11.1-0.20230608150119-94b4daa84adb
3128
open-cluster-management.io/multicloud-operators-subscription v0.11.0
32-
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230607092144-a675d39cc726
29+
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230620013050-12d2edb23043
3330
sigs.k8s.io/controller-runtime v0.15.0
3431
)
3532

@@ -148,6 +145,7 @@ require (
148145
cloud.google.com/go/compute v1.19.1 // indirect
149146
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1 // indirect
150147
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
148+
github.com/go-logr/logr v1.2.4 // indirect
151149
github.com/go-logr/stdr v1.2.2 // indirect
152150
github.com/go-logr/zapr v1.2.4 // indirect
153151
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
@@ -178,6 +176,7 @@ require (
178176
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
179177
go.uber.org/atomic v1.11.0 // indirect
180178
go.uber.org/multierr v1.11.0 // indirect
179+
go.uber.org/zap v1.24.0 // indirect
181180
golang.org/x/crypto v0.9.0 // indirect
182181
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
183182
golang.org/x/mod v0.10.0 // indirect
@@ -186,11 +185,12 @@ require (
186185
golang.org/x/tools v0.9.3 // indirect
187186
k8s.io/cluster-bootstrap v0.27.2 // indirect
188187
k8s.io/controller-manager v0.27.2 // indirect
188+
k8s.io/klog v1.0.0 // indirect
189189
k8s.io/kms v0.27.2 // indirect
190190
k8s.io/kube-controller-manager v0.27.2 // indirect
191191
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
192192
k8s.io/kubernetes v1.27.2 // indirect
193-
open-cluster-management.io/ocm v0.0.0-20230606095507-6f21760b7e57 // indirect
193+
open-cluster-management.io/ocm v0.0.0-20230614150343-ecfb6c08880e // indirect
194194
)
195195

196196
// replace these repos because of imported k8s.io/kubernetes v1.27.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,8 +1314,8 @@ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
13141314
k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
13151315
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
13161316
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1317-
open-cluster-management.io/api v0.11.0 h1:zBxa33Co3wseLBF4HEJobhl0P6ygj+Drhe7Wrfo0/h8=
1318-
open-cluster-management.io/api v0.11.0/go.mod h1:WgKUCJ7+Bf40DsOmH1Gdkpyj3joco+QLzrlM6Ak39zE=
1317+
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139 h1:nw/XSv4eDGqmg0ks2PHzrE2uosvjw+D314843G56xGY=
1318+
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139/go.mod h1:WgKUCJ7+Bf40DsOmH1Gdkpyj3joco+QLzrlM6Ak39zE=
13191319
open-cluster-management.io/config-policy-controller v0.11.1-0.20230601150037-7efe2d125208 h1:2TeDRvAUTJ7F9LUZfuhuqcpp0pR0mYeKVEhajR/HBis=
13201320
open-cluster-management.io/config-policy-controller v0.11.1-0.20230601150037-7efe2d125208/go.mod h1:q5DYBLgEHb0gjAOEzKZOEDarbjdSn2nVtNG96ETHmeU=
13211321
open-cluster-management.io/governance-policy-framework-addon v0.11.1-0.20230609150423-d788045bf097 h1:twYhVK1ccqy9F4s2icAiAhSqmhGaOpUcSuzOJD65oy0=
@@ -1324,10 +1324,10 @@ open-cluster-management.io/governance-policy-propagator v0.11.1-0.20230608150119
13241324
open-cluster-management.io/governance-policy-propagator v0.11.1-0.20230608150119-94b4daa84adb/go.mod h1:n+BgxbaWJO2MortqV2I0EMgmpbGUE5ze9eBPGVe4Npc=
13251325
open-cluster-management.io/multicloud-operators-subscription v0.11.0 h1:OLpohu92lMEmWk4LriTyxD1SIJrzHOvuhS3UsnEOElk=
13261326
open-cluster-management.io/multicloud-operators-subscription v0.11.0/go.mod h1:0YDADTwQiNoLc7ihyHhTaCNAxx9VSVvrTUQf3W+AyGk=
1327-
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230607092144-a675d39cc726 h1:9W9M8eocKaqD6WFy5rhsFHH+vSJUbGDy4FHxG2CQ6qg=
1328-
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230607092144-a675d39cc726/go.mod h1:f4aRH3IpDGZ7qCrUhlbSMTe+sOQgMH5eQFuNtzuSWdM=
1329-
open-cluster-management.io/ocm v0.0.0-20230606095507-6f21760b7e57 h1:QXk9xX9oNrYSfzABD5tVheY9X+n0htRdQGk7c3Nggt4=
1330-
open-cluster-management.io/ocm v0.0.0-20230606095507-6f21760b7e57/go.mod h1:d9nPyvcSqNsQTwaZqhmXDbQGNRawEy7uolHk2ZFshUI=
1327+
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230620013050-12d2edb23043 h1:Wm4634T1Q/2pCd1ecUU67TPRRHD2YeXo8i9mbnKOqOQ=
1328+
open-cluster-management.io/multicluster-controlplane v0.2.1-0.20230620013050-12d2edb23043/go.mod h1:eitWOphtPJHGQ9+rbWjzgxBn2F7v1WQilG3ewGYu334=
1329+
open-cluster-management.io/ocm v0.0.0-20230614150343-ecfb6c08880e h1:6YwGFXa85MO98ZEs3DjAwYDZi61n6yC8m1kGUNpRf2c=
1330+
open-cluster-management.io/ocm v0.0.0-20230614150343-ecfb6c08880e/go.mod h1:Y0Spx83p5RserV8cOVD+ccZd+rYlmAjlUCZmzSoAuXc=
13311331
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
13321332
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
13331333
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

hack/deploy/agent/deployment.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ spec:
2121
image: quay.io/stolostron/multicluster-controlplane
2222
imagePullPolicy: IfNotPresent
2323
args:
24-
- "/multicluster-controlplane"
25-
- "agent"
24+
- "/multicluster-agent"
2625
- "--cluster-name=cluster1"
2726
- "--bootstrap-kubeconfig=/spoke/bootstrap/kubeconfig"
2827
env:

0 commit comments

Comments
 (0)