Skip to content

Commit f498aee

Browse files
authored
Merge pull request #1664 from weaveworks/caching-users-clients
Reusing k8s clients
2 parents b70e834 + 004b034 commit f498aee

File tree

12 files changed

+64
-30
lines changed

12 files changed

+64
-30
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ rules:
637637
verbs: ["impersonate"]
638638
- apiGroups: [""]
639639
resources: ["namespaces"]
640-
verbs: ["get", "list"]
640+
verbs: ["get", "list", "watch"]
641641
- apiGroups: ["apiextensions.k8s.io"] # required for canary support
642642
resources: ["customresourcedefinitions"]
643-
verbs: ["get", "list"]
643+
verbs: ["get", "list", "watch"]
644644
```
645645
646646
**CAPI NAME COLLISION WARNING**

charts/cluster-controller/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ controllerManager:
1313
manager:
1414
image:
1515
repository: docker.io/weaveworks/cluster-controller
16-
tag: v1.3.2
16+
tag: v1.4.0
1717
resources:
1818
limits:
1919
cpu: 500m

charts/mccp/templates/clusters-service/configmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ data:
1616
CAPI_REPOSITORY_CLUSTERS_PATH: {{ .Values.config.capi.repositoryClustersPath | quote }}
1717
CAPI_TEMPLATES_REPOSITORY_API_URL: {{ .Values.config.capi.repositoryApiURL | quote }}
1818
CAPI_TEMPLATES_REPOSITORY_BASE_BRANCH: {{ .Values.config.capi.baseBranch | quote }}
19+
USE_K8S_CACHED_CLIENTS: {{.Values.global.useK8sCachedClients | quote }}
1920
{{- /* build up the support auth methods string, should look like "oidc,user-account" */ -}}
2021
{{- $authMethods := list }}
2122
{{- if .Values.config.auth.userAccount.enabled -}}{{- $authMethods = append $authMethods "user-account" -}}{{- end }}
@@ -35,4 +36,4 @@ data:
3536
{{- if and .Values.tls.enabled .Values.tls.secretName }}
3637
TLS_CERT_FILE: /etc/clusters-service-tls/tls.crt
3738
TLS_PRIVATE_KEY: /etc/clusters-service-tls/tls.key
38-
{{- end }}
39+
{{- end }}

charts/mccp/templates/rbac/clusters_service_customresourcedefinitions_reader_role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ rules:
66
- apiGroups: ["apiextensions.k8s.io"]
77
resources: ["customresourcedefinitions"]
88
# read used to detect if flagger is installed
9-
verbs: ["get", "list"]
9+
verbs: ["get", "list", "watch"]

charts/mccp/templates/rbac/user_roles.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ metadata:
2626
rules:
2727
- apiGroups: [""]
2828
resources: ["secrets", "pods", "services"]
29-
verbs: ["get", "list"]
29+
verbs: ["get", "list", "watch"]
3030
- apiGroups: ["apps"]
3131
resources: ["deployments", "replicasets"]
32-
verbs: ["get", "list"]
32+
verbs: ["get", "list", "watch"]
3333
- apiGroups: ["kustomize.toolkit.fluxcd.io"]
3434
resources: ["kustomizations"]
35-
verbs: ["get", "list", "patch"]
35+
verbs: ["get", "list", "watch", "patch"]
3636
- apiGroups: ["helm.toolkit.fluxcd.io"]
3737
resources: ["helmreleases"]
38-
verbs: ["get", "list", "patch"]
38+
verbs: ["get", "list", "watch", "patch"]
3939
- apiGroups: ["source.toolkit.fluxcd.io"]
4040
resources: ["buckets", "helmcharts", "gitrepositories", "helmrepositories", "ocirepositories"]
41-
verbs: ["get", "list", "patch"]
41+
verbs: [ "get", "list", "watch", "patch" ]
4242
- apiGroups: [""]
4343
resources: ["events"]
4444
verbs: ["get", "watch", "list"]
@@ -50,7 +50,7 @@ rules:
5050
verbs: ["get", "watch", "list", "patch"]
5151
- apiGroups: ["apiextensions.k8s.io"]
5252
resources: ["customresourcedefinitions"]
53-
verbs: ["get", "list"]
53+
verbs: ["get", "list", "watch"]
5454
---
5555
apiVersion: rbac.authorization.k8s.io/v1
5656
kind: ClusterRole
@@ -115,7 +115,7 @@ metadata:
115115
rules:
116116
- apiGroups: [""]
117117
resources: ["secrets"]
118-
verbs: ["get", "list", "create"]
118+
verbs: ["get", "list", "watch", "create"]
119119
---
120120
apiVersion: rbac.authorization.k8s.io/v1
121121
kind: ClusterRole
@@ -129,7 +129,7 @@ metadata:
129129
rules:
130130
- apiGroups: ["pac.weave.works"]
131131
resources: ["policies"]
132-
verbs: ["get", "list"]
132+
verbs: ["get", "list", "watch"]
133133
- apiGroups: [""]
134134
resources: ["events"]
135135
verbs: ["get", "watch", "list"]
@@ -146,7 +146,7 @@ metadata:
146146
rules:
147147
- apiGroups: ["flagger.app"]
148148
resources: ["canaries","metrictemplates"]
149-
verbs: ["get", "list"]
149+
verbs: ["get", "list", "watch"]
150150
- apiGroups: [""]
151151
resources: ["events"]
152152
verbs: ["get", "watch", "list"]

charts/mccp/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ networkPolicy:
141141

142142
global:
143143
capiEnabled: true
144+
useK8sCachedClients: false

cmd/clusters-service/app/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type Params struct {
132132
TLSKey string `mapstructure:"tls-key"`
133133
NoTLS bool `mapstructure:"no-tls"`
134134
DevMode bool `mapstructure:"dev-mode"`
135+
UseK8sCachedClients bool `mapstructure:"use-k8s-cached-clients"`
135136
}
136137

137138
type OIDCAuthenticationOptions struct {
@@ -204,6 +205,7 @@ func NewAPIServerCommand(log logr.Logger, tempDir string) *cobra.Command {
204205
cmd.Flags().Duration("oidc-token-duration", time.Hour, "The duration of the ID token. It should be set in the format: number + time unit (s,m,h) e.g., 20m")
205206

206207
cmd.Flags().Bool("dev-mode", false, "starts the server in development mode")
208+
cmd.Flags().Bool("use-k8s-cached-clients", true, "Enables the use of cached clients")
207209

208210
return cmd
209211
}
@@ -396,12 +398,17 @@ func StartServer(ctx context.Context, log logr.Logger, tempDir string, p Params)
396398
runtimeUtil.Must(pipelinev1alpha1.AddToScheme(clustersManagerScheme))
397399
runtimeUtil.Must(tfctrl.AddToScheme(clustersManagerScheme))
398400

401+
clientsFactory := clustersmngr.CachedClientFactory
402+
if !p.UseK8sCachedClients {
403+
clientsFactory = clustersmngr.ClientFactory
404+
}
405+
399406
clustersManager := clustersmngr.NewClustersManager(
400407
mcf,
401408
nsaccess.NewChecker(nsaccess.DefautltWegoAppRules),
402409
log,
403410
clustersManagerScheme,
404-
clustersmngr.NewClustersClientsPool,
411+
clientsFactory,
405412
clustersmngr.DefaultKubeConfigOptions,
406413
)
407414
clustersManager.Start(ctx)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/sirupsen/logrus v1.9.0
1616
github.com/spf13/cobra v1.5.0
1717
github.com/stretchr/testify v1.8.0
18-
github.com/weaveworks/weave-gitops v0.10.0
18+
github.com/weaveworks/weave-gitops v0.10.1-0.20221017171530-29971f9a3686
1919
github.com/weaveworks/weave-gitops-enterprise-credentials v0.0.2
2020
github.com/weaveworks/weave-gitops-enterprise/common v0.0.0
2121
gopkg.in/yaml.v3 v3.0.1 // indirect
@@ -48,7 +48,7 @@ require (
4848
github.com/mkmik/multierror v0.3.0
4949
github.com/onsi/ginkgo/v2 v2.1.6
5050
github.com/spf13/viper v1.12.0
51-
github.com/weaveworks/cluster-controller v1.3.2
51+
github.com/weaveworks/cluster-controller v1.4.0
5252
github.com/weaveworks/go-checkpoint v0.0.0-20220223124739-fd9899e2b4f2
5353
github.com/weaveworks/policy-agent/api v1.0.4
5454
github.com/weaveworks/progressive-delivery v0.0.0-20220915081124-d9f0c4063521

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,10 @@ github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD
13471347
github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8=
13481348
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
13491349
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE=
1350-
github.com/weaveworks/cluster-controller v1.3.2 h1:MBM2u5KDHhizXyx0oEByPXejgvg9e1qTQZuYtXgRVrI=
1351-
github.com/weaveworks/cluster-controller v1.3.2/go.mod h1:e0Bka2iXVITQG+cG7/u8ZOB5QTaguMmgg+n5nrYaqxQ=
1350+
github.com/weaveworks/cluster-controller v1.3.3-0.20221011162507-f8e726094d4b h1:STpHllhYZPyrnJT2bH7d/nRpZ7bh5dWu1s3MZTZH98k=
1351+
github.com/weaveworks/cluster-controller v1.3.3-0.20221011162507-f8e726094d4b/go.mod h1:NrgkuiyejE2nizsiXNeqaNWfVhpvG2SlAiWHnxKIS4U=
1352+
github.com/weaveworks/cluster-controller v1.4.0 h1:AFvWGm3Lpad6zcbx4IMOvsv1vzUIXnevNScv9pI/D00=
1353+
github.com/weaveworks/cluster-controller v1.4.0/go.mod h1:NrgkuiyejE2nizsiXNeqaNWfVhpvG2SlAiWHnxKIS4U=
13521354
github.com/weaveworks/go-checkpoint v0.0.0-20220223124739-fd9899e2b4f2 h1:EWUmjQdHzmBimPxGIus5JOvNPu+tWxOTC+Q4w9fJOok=
13531355
github.com/weaveworks/go-checkpoint v0.0.0-20220223124739-fd9899e2b4f2/go.mod h1:HfUHaw/CuYj2phXCM9etFQwvOQ3W0786feIEs9OMFHk=
13541356
github.com/weaveworks/pipeline-controller/api v0.0.0-20220916165727-cb8504f08c22 h1:Nn0uFFztrATEyTIwYd0yLXKk7Ee9Ndx6P3DFZsU4TxU=
@@ -1359,8 +1361,8 @@ github.com/weaveworks/progressive-delivery v0.0.0-20220915081124-d9f0c4063521 h1
13591361
github.com/weaveworks/progressive-delivery v0.0.0-20220915081124-d9f0c4063521/go.mod h1:ib0H6jkIMkHnz/2BpE2Lvj/D6xwhiieiWjUwAcoZ+Oo=
13601362
github.com/weaveworks/tf-controller/api v0.0.0-20220829140311-2391c1d66e7c h1:mbiOaxEammDTQX0wWZdJ6cfIgGqP7Zf3zyF+qbeTG0s=
13611363
github.com/weaveworks/tf-controller/api v0.0.0-20220829140311-2391c1d66e7c/go.mod h1:I+QGICmh0CMNJnbJamO6+tfdHvOrceMQdYZcj2AzBVA=
1362-
github.com/weaveworks/weave-gitops v0.10.0 h1:2P6kpzlaJ5Tig2KoUdoQ10yacrzMz4YFQpyGNOeOkb4=
1363-
github.com/weaveworks/weave-gitops v0.10.0/go.mod h1:aN9coD172ZhF7xdRFMSxIE3Zi6+W2b2usDZcqskS5rM=
1364+
github.com/weaveworks/weave-gitops v0.10.1-0.20221017171530-29971f9a3686 h1:T4YL+fhheLpkW9shiktIiBVCgj5fcAlDFxcjHrCr1OQ=
1365+
github.com/weaveworks/weave-gitops v0.10.1-0.20221017171530-29971f9a3686/go.mod h1:p6+/3shchN5kCMRZ6L47cd59PEPijQ8wehhFFDKV3fs=
13641366
github.com/weaveworks/weave-gitops-enterprise-credentials v0.0.2 h1:7jeiQehqmI4ds6YIq8TW1Vqhlb6V7G2BVRJ8VM3r99I=
13651367
github.com/weaveworks/weave-gitops-enterprise-credentials v0.0.2/go.mod h1:6PMYg+VtSNePnP7EXyNG+/hNRNZ3r0mQtolIZU4s/J0=
13661368
github.com/xanzy/go-gitlab v0.73.1 h1:UMagqUZLJdjss1SovIC+kJCH4k2AZWXl58gJd38Y/hI=

internal/entesting/grpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func MakeGRPCServer(t *testing.T, cfg *rest.Config, k8sEnv *testutils.K8sTestEnv
3939
&nsChecker,
4040
log,
4141
nil,
42-
clustersmngr.NewClustersClientsPool,
42+
clustersmngr.ClientFactory,
4343
clustersmngr.DefaultKubeConfigOptions,
4444
)
4545

0 commit comments

Comments
 (0)