Skip to content

Commit cfe58c7

Browse files
committed
feat:kcc: MCL integration
Signed-off-by: Alex Pana <[email protected]>
1 parent f79c640 commit cfe58c7

File tree

5 files changed

+116
-73
lines changed

5 files changed

+116
-73
lines changed

cmd/manager/main.go

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ import (
2727
controllermetrics "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/metrics"
2828
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/ratelimiter"
2929
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp/profiler"
30-
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf"
3130
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/logging"
3231
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/metrics"
3332
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/ready"
3433
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/stateintospec"
3534

3635
flag "github.com/spf13/pflag"
3736
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
38-
"k8s.io/client-go/rest"
3937
"sigs.k8s.io/controller-runtime/pkg/cache"
4038
"sigs.k8s.io/controller-runtime/pkg/client/config"
4139
crlog "sigs.k8s.io/controller-runtime/pkg/log"
@@ -62,6 +60,7 @@ func main() {
6260
pprofPort int
6361
rateLimitQps float32
6462
rateLimitBurst int
63+
multiClusterElection bool
6564
)
6665
flag.StringVar(&prometheusScrapeEndpoint, "prometheus-scrape-endpoint", ":8888", "configure the Prometheus scrape endpoint; :8888 as default")
6766
flag.BoolVar(&controllermetrics.ResourceNameLabel, "resource-name-label", false, "option to enable the resource name label on some Prometheus metrics; false by default")
@@ -72,6 +71,7 @@ func main() {
7271
flag.IntVar(&pprofPort, "pprof-port", 6060, "The port that the pprof server binds to if enabled.")
7372
flag.Float32Var(&rateLimitQps, "qps", 20.0, "The client-side token bucket rate limit qps.")
7473
flag.IntVar(&rateLimitBurst, "burst", 30, "The client-side token bucket rate limit burst.")
74+
flag.BoolVar(&multiClusterElection, "multi-cluster-election", false, "Enable multi-cluster leader election.")
7575
profiler.AddFlag(flag.CommandLine)
7676
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
7777
flag.Parse()
@@ -106,7 +106,19 @@ func main() {
106106
// Set client site rate limiter to optimize the configconnector re-reconciliation performance.
107107
ratelimiter.SetMasterRateLimiter(restCfg, rateLimitQps, rateLimitBurst)
108108
logger.Info("Creating the manager")
109-
mgr, err := newManager(ctx, restCfg, scopedNamespace, userProjectOverride, billingProject)
109+
controllersCfg := kccmanager.Config{
110+
ManagerOptions: manager.Options{
111+
Cache: cache.Options{
112+
DefaultNamespaces: map[string]cache.Config{
113+
scopedNamespace: {},
114+
},
115+
},
116+
},
117+
}
118+
controllersCfg.UserProjectOverride = userProjectOverride
119+
controllersCfg.BillingProject = billingProject
120+
controllersCfg.StateIntoSpecDefaultValue = stateintospec.StateIntoSpecDefaultValueV1Beta1
121+
mgr, err := kccmanager.New(ctx, restCfg, controllersCfg)
110122
if err != nil {
111123
logging.Fatal(err, "error creating the manager")
112124
}
@@ -142,28 +154,12 @@ func main() {
142154
logger.Info("Starting the Cmd.")
143155

144156
// Start the Cmd
145-
logging.Fatal(mgr.Start(stop), "error during manager execution.")
146-
}
147-
148-
func newManager(ctx context.Context, restCfg *rest.Config, scopedNamespace string, userProjectOverride bool, billingProject string) (manager.Manager, error) {
149-
krmtotf.SetUserAgentForTerraformProvider()
150-
controllersCfg := kccmanager.Config{
151-
ManagerOptions: manager.Options{
152-
Cache: cache.Options{
153-
DefaultNamespaces: map[string]cache.Config{
154-
scopedNamespace: {},
155-
},
156-
},
157-
},
158-
}
159-
160-
controllersCfg.UserProjectOverride = userProjectOverride
161-
controllersCfg.BillingProject = billingProject
162-
// TODO(b/320784855): StateIntoSpecDefaultValue and StateIntoSpecUserOverride values should come from the flags.
163-
controllersCfg.StateIntoSpecDefaultValue = stateintospec.StateIntoSpecDefaultValueV1Beta1
164-
mgr, err := kccmanager.New(ctx, restCfg, controllersCfg)
165-
if err != nil {
166-
return nil, fmt.Errorf("error creating manager: %w", err)
157+
mgrErr := mgr.Start(stop)
158+
if mgrErr != nil {
159+
logging.Fatal(mgrErr, "error during manager execution.")
160+
} else {
161+
// err is nil
162+
// todo acpana add more defense in depth here
163+
logging.ExitInfo("might've lost leader election")
167164
}
168-
return mgr, nil
169165
}

go.mod

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ require (
8080
github.com/cenkalti/backoff v2.2.1+incompatible
8181
github.com/fatih/color v1.18.0
8282
github.com/ghodss/yaml v1.0.0
83+
github.com/gke-labs/multicluster-leader-election v0.0.0-20250923220528-0bf41dc7fecc
8384
github.com/go-logr/logr v1.4.3
8485
github.com/go-logr/zapr v1.3.0
8586
github.com/google/go-cmp v0.7.0
@@ -95,13 +96,13 @@ require (
9596
github.com/olekukonko/tablewriter v0.0.5
9697
github.com/onsi/gomega v1.36.1
9798
github.com/pkg/errors v0.9.1
98-
github.com/prometheus/client_golang v1.20.4
99+
github.com/prometheus/client_golang v1.22.0
99100
github.com/prometheus/procfs v0.15.1
100101
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
101102
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
102103
github.com/spf13/cobra v1.8.1
103104
github.com/spf13/pflag v1.0.5
104-
github.com/stretchr/testify v1.10.0
105+
github.com/stretchr/testify v1.11.0
105106
github.com/tmccombs/hcl2json v0.6.8
106107
github.com/zclconf/go-cty v1.16.4
107108
go.opencensus.io v0.24.0
@@ -119,16 +120,16 @@ require (
119120
google.golang.org/protobuf v1.36.7
120121
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
121122
gopkg.in/yaml.v2 v2.4.0
122-
k8s.io/api v0.32.1
123-
k8s.io/apiextensions-apiserver v0.32.1
124-
k8s.io/apimachinery v0.32.1
125-
k8s.io/client-go v0.32.1
123+
k8s.io/api v0.33.0
124+
k8s.io/apiextensions-apiserver v0.33.0
125+
k8s.io/apimachinery v0.33.0
126+
k8s.io/client-go v0.33.0
126127
k8s.io/klog/v2 v2.130.1
127-
sigs.k8s.io/controller-runtime v0.20.4
128+
sigs.k8s.io/controller-runtime v0.21.0
128129
sigs.k8s.io/controller-tools v0.16.5
129130
sigs.k8s.io/kubebuilder-declarative-pattern v0.20.0-beta.1.0.20250514194322-871029137730
130131
sigs.k8s.io/kubebuilder-declarative-pattern/mockkubeapiserver v0.0.0-20230303024857-d1f76c15e05b
131-
sigs.k8s.io/structured-merge-diff/v4 v4.4.2
132+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0
132133
sigs.k8s.io/yaml v1.4.0
133134
)
134135

@@ -141,8 +142,8 @@ require (
141142
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
142143
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
143144
github.com/google/flatbuffers v24.3.25+incompatible // indirect
144-
github.com/google/gnostic-models v0.6.8 // indirect
145-
github.com/gorilla/websocket v1.5.3 // indirect
145+
github.com/google/gnostic-models v0.6.9 // indirect
146+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
146147
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
147148
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
148149
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -155,6 +156,7 @@ require (
155156
gonum.org/v1/gonum v0.16.0 // indirect
156157
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
157158
sigs.k8s.io/kubebuilder-declarative-pattern/ktest v0.0.0-20250514194322-871029137730 // indirect
159+
sigs.k8s.io/randfill v1.0.0 // indirect
158160
)
159161

160162
require (
@@ -208,7 +210,6 @@ require (
208210
github.com/golang/protobuf v1.5.4
209211
github.com/google/btree v1.1.3 // indirect
210212
github.com/google/go-cpy v0.0.0-20211218193943-a9c933c06932 // indirect
211-
github.com/google/gofuzz v1.2.0 // indirect
212213
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
213214
github.com/google/s2a-go v0.1.9 // indirect
214215
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
@@ -240,7 +241,7 @@ require (
240241
github.com/josharian/intern v1.0.0 // indirect
241242
github.com/json-iterator/go v1.1.12 // indirect
242243
github.com/kevinburke/ssh_config v1.2.0 // indirect
243-
github.com/klauspost/compress v1.17.9 // indirect
244+
github.com/klauspost/compress v1.18.0 // indirect
244245
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
245246
github.com/kylelemons/godebug v1.1.0 // indirect
246247
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
@@ -266,7 +267,7 @@ require (
266267
github.com/pjbgf/sha1cd v0.3.2 // indirect
267268
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
268269
github.com/prometheus/client_model v0.6.1 // indirect
269-
github.com/prometheus/common v0.59.1 // indirect
270+
github.com/prometheus/common v0.62.0 // indirect
270271
github.com/rivo/uniseg v0.4.7 // indirect
271272
github.com/russross/blackfriday/v2 v2.1.0 // indirect
272273
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
@@ -300,8 +301,8 @@ require (
300301
gopkg.in/warnings.v0 v0.1.2 // indirect
301302
gopkg.in/yaml.v3 v3.0.1
302303
k8s.io/cli-runtime v0.32.1 // indirect
303-
k8s.io/component-base v0.32.1 // indirect
304-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
304+
k8s.io/component-base v0.33.0 // indirect
305+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
305306
k8s.io/kubectl v0.32.1 // indirect
306307
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
307308
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

0 commit comments

Comments
 (0)