Skip to content

Commit 2e8fe19

Browse files
committed
watch multiple group versions
Signed-off-by: zirain <zirain2009@gmail.com>
1 parent 6a99849 commit 2e8fe19

32 files changed

+130
-114
lines changed

internal/cmd/egctl/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ func runStatus(ctx context.Context, logOut io.Writer, cli client.Client, inputRe
198198
resourceKind = resource.KindUDPRoute
199199

200200
case "tlsroute":
201-
tlsroute := gwapiv1a3.TLSRouteList{}
201+
tlsroute := gwapiv1a2.TLSRouteList{}
202202
if err := cli.List(ctx, &tlsroute, client.InNamespace(namespace)); err != nil {
203203
return err
204204
}
205205
resourcesList = &tlsroute
206206
resourceKind = resource.KindTLSRoute
207207

208208
case "btlspolicy", "backendtlspolicy":
209-
btlspolicy := gwapiv1.BackendTLSPolicyList{}
209+
btlspolicy := gwapiv1a3.BackendTLSPolicyList{}
210210
if err := cli.List(ctx, &btlspolicy, client.InNamespace(namespace)); err != nil {
211211
return err
212212
}

internal/cmd/egctl/status_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
"sigs.k8s.io/controller-runtime/pkg/client"
1616
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
17+
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
1718

1819
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
1920
"github.com/envoyproxy/gateway/internal/gatewayapi"
@@ -479,8 +480,8 @@ http2 gateway/test-2 foobar4 test-status-4 test reason 4
479480
},
480481
{
481482
name: "egctl x status btlspolicy",
482-
resourceList: &gwapiv1.BackendTLSPolicyList{
483-
Items: []gwapiv1.BackendTLSPolicy{
483+
resourceList: &gwapiv1a3.BackendTLSPolicyList{
484+
Items: []gwapiv1a3.BackendTLSPolicy{
484485
{
485486
ObjectMeta: metav1.ObjectMeta{
486487
Name: "btls",

internal/cmd/egctl/testdata/translate/in/default-resources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spec:
7575
port: 3000
7676
weight: 1
7777
---
78-
apiVersion: gateway.networking.k8s.io/v1alpha3
78+
apiVersion: gateway.networking.k8s.io/v1alpha2
7979
kind: TLSRoute
8080
metadata:
8181
name: backend

internal/cmd/egctl/testdata/translate/in/from-gateway-api-to-xds.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ spec:
106106
port: 3000
107107
weight: 1
108108
---
109-
apiVersion: gateway.networking.k8s.io/v1alpha3
109+
apiVersion: gateway.networking.k8s.io/v1alpha2
110110
kind: TLSRoute
111111
metadata:
112112
name: backend

internal/cmd/egctl/testdata/translate/in/invalid-envoyproxy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ spec:
131131
port: 3000
132132
weight: 1
133133
---
134-
apiVersion: gateway.networking.k8s.io/v1alpha3
134+
apiVersion: gateway.networking.k8s.io/v1alpha2
135135
kind: TLSRoute
136136
metadata:
137137
name: backend

internal/cmd/egctl/testdata/translate/in/valid-envoyproxy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ spec:
124124
port: 3000
125125
weight: 1
126126
---
127-
apiVersion: gateway.networking.k8s.io/v1alpha3
127+
apiVersion: gateway.networking.k8s.io/v1alpha2
128128
kind: TLSRoute
129129
metadata:
130130
name: backend

internal/cmd/egctl/testdata/translate/out/default-resources.all.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ tcpRoutes:
461461
name: eg
462462
sectionName: tcp
463463
tlsRoutes:
464-
- apiVersion: gateway.networking.k8s.io/v1alpha3
464+
- apiVersion: gateway.networking.k8s.io/v1alpha2
465465
kind: TLSRoute
466466
metadata:
467467
name: backend

internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ tcpRoutes:
317317
name: eg
318318
sectionName: tcp
319319
tlsRoutes:
320-
- apiVersion: gateway.networking.k8s.io/v1alpha3
320+
- apiVersion: gateway.networking.k8s.io/v1alpha2
321321
kind: TLSRoute
322322
metadata:
323323
name: backend

internal/gatewayapi/backend.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313

1414
"k8s.io/apimachinery/pkg/util/validation"
1515
"k8s.io/utils/ptr"
16-
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
16+
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
1717

1818
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
1919
"github.com/envoyproxy/gateway/internal/gatewayapi/status"
2020
"github.com/envoyproxy/gateway/internal/utils/net"
2121
)
2222

23-
func (t *Translator) ProcessBackends(backends []*egv1a1.Backend, backendTLSPolicies []*gwapiv1.BackendTLSPolicy) []*egv1a1.Backend {
23+
func (t *Translator) ProcessBackends(backends []*egv1a1.Backend, backendTLSPolicies []*gwapiv1a3.BackendTLSPolicy) []*egv1a1.Backend {
2424
res := make([]*egv1a1.Backend, 0, len(backends))
2525
for _, backend := range backends {
2626
// Ensure Backends are enabled
@@ -41,7 +41,7 @@ func (t *Translator) ProcessBackends(backends []*egv1a1.Backend, backendTLSPolic
4141
return res
4242
}
4343

44-
func validateBackend(backend *egv1a1.Backend, backendTLSPolicies []*gwapiv1.BackendTLSPolicy, runningOnHost bool) status.Error {
44+
func validateBackend(backend *egv1a1.Backend, backendTLSPolicies []*gwapiv1a3.BackendTLSPolicy, runningOnHost bool) status.Error {
4545
if backend.Spec.Type != nil && *backend.Spec.Type == egv1a1.BackendTypeDynamicResolver {
4646
if len(backend.Spec.Endpoints) > 0 {
4747
return status.NewRouteStatusError(
@@ -87,7 +87,7 @@ func validateBackend(backend *egv1a1.Backend, backendTLSPolicies []*gwapiv1.Back
8787
}
8888

8989
// validateBackendTLSSettings validates CACert is specified if InsecureSkipVerify is false
90-
func validateBackendTLSSettings(backend *egv1a1.Backend, backendTLSPolicies []*gwapiv1.BackendTLSPolicy) status.Error {
90+
func validateBackendTLSSettings(backend *egv1a1.Backend, backendTLSPolicies []*gwapiv1a3.BackendTLSPolicy) status.Error {
9191
if backend.Spec.TLS == nil {
9292
return nil
9393
}

internal/gatewayapi/backendtlspolicy.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/types"
1515
"k8s.io/utils/ptr"
1616
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
17+
gwapiv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
1718

1819
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
1920
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
@@ -26,10 +27,10 @@ var ErrBackendTLSPolicyInvalidKind = fmt.Errorf("no CA bundle found in reference
2627

2728
// ProcessBackendTLSPolicyStatus is called to post-process Backend TLS Policy status
2829
// after they were applied in all relevant translations.
29-
func (t *Translator) ProcessBackendTLSPolicyStatus(btlsp []*gwapiv1.BackendTLSPolicy) {
30-
targetRefs := map[string]*gwapiv1.BackendTLSPolicy{}
30+
func (t *Translator) ProcessBackendTLSPolicyStatus(btlsp []*gwapiv1a3.BackendTLSPolicy) {
31+
targetRefs := map[string]*gwapiv1a3.BackendTLSPolicy{}
3132
for _, policy := range btlsp {
32-
conflicted, conflictPolicy := false, &gwapiv1.BackendTLSPolicy{}
33+
conflicted, conflictPolicy := false, &gwapiv1a3.BackendTLSPolicy{}
3334
for _, ref := range policy.Spec.TargetRefs {
3435
key := localPolicyTargetReferenceWithSectionNameToKey(policy.Namespace, ref)
3536
p, exists := targetRefs[key]
@@ -387,7 +388,7 @@ func (t *Translator) processClientTLSSettings(resources *resource.Resources, cli
387388
return tlsConfig, nil
388389
}
389390

390-
func backendTLSTargetMatched(policy *gwapiv1.BackendTLSPolicy, target gwapiv1.LocalPolicyTargetReferenceWithSectionName, backendNamespace string) bool {
391+
func backendTLSTargetMatched(policy *gwapiv1a3.BackendTLSPolicy, target gwapiv1.LocalPolicyTargetReferenceWithSectionName, backendNamespace string) bool {
391392
for _, currTarget := range policy.Spec.TargetRefs {
392393
if target.Group == currTarget.Group &&
393394
target.Kind == currTarget.Kind &&
@@ -405,11 +406,11 @@ func backendTLSTargetMatched(policy *gwapiv1.BackendTLSPolicy, target gwapiv1.Lo
405406
}
406407

407408
func getBackendTLSPolicy(
408-
policies []*gwapiv1.BackendTLSPolicy,
409+
policies []*gwapiv1a3.BackendTLSPolicy,
409410
backendRef gwapiv1.BackendObjectReference,
410411
backendNamespace string,
411412
resources *resource.Resources,
412-
) *gwapiv1.BackendTLSPolicy {
413+
) *gwapiv1a3.BackendTLSPolicy {
413414
// SectionName is port number for EG Backend object
414415
target := getTargetBackendReference(backendRef, backendNamespace, resources)
415416
for _, policy := range policies {
@@ -420,7 +421,7 @@ func getBackendTLSPolicy(
420421
return nil
421422
}
422423

423-
func getBackendTLSBundle(backendTLSPolicy *gwapiv1.BackendTLSPolicy, resources *resource.Resources) (*ir.TLSUpstreamConfig, error) {
424+
func getBackendTLSBundle(backendTLSPolicy *gwapiv1a3.BackendTLSPolicy, resources *resource.Resources) (*ir.TLSUpstreamConfig, error) {
424425
// Translate SubjectAltNames from gwapiv1a3 to ir
425426
subjectAltNames := make([]ir.SubjectAltName, 0, len(backendTLSPolicy.Spec.Validation.SubjectAltNames))
426427
for _, san := range backendTLSPolicy.Spec.Validation.SubjectAltNames {
@@ -512,7 +513,7 @@ func getCaCertsFromCARefs(namespace string, caCertificates []gwapiv1.LocalObject
512513
return []byte(ca), nil
513514
}
514515

515-
func getAncestorRefs(policy *gwapiv1.BackendTLSPolicy) []*gwapiv1.ParentReference {
516+
func getAncestorRefs(policy *gwapiv1a3.BackendTLSPolicy) []*gwapiv1.ParentReference {
516517
ret := make([]*gwapiv1.ParentReference, len(policy.Status.Ancestors))
517518
for i, ancestor := range policy.Status.Ancestors {
518519
ret[i] = &ancestor.AncestorRef

0 commit comments

Comments
 (0)