Skip to content

Commit 36b621d

Browse files
committed
fix lattice service
1 parent e4ec08a commit 36b621d

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

pkg/controllers/route_controller.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
2223
"sigs.k8s.io/controller-runtime/pkg/controller"
2324

2425
"github.com/pkg/errors"
@@ -116,14 +117,11 @@ func RegisterAllRouteControllers(
116117
for _, routeInfo := range routeInfos {
117118
gv := routeInfo.gatewayApiType.GetObjectKind().GroupVersionKind().GroupVersion().String()
118119
kind := routeInfo.gatewayApiType.GetObjectKind().GroupVersionKind().Kind
119-
fmt.Printf("GVK: %s, %s", gv, kind)
120120
log.Infof(context.TODO(), "GVK: %s, %s", gv, kind)
121121
if ok, err := k8s.IsGVKSupported(mgr, gv, kind); !ok {
122122
log.Infof(context.TODO(), "GVK not supported gv: %s, kind: %s", gv, kind)
123-
fmt.Printf("GVK not supported gv: %s, kind: %s", gv, kind)
124123
if err != nil {
125124
log.Infof(context.TODO(), "GVK not supported error: %s", err)
126-
fmt.Printf("GVK not supported error: %s", err)
127125
return nil
128126
}
129127
} else {
@@ -203,6 +201,7 @@ func (r *routeReconciler) reconcile(ctx context.Context, req ctrl.Request) error
203201
if err != nil {
204202
return client.IgnoreNotFound(err)
205203
}
204+
r.log.Debugw(ctx, "u-kai reconcile after getRoute", "route", route)
206205

207206
if err = r.client.Get(ctx, req.NamespacedName, route.K8sObject()); err != nil {
208207
return client.IgnoreNotFound(err)
@@ -389,25 +388,6 @@ func (r *routeReconciler) reconcileUpsert(ctx context.Context, req ctrl.Request,
389388
return backendRefIPFamiliesErr
390389
}
391390

392-
if _, err := r.buildAndDeployModel(ctx, route); err != nil {
393-
if services.IsConflictError(err) {
394-
// Stop reconciliation of this route if the route cannot be owned / has conflict
395-
route.Status().UpdateParentRefs(route.Spec().ParentRefs()[0], config.LatticeGatewayControllerName)
396-
route.Status().UpdateRouteCondition(metav1.Condition{
397-
Type: string(gwv1.RouteConditionAccepted),
398-
Status: metav1.ConditionFalse,
399-
ObservedGeneration: route.K8sObject().GetGeneration(),
400-
Reason: "Conflicted",
401-
Message: err.Error(),
402-
})
403-
if err = r.client.Status().Update(ctx, route.K8sObject()); err != nil {
404-
return fmt.Errorf("failed to update route status for conflict due to err %w", err)
405-
}
406-
return nil
407-
}
408-
return err
409-
}
410-
411391
r.eventRecorder.Event(route.K8sObject(), corev1.EventTypeNormal,
412392
k8s.RouteEventReasonDeploySucceed, "Adding/Updating reconcile Done!")
413393

@@ -574,6 +554,20 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
574554
if gw == nil {
575555
continue // ignore status update if gw not found
576556
}
557+
gwClass := &gwv1.GatewayClass{}
558+
gwClassName := types.NamespacedName{
559+
Namespace: defaultNamespace,
560+
Name: string(gw.Spec.GatewayClassName),
561+
}
562+
err = r.client.Get(ctx, gwClassName, gwClass)
563+
if err != nil {
564+
r.ukaiLog(ctx, "Ignore Route not controlled by any GatewayClass %s, %s", route.Name(), route.Namespace())
565+
continue
566+
}
567+
if gwClass.Spec.ControllerName != config.LatticeGatewayControllerName {
568+
r.ukaiLog(ctx, "Ignore non aws-vpc-lattice Route %s, %s", route.Name(), route.Namespace())
569+
continue
570+
}
577571

578572
noMatchingParent := true
579573
for _, listener := range gw.Spec.Listeners {
@@ -605,6 +599,9 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
605599

606600
return parentStatuses, nil
607601
}
602+
func (r *routeReconciler) ukaiLog(ctx context.Context, template string, args ...interface{}) {
603+
r.log.Infof(ctx, "u-kai: "+template, args...)
604+
}
608605

609606
// set of valid Kinds for Route Backend References
610607
var validBackendKinds = utils.NewSet("Service", "ServiceImport")

pkg/gateway/model_build_lattice_service.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ func (t *latticeServiceModelBuildTask) buildLatticeService(ctx context.Context)
124124
}
125125

126126
for _, parentRef := range t.route.Spec().ParentRefs() {
127+
gw := &gwv1.Gateway{}
128+
err := t.client.Get(ctx, client.ObjectKey{Name: string(parentRef.Name), Namespace: string(*parentRef.Namespace)}, gw)
129+
if err != nil {
130+
t.log.Infof(ctx, "u-kai: Failed to get gateway %s-%s: %v", parentRef.Name, *parentRef.Namespace, err)
131+
continue
132+
}
133+
gwClass := &gwv1.GatewayClass{}
134+
err = t.client.Get(ctx, client.ObjectKey{Name: string(gw.Spec.GatewayClassName), Namespace: gw.Namespace}, gwClass)
135+
if err != nil {
136+
t.log.Infof(ctx, "u-kai: Failed to get gateway class %s-%s: %v", gw.Spec.GatewayClassName, gw.Namespace, err)
137+
continue
138+
}
139+
if gwClass.Spec.ControllerName != config.LatticeGatewayControllerName {
140+
t.log.Infof(ctx, "u-kai: Skip gateway %s-%s with controller %s", parentRef.Name, *parentRef.Namespace, gwClass.Spec.ControllerName)
141+
continue
142+
}
127143
spec.ServiceNetworkNames = append(spec.ServiceNetworkNames, string(parentRef.Name))
128144
}
129145
if config.ServiceNetworkOverrideMode {

pkg/gateway/model_build_listener.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (t *latticeServiceModelBuildTask) buildListeners(ctx context.Context, stack
8686
}
8787

8888
for _, parentRef := range t.route.Spec().ParentRefs() {
89+
// TODO: fix u-kai
8990
if parentRef.Name != t.route.Spec().ParentRefs()[0].Name {
9091
// when a service is associate to multiple service network(s), all listener config MUST be same
9192
// so here we are only using the 1st gateway

0 commit comments

Comments
 (0)