Skip to content

Commit 3c0c16d

Browse files
authored
Feat: virtual workspace (#282)
* feat: virtual ws support On-behalf-of: @SAP [email protected] Signed-off-by: Artem Shcherbatiuk <[email protected]>
1 parent 04b60fc commit 3c0c16d

Some content is hidden

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

63 files changed

+5430
-1024
lines changed

cmd/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var gatewayCmd = &cobra.Command{
4848

4949
ctrl.SetLogger(log.Logr())
5050

51-
gatewayInstance, err := manager.NewGateway(log, appCfg)
51+
gatewayInstance, err := manager.NewGateway(ctx, log, appCfg)
5252
if err != nil {
5353
log.Error().Err(err).Msg("Error creating gateway")
5454
return fmt.Errorf("failed to create gateway: %w", err)

cmd/listener.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,29 @@ var listenCmd = &cobra.Command{
105105
// Create the appropriate reconciler based on configuration
106106
var reconcilerInstance reconciler.CustomReconciler
107107
if appCfg.EnableKcp {
108-
reconcilerInstance, err = kcp.NewKCPReconciler(appCfg, reconcilerOpts, log)
108+
kcpReconciler, err := kcp.NewKCPReconciler(appCfg, reconcilerOpts, log)
109+
if err != nil {
110+
log.Error().Err(err).Msg("unable to create KCP reconciler")
111+
os.Exit(1)
112+
}
113+
114+
// Start virtual workspace watching if path is configured
115+
if appCfg.Listener.VirtualWorkspacesConfigPath != "" {
116+
go func() {
117+
if err := kcpReconciler.StartVirtualWorkspaceWatching(ctx, appCfg.Listener.VirtualWorkspacesConfigPath); err != nil {
118+
log.Error().Err(err).Msg("failed to start virtual workspace watching")
119+
os.Exit(1)
120+
}
121+
}()
122+
}
123+
124+
reconcilerInstance = kcpReconciler
109125
} else {
110126
reconcilerInstance, err = clusteraccess.CreateMultiClusterReconciler(appCfg, reconcilerOpts, log)
111-
}
112-
if err != nil {
113-
log.Error().Err(err).Msg("unable to create reconciler")
114-
os.Exit(1)
127+
if err != nil {
128+
log.Error().Err(err).Msg("unable to create cluster access reconciler")
129+
os.Exit(1)
130+
}
115131
}
116132

117133
// Setup reconciler with its own manager and start everything

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func initConfig() {
7575
v.SetDefault("gateway-cors-enabled", false)
7676
v.SetDefault("gateway-cors-allowed-origins", "*")
7777
v.SetDefault("gateway-cors-allowed-headers", "*")
78+
// Gateway URL
79+
v.SetDefault("gateway-url-virtual-workspace-prefix", "virtual-workspace")
80+
v.SetDefault("gateway-url-default-kcp-workspace", "root")
81+
v.SetDefault("gateway-url-graphql-suffix", "graphql")
7882
}
7983

8084
func Execute() {

common/auth/config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
// BuildConfig creates a rest.Config from cluster connection parameters
2222
// This function unifies the authentication logic used by both listener and gateway
23-
func BuildConfig(host string, auth *gatewayv1alpha1.AuthConfig, ca *gatewayv1alpha1.CAConfig, k8sClient client.Client) (*rest.Config, error) {
23+
func BuildConfig(ctx context.Context, host string, auth *gatewayv1alpha1.AuthConfig, ca *gatewayv1alpha1.CAConfig, k8sClient client.Client) (*rest.Config, error) {
2424
if host == "" {
2525
return nil, errors.New("host is required")
2626
}
@@ -34,7 +34,7 @@ func BuildConfig(host string, auth *gatewayv1alpha1.AuthConfig, ca *gatewayv1alp
3434

3535
// Handle CA configuration first
3636
if ca != nil {
37-
caData, err := ExtractCAData(ca, k8sClient)
37+
caData, err := ExtractCAData(ctx, ca, k8sClient)
3838
if err != nil {
3939
return nil, errors.Join(errors.New("failed to extract CA data"), err)
4040
}
@@ -46,7 +46,7 @@ func BuildConfig(host string, auth *gatewayv1alpha1.AuthConfig, ca *gatewayv1alp
4646

4747
// Handle Auth configuration
4848
if auth != nil {
49-
err := ConfigureAuthentication(config, auth, k8sClient)
49+
err := ConfigureAuthentication(ctx, config, auth, k8sClient)
5050
if err != nil {
5151
return nil, errors.Join(errors.New("failed to configure authentication"), err)
5252
}
@@ -118,13 +118,11 @@ func BuildConfigFromMetadata(host string, authType, token, kubeconfig, certData,
118118
}
119119

120120
// ExtractCAData extracts CA certificate data from secret or configmap references
121-
func ExtractCAData(ca *gatewayv1alpha1.CAConfig, k8sClient client.Client) ([]byte, error) {
121+
func ExtractCAData(ctx context.Context, ca *gatewayv1alpha1.CAConfig, k8sClient client.Client) ([]byte, error) {
122122
if ca == nil {
123123
return nil, nil
124124
}
125125

126-
ctx := context.Background()
127-
128126
if ca.SecretRef != nil {
129127
secret := &corev1.Secret{}
130128
namespace := ca.SecretRef.Namespace
@@ -175,13 +173,11 @@ func ExtractCAData(ca *gatewayv1alpha1.CAConfig, k8sClient client.Client) ([]byt
175173
}
176174

177175
// ConfigureAuthentication configures authentication for rest.Config from AuthConfig
178-
func ConfigureAuthentication(config *rest.Config, auth *gatewayv1alpha1.AuthConfig, k8sClient client.Client) error {
176+
func ConfigureAuthentication(ctx context.Context, config *rest.Config, auth *gatewayv1alpha1.AuthConfig, k8sClient client.Client) error {
179177
if auth == nil {
180178
return nil
181179
}
182180

183-
ctx := context.Background()
184-
185181
if auth.SecretRef != nil {
186182
secret := &corev1.Secret{}
187183
namespace := auth.SecretRef.Namespace

listener/reconciler/clusteraccess/auth_extractor_test.go renamed to common/auth/config_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package clusteraccess_test
1+
package auth
22

33
import (
44
"context"
@@ -15,7 +15,6 @@ import (
1515

1616
gatewayv1alpha1 "github.com/openmfp/kubernetes-graphql-gateway/common/apis/v1alpha1"
1717
"github.com/openmfp/kubernetes-graphql-gateway/common/mocks"
18-
"github.com/openmfp/kubernetes-graphql-gateway/listener/reconciler/clusteraccess"
1918
)
2019

2120
func TestConfigureAuthentication(t *testing.T) {
@@ -257,7 +256,7 @@ clusters:
257256
},
258257
}
259258

260-
err := clusteraccess.ConfigureAuthentication(config, tt.auth, mockClient)
259+
err := ConfigureAuthentication(t.Context(), config, tt.auth, mockClient)
261260

262261
if tt.wantErr {
263262
assert.Error(t, err)
@@ -366,7 +365,7 @@ func TestExtractAuthFromKubeconfig(t *testing.T) {
366365
},
367366
}
368367

369-
err := clusteraccess.ExtractAuthFromKubeconfig(config, tt.authInfo)
368+
err := ExtractAuthFromKubeconfig(config, tt.authInfo)
370369

371370
if tt.wantErr {
372371
assert.Error(t, err)

0 commit comments

Comments
 (0)