Skip to content

Commit 21643fd

Browse files
author
Doyoon Kim
authored
Fix DNSEndpoint owner reference for GRPCRoute (#372)
1 parent dbde6d1 commit 21643fd

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

pkg/deploy/externaldns/dnsendpoint_manager.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"reflect"
66

7+
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
78
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
89
"github.com/golang/glog"
910
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -13,7 +14,6 @@ import (
1314
"sigs.k8s.io/controller-runtime/pkg/client"
1415
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1516
"sigs.k8s.io/external-dns/endpoint"
16-
gateway_api "sigs.k8s.io/gateway-api/apis/v1beta1"
1717
)
1818

1919
type DnsEndpointManager interface {
@@ -44,12 +44,20 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
4444
return nil
4545
}
4646

47-
httproute := &gateway_api.HTTPRoute{}
47+
var (
48+
route core.Route
49+
err error
50+
)
4851
routeNamespacedName := types.NamespacedName{
4952
Namespace: service.Spec.Namespace,
5053
Name: service.Spec.Name,
5154
}
52-
if err := s.k8sClient.Get(ctx, routeNamespacedName, httproute); err != nil {
55+
if service.Spec.RouteType == core.GrpcRouteType {
56+
route, err = core.GetGRPCRoute(ctx, s.k8sClient, routeNamespacedName)
57+
} else {
58+
route, err = core.GetHTTPRoute(ctx, s.k8sClient, routeNamespacedName)
59+
}
60+
if err != nil {
5361
glog.V(2).Infof("Skipping creation of %s: Could not find corresponding route", namespacedName.String())
5462
return nil
5563
}
@@ -77,7 +85,7 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice
7785
},
7886
},
7987
}
80-
controllerutil.SetControllerReference(httproute, ep, s.k8sClient.Scheme())
88+
controllerutil.SetControllerReference(route.K8sObject(), ep, s.k8sClient.Scheme())
8189
if err = s.k8sClient.Create(ctx, ep); err != nil {
8290
glog.V(2).Infof("Failed creating DNSEndpoint: %s", err.Error())
8391
return err

pkg/gateway/model_build_lattice_service.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ func (t *latticeServiceModelBuildTask) buildModel(ctx context.Context) error {
115115
}
116116

117117
func (t *latticeServiceModelBuildTask) buildLatticeService(ctx context.Context) error {
118-
pro := "HTTP"
119-
protocols := []*string{&pro}
118+
routeType := core.HttpRouteType
119+
if _, ok := t.route.(*core.GRPCRoute); ok {
120+
routeType = core.GrpcRouteType
121+
}
122+
120123
spec := latticemodel.ServiceSpec{
121124
Name: t.route.Name(),
122125
Namespace: t.route.Namespace(),
123-
Protocols: protocols,
126+
RouteType: routeType,
124127
//ServiceNetworkNames: string(t.route.Spec().ParentRefs()[0].Name),
125128
}
126129

pkg/gateway/model_build_lattice_service_test.go

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

2222
"github.com/aws/aws-application-networking-k8s/pkg/k8s"
2323
latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice"
24+
gateway_api_v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
2425
)
2526

2627
func Test_LatticeServiceModelBuild(t *testing.T) {
@@ -55,6 +56,7 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
5556
wantError error
5657
wantErrIsNil bool
5758
wantName string
59+
wantRouteType core.RouteType
5860
wantIsDeleted bool
5961
}{
6062
{
@@ -80,6 +82,7 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
8082

8183
wantError: nil,
8284
wantName: "service1",
85+
wantRouteType: core.HttpRouteType,
8386
wantIsDeleted: false,
8487
wantErrIsNil: true,
8588
},
@@ -102,6 +105,29 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
102105

103106
wantError: nil,
104107
wantName: "service1",
108+
wantRouteType: core.HttpRouteType,
109+
wantIsDeleted: false,
110+
wantErrIsNil: true,
111+
},
112+
{
113+
name: "Add LatticeService with GRPCRoute",
114+
route: core.NewGRPCRoute(gateway_api_v1alpha2.GRPCRoute{
115+
ObjectMeta: metav1.ObjectMeta{
116+
Name: "service1",
117+
},
118+
Spec: gateway_api_v1alpha2.GRPCRouteSpec{
119+
CommonRouteSpec: gateway_api.CommonRouteSpec{
120+
ParentRefs: []gateway_api.ParentReference{
121+
{
122+
Name: "gateway1",
123+
},
124+
},
125+
},
126+
},
127+
}),
128+
wantError: nil,
129+
wantName: "service1",
130+
wantRouteType: core.GrpcRouteType,
105131
wantIsDeleted: false,
106132
wantErrIsNil: true,
107133
},
@@ -139,6 +165,7 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
139165

140166
wantError: nil,
141167
wantName: "service2",
168+
wantRouteType: core.HttpRouteType,
142169
wantIsDeleted: true,
143170
wantErrIsNil: true,
144171
},

pkg/model/lattice/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ type Service struct {
1414
}
1515

1616
type ServiceSpec struct {
17-
Name string `json:"name"`
18-
Namespace string `json:"namespace"`
17+
Name string `json:"name"`
18+
Namespace string `json:"namespace"`
19+
RouteType core.RouteType
1920
Protocols []*string `json:"protocols"`
2021
ServiceNetworkNames []string `json:"servicenetworkhname"`
2122
CustomerDomainName string `json:"customerdomainname"`

0 commit comments

Comments
 (0)