Skip to content

Commit f4ce3f1

Browse files
committed
chore: migrated to multi-cluster provider
1 parent 2fe7417 commit f4ce3f1

File tree

10 files changed

+613
-833
lines changed

10 files changed

+613
-833
lines changed

gateway/manager/targetcluster/cluster.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/platform-mesh/golang-commons/logger"
1212
"k8s.io/client-go/rest"
1313
"sigs.k8s.io/controller-runtime/pkg/client"
14-
"sigs.k8s.io/controller-runtime/pkg/kcp"
1514

1615
"github.com/platform-mesh/kubernetes-graphql-gateway/common/auth"
1716
appConfig "github.com/platform-mesh/kubernetes-graphql-gateway/common/config"
@@ -120,12 +119,9 @@ func (tc *TargetCluster) connect(appCfg appConfig.Config, metadata *ClusterMetad
120119
})
121120
}
122121

123-
// Create client - use KCP-aware client only for KCP mode, standard client otherwise
124-
if appCfg.EnableKcp {
125-
tc.client, err = kcp.NewClusterAwareClientWithWatch(tc.restCfg, client.Options{})
126-
} else {
127-
tc.client, err = client.NewWithWatch(tc.restCfg, client.Options{})
128-
}
122+
// Create client - with multicluster-provider, we use standard client for all modes
123+
// The multicluster-runtime handles cluster awareness when needed
124+
tc.client, err = client.NewWithWatch(tc.restCfg, client.Options{})
129125
if err != nil {
130126
return fmt.Errorf("failed to create cluster client: %w", err)
131127
}

gateway/manager/targetcluster/graphql.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import (
1212
"github.com/graphql-go/graphql"
1313
"github.com/graphql-go/handler"
1414
"github.com/kcp-dev/logicalcluster/v3"
15-
"sigs.k8s.io/controller-runtime/pkg/kontext"
1615

1716
"github.com/platform-mesh/golang-commons/logger"
1817

1918
appConfig "github.com/platform-mesh/kubernetes-graphql-gateway/common/config"
2019
"github.com/platform-mesh/kubernetes-graphql-gateway/gateway/manager/roundtripper"
2120
)
2221

