Skip to content

Commit 49d1b8c

Browse files
Merge pull request #2744 from ncdc/make-syncer-vw-global
🌱 Make syncer vw global
2 parents b505b8a + c0b0f1a commit 49d1b8c

File tree

7 files changed

+37
-46
lines changed

7 files changed

+37
-46
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ test-e2e-shared: require-kind build-all build-kind-images
279279
./bin/test-server --quiet --log-file-path="$(LOG_DIR)/kcp.log" $(TEST_SERVER_ARGS) 2>&1 & PID=$$! && echo "PID $$PID" && \
280280
trap 'kill -TERM $$PID' TERM INT EXIT && \
281281
while [ ! -f "$(WORK_DIR)/.kcp/ready-to-test" ]; do sleep 1; done && \
282+
echo 'Starting test(s)' && \
282283
NO_GORUN=1 GOOS=$(OS) GOARCH=$(ARCH) \
283284
$(GO_TEST) -race $(COUNT_ARG) $(PARALLELISM_ARG) $(WHAT) $(TEST_ARGS) \
284285
-args --use-default-kcp-server --syncer-image="$(SYNCER_IMAGE)" --kcp-test-image="$(TEST_IMAGE)" --pcluster-kubeconfig="$(abspath $(WORK_DIR)/.kcp/kind.kubeconfig)" $(SUITES_ARG) \
@@ -303,6 +304,7 @@ test-e2e-shared-minimal: build-all
303304
./bin/test-server --quiet --log-file-path="$(LOG_DIR)/kcp.log" $(TEST_SERVER_ARGS) 2>&1 & PID=$$! && echo "PID $$PID" && \
304305
trap 'kill -TERM $$PID' TERM INT EXIT && \
305306
while [ ! -f "$(WORK_DIR)/.kcp/ready-to-test" ]; do sleep 1; done && \
307+
echo 'Starting test(s)' && \
306308
NO_GORUN=1 GOOS=$(OS) GOARCH=$(ARCH) \
307309
$(GO_TEST) -race $(COUNT_ARG) $(PARALLELISM_ARG) $(WHAT) $(TEST_ARGS) \
308310
-args --use-default-kcp-server $(SUITES_ARG) \
@@ -329,6 +331,7 @@ test-e2e-sharded: require-kind build-all build-kind-images
329331
./bin/sharded-test-server --quiet --v=2 --log-dir-path="$(LOG_DIR)" --work-dir-path="$(WORK_DIR)" --shard-run-virtual-workspaces=false $(TEST_SERVER_ARGS) --number-of-shards=$(SHARDS) 2>&1 & PID=$$!; echo "PID $$PID" && \
330332
trap 'kill -TERM $$PID' TERM INT EXIT && \
331333
while [ ! -f "$(WORK_DIR)/.kcp/ready-to-test" ]; do sleep 1; done && \
334+
echo 'Starting test(s)' && \
332335
NO_GORUN=1 GOOS=$(OS) GOARCH=$(ARCH) \
333336
$(GO_TEST) -race $(COUNT_ARG) $(PARALLELISM_ARG) $(WHAT) $(TEST_ARGS) \
334337
-args --use-default-kcp-server --shard-kubeconfigs=root=$(PWD)/.kcp-0/admin.kubeconfig$(shell if [ $(SHARDS) -gt 1 ]; then seq 1 $$[$(SHARDS) - 1]; fi | while read n; do echo -n ",shard-$$n=$(PWD)/.kcp-$$n/admin.kubeconfig"; done) \
@@ -355,6 +358,7 @@ test-e2e-sharded-minimal: build-all
355358
UNSAFE_E2E_HACK_DISABLE_ETCD_FSYNC=true NO_GORUN=1 ./bin/sharded-test-server --quiet --v=2 --log-dir-path="$(LOG_DIR)" --work-dir-path="$(WORK_DIR)" --shard-run-virtual-workspaces=false $(TEST_SERVER_ARGS) --number-of-shards=$(SHARDS) 2>&1 & PID=$$!; echo "PID $$PID" && \
356359
trap 'kill -TERM $$PID' TERM INT EXIT && \
357360
while [ ! -f "$(WORK_DIR)/.kcp/ready-to-test" ]; do sleep 1; done && \
361+
echo 'Starting test(s)' && \
358362
NO_GORUN=1 GOOS=$(OS) GOARCH=$(ARCH) $(GO_TEST) -race $(COUNT_ARG) $(PARALLELISM_ARG) $(WHAT) $(TEST_ARGS) \
359363
-args --use-default-kcp-server --shard-kubeconfigs=root=$(PWD)/.kcp-0/admin.kubeconfig$(shell if [ $(SHARDS) -gt 1 ]; then seq 1 $$[$(SHARDS) - 1]; fi | while read n; do echo -n ",shard-$$n=$(PWD)/.kcp-$$n/admin.kubeconfig"; done) \
360364
$(SUITES_ARGS) \

