Skip to content

Commit 4e9fbde

Browse files
committed
update based on reviews
1 parent 2a8b719 commit 4e9fbde

File tree

4 files changed

+150
-224
lines changed

4 files changed

+150
-224
lines changed

internal/mode/static/nginx/config/servers_test.go

+19-33
Original file line numberDiff line numberDiff line change
@@ -589,20 +589,6 @@ func TestExecuteForDefaultServers(t *testing.T) {
589589
}
590590
}
591591

592-
func getHeaderMatchType(matchType string) dataplane.MatchType {
593-
if len(matchType) == 0 {
594-
return dataplane.MatchTypeExact
595-
}
596-
return dataplane.MatchType(matchType)
597-
}
598-
599-
func getQueryParamMatchType(matchType string) dataplane.MatchType {
600-
if len(matchType) == 0 {
601-
return dataplane.MatchTypeExact
602-
}
603-
return dataplane.MatchType(matchType)
604-
}
605-
606592
func TestCreateServers(t *testing.T) {
607593
t.Parallel()
608594
const (
@@ -724,30 +710,30 @@ func TestCreateServers(t *testing.T) {
724710
{
725711
Name: "Version",
726712
Value: "V1",
727-
Type: getHeaderMatchType(""),
713+
Type: dataplane.MatchTypeExact,
728714
},
729715
{
730716
Name: "test",
731717
Value: "foo",
732-
Type: getHeaderMatchType(""),
718+
Type: dataplane.MatchTypeExact,
733719
},
734720
{
735721
Name: "my-header",
736722
Value: "my-value",
737-
Type: getHeaderMatchType(""),
723+
Type: dataplane.MatchTypeExact,
738724
},
739725
},
740726
QueryParams: []dataplane.HTTPQueryParamMatch{
741727
{
742728
// query names and values should not be normalized to lowercase
743729
Name: "GrEat",
744730
Value: "EXAMPLE",
745-
Type: getQueryParamMatchType(""),
731+
Type: dataplane.MatchTypeExact,
746732
},
747733
{
748734
Name: "test",
749735
Value: "foo=bar",
750-
Type: getQueryParamMatchType(""),
736+
Type: dataplane.MatchTypeExact,
751737
},
752738
},
753739
},
@@ -816,7 +802,7 @@ func TestCreateServers(t *testing.T) {
816802
{
817803
Name: "redirect",
818804
Value: "this",
819-
Type: getHeaderMatchType(""),
805+
Type: dataplane.MatchTypeExact,
820806
},
821807
},
822808
},
@@ -859,7 +845,7 @@ func TestCreateServers(t *testing.T) {
859845
{
860846
Name: "rewrite",
861847
Value: "this",
862-
Type: getHeaderMatchType(""),
848+
Type: dataplane.MatchTypeExact,
863849
},
864850
},
865851
},
@@ -899,7 +885,7 @@ func TestCreateServers(t *testing.T) {
899885
{
900886
Name: "filter",
901887
Value: "this",
902-
Type: getHeaderMatchType(""),
888+
Type: dataplane.MatchTypeExact,
903889
},
904890
},
905891
},
@@ -2724,17 +2710,17 @@ func TestCreateRouteMatch(t *testing.T) {
27242710
{
27252711
Name: "header-1",
27262712
Value: "val-1",
2727-
Type: getHeaderMatchType(""),
2713+
Type: dataplane.MatchTypeExact,
27282714
},
27292715
{
27302716
Name: "header-2",
27312717
Value: "val-2",
2732-
Type: getHeaderMatchType(""),
2718+
Type: dataplane.MatchTypeExact,
27332719
},
27342720
{
27352721
Name: "header-3",
27362722
Value: "val-3",
2737-
Type: getHeaderMatchType(""),
2723+
Type: dataplane.MatchTypeExact,
27382724
},
27392725
}
27402726

@@ -2750,17 +2736,17 @@ func TestCreateRouteMatch(t *testing.T) {
27502736
{
27512737
Name: "arg1",
27522738
Value: "val1",
2753-
Type: getQueryParamMatchType(""),
2739+
Type: dataplane.MatchTypeExact,
27542740
},
27552741
{
27562742
Name: "arg2",
27572743
Value: "val2=another-val",
2758-
Type: getQueryParamMatchType(""),
2744+
Type: dataplane.MatchTypeExact,
27592745
},
27602746
{
27612747
Name: "arg3",
27622748
Value: "==val3",
2763-
Type: getQueryParamMatchType(""),
2749+
Type: dataplane.MatchTypeExact,
27642750
},
27652751
}
27662752

@@ -2895,7 +2881,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
28952881
input: dataplane.HTTPQueryParamMatch{
28962882
Name: "key",
28972883
Value: "value",
2898-
Type: getQueryParamMatchType(string(dataplane.MatchTypeExact)),
2884+
Type: dataplane.MatchTypeExact,
28992885
},
29002886
expected: "key=Exact=value",
29012887
},
@@ -2904,7 +2890,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
29042890
input: dataplane.HTTPQueryParamMatch{
29052891
Name: "KeY",
29062892
Value: "vaLUe-[a-z]==",
2907-
Type: getQueryParamMatchType(string(dataplane.MatchTypeRegularExpression)),
2893+
Type: dataplane.MatchTypeRegularExpression,
29082894
},
29092895
expected: "KeY=RegularExpression=vaLUe-[a-z]==",
29102896
},
@@ -2913,7 +2899,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
29132899
input: dataplane.HTTPQueryParamMatch{
29142900
Name: "keY",
29152901
Value: "vaLUe==",
2916-
Type: getQueryParamMatchType(""),
2902+
Type: dataplane.MatchTypeExact,
29172903
},
29182904
expected: "keY=Exact=vaLUe==",
29192905
},
@@ -2939,7 +2925,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
29392925
dataplane.HTTPHeaderMatch{
29402926
Name: "kEy",
29412927
Value: "vALUe",
2942-
Type: getHeaderMatchType(string(dataplane.MatchTypeExact)),
2928+
Type: dataplane.MatchTypeExact,
29432929
},
29442930
)
29452931

@@ -2951,7 +2937,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
29512937
dataplane.HTTPHeaderMatch{
29522938
Name: "kEy",
29532939
Value: "vALUe-[0-9]",
2954-
Type: getHeaderMatchType(string(dataplane.MatchTypeRegularExpression)),
2940+
Type: dataplane.MatchTypeRegularExpression,
29552941
},
29562942
)
29572943

internal/mode/static/state/graph/grpcroute.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package graph
22

33
import (
4-
"fmt"
5-
64
"k8s.io/apimachinery/pkg/types"
75
"k8s.io/apimachinery/pkg/util/validation/field"
86
v1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -225,13 +223,16 @@ func ConvertGRPCMatches(grpcMatches []v1.GRPCRouteMatch) []v1.HTTPRouteMatch {
225223
}
226224

227225
func convertGRPCHeaderMatchType(matchType *v1.GRPCHeaderMatchType) *v1.HeaderMatchType {
226+
if matchType == nil {
227+
return nil
228+
}
228229
switch *matchType {
229230
case v1.GRPCHeaderMatchExact:
230231
return helpers.GetPointer(v1.HeaderMatchExact)
231232
case v1.GRPCHeaderMatchRegularExpression:
232233
return helpers.GetPointer(v1.HeaderMatchRegularExpression)
233234
default:
234-
panic(fmt.Sprintf("unsupported header match type: %v", matchType))
235+
return nil
235236
}
236237
}
237238

0 commit comments

Comments
 (0)