Skip to content

Commit 7fb3254

Browse files
authored
chore: remove unused classRefsEnvoyProxy function and improve the error message (#7622)
* chore: remove useless function and improve the error message Signed-off-by: zirain <[email protected]> * fix Signed-off-by: zirain <[email protected]> --------- Signed-off-by: zirain <[email protected]>
1 parent 50dcb15 commit 7fb3254

File tree

3 files changed

+1
-162
lines changed

3 files changed

+1
-162
lines changed

internal/provider/kubernetes/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ func (r *gatewayAPIReconciler) processGatewayParamsRef(ctx context.Context, gtw
24862486
// processGatewayClassParamsRef processes the parametersRef of the provided GatewayClass.
24872487
func (r *gatewayAPIReconciler) processGatewayClassParamsRef(ctx context.Context, gc *gwapiv1.GatewayClass, resourceMap *resourceMappings, resourceTree *resource.Resources) error {
24882488
if !refsEnvoyProxy(gc) {
2489-
return fmt.Errorf("unsupported parametersRef for gatewayclass %s", gc.Name)
2489+
return fmt.Errorf("unsupported parametersRef(invalid group or kind) for gatewayclass %s", gc.Name)
24902490
}
24912491

24922492
ep := new(egv1a1.EnvoyProxy)

internal/provider/kubernetes/helpers.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
"k8s.io/apimachinery/pkg/types"
15-
"k8s.io/utils/ptr"
1615
"sigs.k8s.io/controller-runtime/pkg/client"
1716
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1817
mcsapiv1a1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
@@ -136,18 +135,6 @@ func validateBackendRef(ref *gwapiv1.BackendRef) error {
136135
return nil
137136
}
138137

139-
// classRefsEnvoyProxy returns true if the provided GatewayClass references the provided EnvoyProxy.
140-
func classRefsEnvoyProxy(gc *gwapiv1.GatewayClass, ep *egv1a1.EnvoyProxy) bool {
141-
if gc == nil || ep == nil {
142-
return false
143-
}
144-
145-
ns := ptr.Deref(gc.Spec.ParametersRef.Namespace, "default")
146-
return refsEnvoyProxy(gc) &&
147-
string(ns) == ep.Namespace &&
148-
gc.Spec.ParametersRef.Name == ep.Name
149-
}
150-
151138
// refsEnvoyProxy returns true if the provided GatewayClass references an EnvoyProxy.
152139
func refsEnvoyProxy(gc *gwapiv1.GatewayClass) bool {
153140
if gc == nil {

internal/provider/kubernetes/helpers_test.go

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -368,154 +368,6 @@ func TestRefsEnvoyProxy(t *testing.T) {
368368
}
369369
}
370370

371-
func TestClassRefsEnvoyProxy(t *testing.T) {
372-
gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName)
373-
374-
testCases := []struct {
375-
name string
376-
gc *gwapiv1.GatewayClass
377-
ep *egv1a1.EnvoyProxy
378-
expected bool
379-
}{
380-
{
381-
name: "nil gatewayclass and envoyproxy",
382-
gc: nil,
383-
ep: nil,
384-
expected: false,
385-
},
386-
{
387-
name: "gatewayclass references envoyproxy",
388-
gc: &gwapiv1.GatewayClass{
389-
ObjectMeta: metav1.ObjectMeta{
390-
Name: "test-gc",
391-
},
392-
Spec: gwapiv1.GatewayClassSpec{
393-
ControllerName: gcCtrlName,
394-
ParametersRef: &gwapiv1.ParametersReference{
395-
Group: gwapiv1.Group(egv1a1.GroupVersion.Group),
396-
Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy),
397-
Name: "test-ep",
398-
Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace),
399-
},
400-
},
401-
},
402-
ep: &egv1a1.EnvoyProxy{
403-
ObjectMeta: metav1.ObjectMeta{
404-
Namespace: config.DefaultNamespace,
405-
Name: "test-ep",
406-
},
407-
},
408-
expected: true,
409-
},
410-
{
411-
name: "gatewayclass does not reference envoyproxy",
412-
gc: &gwapiv1.GatewayClass{
413-
ObjectMeta: metav1.ObjectMeta{
414-
Name: "test-gc",
415-
},
416-
Spec: gwapiv1.GatewayClassSpec{
417-
ControllerName: gcCtrlName,
418-
ParametersRef: &gwapiv1.ParametersReference{
419-
Group: gwapiv1.Group(egv1a1.GroupVersion.Group),
420-
Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy),
421-
Name: "not-test-ep",
422-
Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace),
423-
},
424-
},
425-
},
426-
ep: &egv1a1.EnvoyProxy{
427-
ObjectMeta: metav1.ObjectMeta{
428-
Namespace: config.DefaultNamespace,
429-
Name: "test-ep",
430-
},
431-
},
432-
expected: false,
433-
},
434-
{
435-
name: "gatewayclass references invalid kind",
436-
gc: &gwapiv1.GatewayClass{
437-
ObjectMeta: metav1.ObjectMeta{
438-
Name: "test-gc",
439-
},
440-
Spec: gwapiv1.GatewayClassSpec{
441-
ControllerName: gcCtrlName,
442-
ParametersRef: &gwapiv1.ParametersReference{
443-
Group: gwapiv1.Group(egv1a1.GroupVersion.Group),
444-
Kind: gwapiv1.Kind("UnsupportedKind"),
445-
Name: "test-ep",
446-
Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace),
447-
},
448-
},
449-
},
450-
ep: &egv1a1.EnvoyProxy{
451-
ObjectMeta: metav1.ObjectMeta{
452-
Namespace: config.DefaultNamespace,
453-
Name: "test-ep",
454-
},
455-
},
456-
expected: false,
457-
},
458-
{
459-
name: "gatewayclass references invalid group",
460-
gc: &gwapiv1.GatewayClass{
461-
ObjectMeta: metav1.ObjectMeta{
462-
Name: "test-gc",
463-
},
464-
Spec: gwapiv1.GatewayClassSpec{
465-
ControllerName: gcCtrlName,
466-
ParametersRef: &gwapiv1.ParametersReference{
467-
Group: gwapiv1.Group("UnsupportedGroup"),
468-
Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy),
469-
Name: "test-ep",
470-
Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace),
471-
},
472-
},
473-
},
474-
ep: &egv1a1.EnvoyProxy{
475-
ObjectMeta: metav1.ObjectMeta{
476-
Namespace: config.DefaultNamespace,
477-
Name: "test-ep",
478-
},
479-
},
480-
expected: false,
481-
},
482-
{
483-
name: "gatewayclass references envoyproxy without namespace",
484-
gc: &gwapiv1.GatewayClass{
485-
ObjectMeta: metav1.ObjectMeta{
486-
Name: "test-gc",
487-
},
488-
Spec: gwapiv1.GatewayClassSpec{
489-
ControllerName: gcCtrlName,
490-
ParametersRef: &gwapiv1.ParametersReference{
491-
Group: gwapiv1.Group(egv1a1.GroupVersion.Group),
492-
Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy),
493-
Name: "test-ep",
494-
},
495-
},
496-
},
497-
ep: &egv1a1.EnvoyProxy{
498-
ObjectMeta: metav1.ObjectMeta{
499-
Namespace: config.DefaultNamespace,
500-
Name: "test-ep",
501-
},
502-
},
503-
expected: false,
504-
},
505-
}
506-
507-
for i := range testCases {
508-
tc := testCases[i]
509-
510-
// Run the test cases.
511-
t.Run(tc.name, func(t *testing.T) {
512-
// Process the test case objects.
513-
res := classRefsEnvoyProxy(tc.gc, tc.ep)
514-
require.Equal(t, tc.expected, res)
515-
})
516-
}
517-
}
518-
519371
func TestClassAccepted(t *testing.T) {
520372
gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName)
521373

0 commit comments

Comments
 (0)