22+
// Context key types to avoid collisions
23+
type LogicalClusterKey struct{}
24+
2325
// GraphQLHandler wraps a GraphQL schema and HTTP handler
2426
type GraphQLHandler struct {
2527
Schema *graphql.Schema
@@ -57,14 +59,14 @@ func (s *GraphQLServer) CreateHandler(schema *graphql.Schema) *GraphQLHandler {
5759
// SetContexts sets the required contexts for KCP and authentication
5860
func SetContexts(r *http.Request, workspace, token string, enableKcp bool) *http.Request {
5961
if enableKcp {
60-
// For virtual workspaces, use the KCP workspace from the request context if available
61-
// This allows the URL to specify the actual KCP workspace (e.g., root, root:orgs)
62-
// while keeping the file mapping based on the virtual workspace name
62+
// For virtual workspaces, the multicluster-runtime will handle cluster context
63+
// We just need to store the workspace name in the context for potential future use
6364
kcpWorkspaceName := workspace
6465
if kcpWorkspace, ok := r.Context().Value(kcpWorkspaceKey).(string); ok && kcpWorkspace != "" {
6566
kcpWorkspaceName = kcpWorkspace
6667
}
67-
r = r.WithContext(kontext.WithCluster(r.Context(), logicalcluster.Name(kcpWorkspaceName)))
68+
// Store the logical cluster name in context without using KCP-specific kontext
69+
r = r.WithContext(context.WithValue(r.Context(), LogicalClusterKey{}, logicalcluster.Name(kcpWorkspaceName)))
6870
}
6971
return r.WithContext(context.WithValue(r.Context(), roundtripper.TokenKey{}, token))
7072
}

gateway/manager/targetcluster/graphql_test.go

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

1212
"github.com/graphql-go/graphql"
1313
"github.com/kcp-dev/logicalcluster/v3"
14-
"sigs.k8s.io/controller-runtime/pkg/kontext"
1514

1615
"github.com/platform-mesh/golang-commons/logger/testlogger"
1716
"github.com/platform-mesh/kubernetes-graphql-gateway/common"
@@ -197,8 +196,8 @@ func TestSetContexts(t *testing.T) {
197196

198197
// Check KCP context
199198
if tt.expectKcp {
200-
clusterFromCtx, _ := kontext.ClusterFrom(result.Context())
201-
if clusterFromCtx != logicalcluster.Name(tt.workspace) {
199+
clusterFromCtx, ok := result.Context().Value(targetcluster.LogicalClusterKey{}).(logicalcluster.Name)
200+
if !ok || clusterFromCtx != logicalcluster.Name(tt.workspace) {
202201
t.Errorf("expected cluster %q in context, got %q", tt.workspace, clusterFromCtx)
203202
}
204203
}

go.mod

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ module github.com/platform-mesh/kubernetes-graphql-gateway
33
go 1.24.3
44

55
replace (
6-
github.com/google/cel-go => github.com/google/cel-go v0.26.1
6+
github.com/google/cel-go => github.com/google/cel-go v0.26.0
77
// this PR introduces newer version of graphiQL that supports headers
88
// https://github.com/graphql-go/handler/pull/93
99
github.com/graphql-go/handler => github.com/vertex451/handler v0.0.0-20250124125145-ed328e3cf42a
10-
k8s.io/api => k8s.io/api v0.33.3
11-
k8s.io/apimachinery => k8s.io/apimachinery v0.33.3
12-
k8s.io/client-go => k8s.io/client-go v0.32.4
13-
sigs.k8s.io/controller-runtime => github.com/kcp-dev/controller-runtime v0.19.0-kcp.1.0.20250129100209-5eaf4c7b6056
10+
// Pin controller-runtime to v0.21.0 to avoid compatibility issues
11+
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.21.0
1412
)
1513

1614
require (
@@ -24,8 +22,9 @@ require (
2422
github.com/hashicorp/go-multierror v1.1.1
2523
github.com/kcp-dev/kcp/sdk v0.28.1
2624
github.com/kcp-dev/logicalcluster/v3 v3.0.5
25+
github.com/kcp-dev/multicluster-provider v0.0.0-20250827085327-2b5ca378b7b4
2726
github.com/pkg/errors v0.9.1
28-
github.com/platform-mesh/account-operator v0.1.22
27+
github.com/platform-mesh/account-operator v0.1.23
2928
github.com/platform-mesh/golang-commons v0.1.23
3029
github.com/prometheus/client_golang v1.23.0
3130
github.com/rs/zerolog v1.34.0
@@ -37,12 +36,13 @@ require (
3736
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b
3837
golang.org/x/text v0.28.0
3938
gopkg.in/yaml.v3 v3.0.1
40-
k8s.io/api v0.33.3
41-
k8s.io/apiextensions-apiserver v0.33.3
42-
k8s.io/apimachinery v0.33.3
43-
k8s.io/client-go v0.33.3
44-
k8s.io/kube-openapi v0.0.0-20250701173324-9bd5c66d9911
39+
k8s.io/api v0.34.0
40+
k8s.io/apiextensions-apiserver v0.34.0
41+
k8s.io/apimachinery v0.34.0
42+
k8s.io/client-go v0.34.0
43+
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
4544
sigs.k8s.io/controller-runtime v0.22.0
45+
sigs.k8s.io/multicluster-runtime v0.21.0-alpha.8
4646
)
4747

4848
require (
@@ -54,10 +54,10 @@ require (
5454
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
5555
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5656
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
57-
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
57+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
5858
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
5959
github.com/felixge/httpsnoop v1.0.4 // indirect
60-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
60+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
6161
github.com/getsentry/sentry-go v0.35.1 // indirect
6262
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
6363
github.com/go-logr/logr v1.4.3 // indirect
@@ -69,22 +69,21 @@ require (
6969
github.com/go-openapi/swag v0.23.0 // indirect
7070
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
7171
github.com/gogo/protobuf v1.3.2 // indirect
72-
github.com/golang/protobuf v1.5.4 // indirect
72+
github.com/google/btree v1.1.3 // indirect
7373
github.com/google/cel-go v0.26.0 // indirect
7474
github.com/google/go-cmp v0.7.0 // indirect
7575
github.com/google/uuid v1.6.0 // indirect
7676
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
7777
github.com/hashicorp/errwrap v1.1.0 // indirect
78-
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
7978
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8079
github.com/josharian/intern v1.0.0 // indirect
8180
github.com/json-iterator/go v1.1.12 // indirect
82-
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 // indirect
81+
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51 // indirect
8382
github.com/mailru/easyjson v0.9.0 // indirect
8483
github.com/mattn/go-colorable v0.1.14 // indirect
8584
github.com/mattn/go-isatty v0.0.20 // indirect
8685
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
87-
github.com/modern-go/reflect2 v1.0.2 // indirect
86+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
8887
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8988
github.com/onsi/gomega v1.36.2 // indirect
9089
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
@@ -114,7 +113,7 @@ require (
114113
go.uber.org/multierr v1.11.0 // indirect
115114
go.uber.org/zap v1.27.0 // indirect
116115
go.yaml.in/yaml/v2 v2.4.2 // indirect
117-
go.yaml.in/yaml/v3 v3.0.3 // indirect
116+
go.yaml.in/yaml/v3 v3.0.4 // indirect
118117
golang.org/x/crypto v0.40.0 // indirect
119118
golang.org/x/net v0.42.0 // indirect
120119
golang.org/x/oauth2 v0.30.0 // indirect
@@ -129,13 +128,13 @@ require (
129128
google.golang.org/protobuf v1.36.6 // indirect
130129
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
131130
gopkg.in/inf.v0 v0.9.1 // indirect
132-
k8s.io/apiserver v0.33.3 // indirect
133-
k8s.io/component-base v0.33.3 // indirect
131+
k8s.io/apiserver v0.34.0 // indirect
132+
k8s.io/component-base v0.34.0 // indirect
134133
k8s.io/klog/v2 v2.130.1 // indirect
135134
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d // indirect
136135
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
137136
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
138137
sigs.k8s.io/randfill v1.0.0 // indirect
139-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
138+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
140139
sigs.k8s.io/yaml v1.6.0 // indirect
141140
)

0 commit comments

Comments
 (0)