Skip to content

Commit 50a52e5

Browse files
dilyevskyclaude
andcommitted
[cli] implement kube-mirror Gateway API reflection controller
Add MirrorReconciler that watches local K8s Gateway API resources (Gateway, HTTPRoute, GRPCRoute, TCPRoute, TLSRoute, UDPRoute) and mirrors them to the Apoxy control plane via API aggregation. Names are deconflicted as {name}-{hash(cluster/namespace)} and ParentRefs are rewritten to reference the mirrored Gateway names. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6382a5b commit 50a52e5

File tree

2 files changed

+507
-1
lines changed

2 files changed

+507
-1
lines changed

pkg/cmd/run.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ import (
66

77
"github.com/spf13/cobra"
88
"golang.org/x/sync/errgroup"
9+
"k8s.io/apimachinery/pkg/runtime"
10+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
911
"k8s.io/client-go/kubernetes"
1012
"k8s.io/client-go/rest"
13+
ctrl "sigs.k8s.io/controller-runtime"
14+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
15+
gwapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1116

1217
configv1alpha1 "github.com/apoxy-dev/apoxy/api/config/v1alpha1"
18+
"github.com/apoxy-dev/apoxy/client/versioned"
1319
"github.com/apoxy-dev/apoxy/config"
1420
"github.com/apoxy-dev/apoxy/pkg/kube-controller/apiregistration"
1521
"github.com/apoxy-dev/apoxy/pkg/kube-controller/apiserviceproxy"
22+
"github.com/apoxy-dev/apoxy/pkg/kube-controller/controllers"
1623
"github.com/apoxy-dev/apoxy/pkg/log"
1724
)
1825

@@ -177,7 +184,34 @@ func runKubeAggregation(ctx context.Context, cfg *configv1alpha1.Config, ac *con
177184
}
178185

179186
func runKubeMirror(ctx context.Context, cfg *configv1alpha1.Config, mc *configv1alpha1.KubeMirrorConfig) error {
180-
return fmt.Errorf("kube-mirror runtime component not yet implemented")
187+
log.Infof("Starting kube-mirror component (cluster=%s, mirror=%s, namespace=%s)",
188+
mc.ClusterName, mc.Mirror, mc.Namespace)
189+
190+
kCluster, err := rest.InClusterConfig()
191+
if err != nil {
192+
return fmt.Errorf("failed to create in-cluster config: %w", err)
193+
}
194+
195+
scheme := runtime.NewScheme()
196+
utilruntime.Must(gwapiv1.Install(scheme))
197+
utilruntime.Must(gwapiv1alpha2.Install(scheme))
198+
199+
mgr, err := ctrl.NewManager(kCluster, ctrl.Options{Scheme: scheme})
200+
if err != nil {
201+
return fmt.Errorf("failed to create controller manager: %w", err)
202+
}
203+
204+
apoxyClient, err := versioned.NewForConfig(kCluster)
205+
if err != nil {
206+
return fmt.Errorf("failed to create Apoxy client: %w", err)
207+
}
208+
209+
reconciler := controllers.NewMirrorReconciler(mgr.GetClient(), apoxyClient, mc)
210+
if err := reconciler.SetupWithManager(ctx, mgr); err != nil {
211+
return fmt.Errorf("failed to setup mirror reconciler: %w", err)
212+
}
213+
214+
return mgr.Start(ctx)
181215
}
182216

183217
func init() {

0 commit comments

Comments
 (0)