pkg/reconciler/cache/replication/replication_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ import (
3939
apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1"
4040
"github.com/kcp-dev/kcp/pkg/apis/core"
4141
corev1alpha1 "github.com/kcp-dev/kcp/pkg/apis/core/v1alpha1"
42+
schedulingv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/scheduling/v1alpha1"
4243
tenancyv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/tenancy/v1alpha1"
44+
workloadv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/workload/v1alpha1"
4345
cacheclient "github.com/kcp-dev/kcp/pkg/cache/client"
4446
"github.com/kcp-dev/kcp/pkg/cache/client/shard"
4547
kcpinformers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions"
@@ -114,12 +116,12 @@ func NewController(
114116
local: localKcpInformers.Tenancy().V1alpha1().WorkspaceTypes().Informer(),
115117
global: globalKcpInformers.Tenancy().V1alpha1().WorkspaceTypes().Informer(),
116118
},
117-
tenancyv1alpha1.SchemeGroupVersion.WithResource("synctargets"): {
119+
workloadv1alpha1.SchemeGroupVersion.WithResource("synctargets"): {
118120
kind: "SyncTarget",
119121
local: localKcpInformers.Workload().V1alpha1().SyncTargets().Informer(),
120122
global: globalKcpInformers.Workload().V1alpha1().SyncTargets().Informer(),
121123
},
122-
tenancyv1alpha1.SchemeGroupVersion.WithResource("locations"): {
124+
schedulingv1alpha1.SchemeGroupVersion.WithResource("locations"): {
123125
kind: "Location",
124126
local: localKcpInformers.Scheduling().V1alpha1().Locations().Informer(),
125127
global: globalKcpInformers.Scheduling().V1alpha1().Locations().Informer(),

pkg/virtual/options/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (o *Options) NewVirtualWorkspaces(
6767
wildcardKubeInformers kcpkubernetesinformers.SharedInformerFactory,
6868
wildcardKcpInformers, cachedKcpInformers kcpinformers.SharedInformerFactory,
6969
) ([]rootapiserver.NamedVirtualWorkspace, error) {
70-
syncer, err := o.Syncer.NewVirtualWorkspaces(rootPathPrefix, config, wildcardKcpInformers)
70+
syncer, err := o.Syncer.NewVirtualWorkspaces(rootPathPrefix, config, cachedKcpInformers)
7171
if err != nil {
7272
return nil, err
7373
}

pkg/virtual/syncer/builder/build.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
"k8s.io/client-go/tools/cache"
2727

2828
workloadv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/workload/v1alpha1"
29-
kcpclientset "github.com/kcp-dev/kcp/pkg/client/clientset/versioned/cluster"
3029
kcpinformers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions"
30+
"github.com/kcp-dev/kcp/pkg/indexers"
3131
"github.com/kcp-dev/kcp/pkg/virtual/framework/forwardingregistry"
3232
"github.com/kcp-dev/kcp/pkg/virtual/framework/rootapiserver"
3333
"github.com/kcp-dev/kcp/pkg/virtual/syncer/controllers/apireconciler"
@@ -48,31 +48,30 @@ func BuildVirtualWorkspace(
4848
rootPathPrefix string,
4949
kubeClusterClient kcpkubernetesclientset.ClusterInterface,
5050
dynamicClusterClient kcpdynamic.ClusterInterface,
51-
kcpClusterClient kcpclientset.ClusterInterface,
52-
wildcardKcpInformers kcpinformers.SharedInformerFactory,
51+
cachedKCPInformers kcpinformers.SharedInformerFactory,
5352
) []rootapiserver.NamedVirtualWorkspace {
5453
if !strings.HasSuffix(rootPathPrefix, "/") {
5554
rootPathPrefix += "/"
5655
}
5756

5857
// Setup the APIReconciler indexes to share between both virtualworkspaces.
59-
if err := wildcardKcpInformers.Workload().V1alpha1().SyncTargets().Informer().AddIndexers(cache.Indexers{
60-
apireconciler.IndexSyncTargetsByExport: apireconciler.IndexSyncTargetsByExports,
61-
}); err != nil {
62-
return nil
63-
}
64-
65-
if err := wildcardKcpInformers.Apis().V1alpha1().APIExports().Informer().AddIndexers(cache.Indexers{
66-
apireconciler.IndexAPIExportsByAPIResourceSchema: apireconciler.IndexAPIExportsByAPIResourceSchemas,
67-
}); err != nil {
68-
return nil
69-
}
58+
indexers.AddIfNotPresentOrDie(
59+
cachedKCPInformers.Workload().V1alpha1().SyncTargets().Informer().GetIndexer(),
60+
cache.Indexers{
61+
apireconciler.IndexSyncTargetsByExport: apireconciler.IndexSyncTargetsByExports,
62+
},
63+
)
64+
indexers.AddIfNotPresentOrDie(
65+
cachedKCPInformers.Apis().V1alpha1().APIExports().Informer().GetIndexer(),
66+
cache.Indexers{
67+
apireconciler.IndexAPIExportsByAPIResourceSchema: apireconciler.IndexAPIExportsByAPIResourceSchemas,
68+
},
69+
)
7070

7171
provider := templateProvider{
7272
kubeClusterClient: kubeClusterClient,
7373
dynamicClusterClient: dynamicClusterClient,
74-
kcpClusterClient: kcpClusterClient,
75-
wildcardKcpInformers: wildcardKcpInformers,
74+
cachedKCPInformers: cachedKCPInformers,
7675
rootPathPrefix: rootPathPrefix,
7776
}
7877

pkg/virtual/syncer/builder/template.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1"
3939
workloadv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/workload/v1alpha1"
4040
"github.com/kcp-dev/kcp/pkg/authorization/delegated"
41-
kcpclientset "github.com/kcp-dev/kcp/pkg/client/clientset/versioned/cluster"
4241
kcpinformers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions"
4342
"github.com/kcp-dev/kcp/pkg/virtual/framework"
4443
virtualworkspacesdynamic "github.com/kcp-dev/kcp/pkg/virtual/framework/dynamic"
@@ -54,8 +53,7 @@ import (
5453
type templateProvider struct {
5554
kubeClusterClient kcpkubernetesclientset.ClusterInterface
5655
dynamicClusterClient kcpdynamic.ClusterInterface
57-
kcpClusterClient kcpclientset.ClusterInterface
58-
wildcardKcpInformers kcpinformers.SharedInformerFactory
56+
cachedKCPInformers kcpinformers.SharedInformerFactory
5957
rootPathPrefix string
6058
}
6159

@@ -70,8 +68,8 @@ type templateParameters struct {
7068
storageWrapperBuilder func(labels.Requirements) forwardingregistry.StorageWrapper
7169
}
7270

73-
func (p *templateProvider) newTemplate(parameters templateParameters) template {
74-
return template{
71+
func (p *templateProvider) newTemplate(parameters templateParameters) *template {
72+
return &template{
7573
templateProvider: *p,
7674
templateParameters: parameters,
7775
readyCh: make(chan struct{}),
@@ -120,7 +118,7 @@ func (t *template) resolveRootPath(urlPath string, requestContext context.Contex
120118

121119
// In order to avoid conflicts with reusing deleted synctarget names, let's make sure that the synctarget name and synctarget UID match, if not,
122120
// that likely means that a syncer is running with a stale synctarget that got deleted.
123-
syncTarget, err := t.wildcardKcpInformers.Workload().V1alpha1().SyncTargets().Cluster(clusterName).Lister().Get(syncTargetName)
121+
syncTarget, err := t.cachedKCPInformers.Workload().V1alpha1().SyncTargets().Cluster(clusterName).Lister().Get(syncTargetName)
124122
if err != nil {
125123
utilruntime.HandleError(fmt.Errorf("failed to get synctarget %s|%s: %w", path, syncTargetName, err))
126124
return
@@ -205,10 +203,9 @@ func (t *template) authorize(ctx context.Context, a authorizer.Attributes) (auth
205203
func (t *template) bootstrapManagement(mainConfig genericapiserver.CompletedConfig) (apidefinition.APIDefinitionSetGetter, error) {
206204
apiReconciler, err := apireconciler.NewAPIReconciler(
207205
t.virtualWorkspaceName,
208-
t.kcpClusterClient,
209-
t.wildcardKcpInformers.Workload().V1alpha1().SyncTargets(),
210-
t.wildcardKcpInformers.Apis().V1alpha1().APIResourceSchemas(),
211-
t.wildcardKcpInformers.Apis().V1alpha1().APIExports(),
206+
t.cachedKCPInformers.Workload().V1alpha1().SyncTargets(),
207+
t.cachedKCPInformers.Apis().V1alpha1().APIResourceSchemas(),
208+
t.cachedKCPInformers.Apis().V1alpha1().APIExports(),
212209
func(syncTargetClusterName logicalcluster.Name, syncTargetName string, apiResourceSchema *apisv1alpha1.APIResourceSchema, version string, apiExportIdentityHash string) (apidefinition.APIDefinition, error) {
213210
syncTargetKey := workloadv1alpha1.ToSyncTargetKey(syncTargetClusterName, syncTargetName)
214211
requirements, selectable := labels.SelectorFromSet(map[string]string{
@@ -244,9 +241,9 @@ func (t *template) bootstrapManagement(mainConfig genericapiserver.CompletedConf
244241
defer close(t.readyCh)
245242

246243
for name, informer := range map[string]cache.SharedIndexInformer{
247-
"synctargets": t.wildcardKcpInformers.Workload().V1alpha1().SyncTargets().Informer(),
248-
"apiresourceschemas": t.wildcardKcpInformers.Apis().V1alpha1().APIResourceSchemas().Informer(),
249-
"apiexports": t.wildcardKcpInformers.Apis().V1alpha1().APIExports().Informer(),
244+
"synctargets": t.cachedKCPInformers.Workload().V1alpha1().SyncTargets().Informer(),
245+
"apiresourceschemas": t.cachedKCPInformers.Apis().V1alpha1().APIResourceSchemas().Informer(),
246+
"apiexports": t.cachedKCPInformers.Apis().V1alpha1().APIExports().Informer(),
250247
} {
251248
if !cache.WaitForNamedCacheSync(name, hookContext.StopCh, informer.HasSynced) {
252249
klog.Background().Error(nil, "informer not synced")
@@ -263,7 +260,7 @@ func (t *template) bootstrapManagement(mainConfig genericapiserver.CompletedConf
263260
return apiReconciler, nil
264261
}
265262

266-
func (t template) buildVirtualWorkspace() *virtualworkspacesdynamic.DynamicVirtualWorkspace {
263+
func (t *template) buildVirtualWorkspace() *virtualworkspacesdynamic.DynamicVirtualWorkspace {
267264
return &virtualworkspacesdynamic.DynamicVirtualWorkspace{
268265
RootPathResolver: framework.RootPathResolverFunc(t.resolveRootPath),
269266
Authorizer: authorizer.AuthorizerFunc(t.authorize),

pkg/virtual/syncer/controllers/apireconciler/syncer_apireconciler_controller.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737

3838
apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1"
3939
workloadv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/workload/v1alpha1"
40-
kcpclientset "github.com/kcp-dev/kcp/pkg/client/clientset/versioned/cluster"
4140
apisv1alpha1informers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions/apis/v1alpha1"
4241
workloadv1alpha1informers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions/workload/v1alpha1"
4342
apisv1alpha1listers "github.com/kcp-dev/kcp/pkg/client/listers/apis/v1alpha1"
@@ -59,7 +58,6 @@ type AllowedAPIfilterFunc func(apiGroupResource schema.GroupResource) bool
5958

6059
func NewAPIReconciler(
6160
virtualWorkspaceName string,
62-
kcpClusterClient kcpclientset.ClusterInterface,
6361
syncTargetInformer workloadv1alpha1informers.SyncTargetClusterInformer,
6462
apiResourceSchemaInformer apisv1alpha1informers.APIResourceSchemaClusterInformer,
6563
apiExportInformer apisv1alpha1informers.APIExportClusterInformer,
@@ -71,8 +69,6 @@ func NewAPIReconciler(
7169
c := &APIReconciler{
7270
virtualWorkspaceName: virtualWorkspaceName,
7371

74-
kcpClusterClient: kcpClusterClient,
75-
7672
syncTargetLister: syncTargetInformer.Lister(),
7773
syncTargetIndexer: syncTargetInformer.Informer().GetIndexer(),
7874

@@ -128,8 +124,6 @@ func NewAPIReconciler(
128124
type APIReconciler struct {
129125
virtualWorkspaceName string
130126

131-
kcpClusterClient kcpclientset.ClusterInterface
132-
133127
syncTargetLister workloadv1alpha1listers.SyncTargetClusterLister
134128
syncTargetIndexer cache.Indexer
135129

pkg/virtual/syncer/options/options.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"k8s.io/client-go/rest"
2525

26-
kcpclientset "github.com/kcp-dev/kcp/pkg/client/clientset/versioned/cluster"
2726
kcpinformers "github.com/kcp-dev/kcp/pkg/client/informers/externalversions"
2827
"github.com/kcp-dev/kcp/pkg/virtual/framework/rootapiserver"
2928
"github.com/kcp-dev/kcp/pkg/virtual/syncer/builder"
@@ -53,13 +52,9 @@ func (o *Syncer) Validate(flagPrefix string) []error {
5352
func (o *Syncer) NewVirtualWorkspaces(
5453
rootPathPrefix string,
5554
config *rest.Config,
56-
wildcardKcpInformers kcpinformers.SharedInformerFactory,
55+
cachedKCPInformers kcpinformers.SharedInformerFactory,
5756
) (workspaces []rootapiserver.NamedVirtualWorkspace, err error) {
5857
config = rest.AddUserAgent(rest.CopyConfig(config), "syncer-virtual-workspace")
59-
kcpClusterClient, err := kcpclientset.NewForConfig(config)
60-
if err != nil {
61-
return nil, err
62-
}
6358
kubeClusterClient, err := kcpkubernetesclientset.NewForConfig(config)
6459
if err != nil {
6560
return nil, err
@@ -69,5 +64,5 @@ func (o *Syncer) NewVirtualWorkspaces(
6964
return nil, err
7065
}
7166

72-
return builder.BuildVirtualWorkspace(rootPathPrefix, kubeClusterClient, dynamicClusterClient, kcpClusterClient, wildcardKcpInformers), nil
67+
return builder.BuildVirtualWorkspace(rootPathPrefix, kubeClusterClient, dynamicClusterClient, cachedKCPInformers), nil
7368
}

0 commit comments

Comments
 (0)