Skip to content

Commit

Permalink
feat: enable load backend resources (envoyproxy#4535)
Browse files Browse the repository at this point in the history
enable load backend resources

Signed-off-by: shawnh2 <[email protected]>
(cherry picked from commit 9c9f435)
Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
shawnh2 authored and zhaohuabing committed Nov 6, 2024
1 parent 7bd7db5 commit a9f383d
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
46 changes: 46 additions & 0 deletions internal/cmd/egctl/testdata/translate/in/backend-endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: eg
spec:
controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: eg
spec:
gatewayClassName: eg
listeners:
- name: http
protocol: HTTP
port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: backend
spec:
parentRefs:
- name: eg
hostnames:
- "www.example.com"
rules:
- backendRefs:
- group: gateway.envoyproxy.io
kind: Backend
name: backend
matches:
- path:
type: PathPrefix
value: /
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: backend
spec:
endpoints:
- ip:
address: 0.0.0.0
port: 3000
106 changes: 106 additions & 0 deletions internal/cmd/egctl/testdata/translate/out/backend-endpoint.all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
backends:
- kind: Backend
metadata:
creationTimestamp: null
name: backend
namespace: envoy-gateway-system
spec:
endpoints:
- ip:
address: 0.0.0.0
port: 3000
status:
conditions:
- lastTransitionTime: null
message: The Backend was accepted
reason: Accepted
status: "True"
type: Accepted
gatewayClass:
kind: GatewayClass
metadata:
creationTimestamp: null
name: eg
namespace: envoy-gateway-system
spec:
controllerName: gateway.envoyproxy.io/gatewayclass-controller
status:
conditions:
- lastTransitionTime: null
message: Valid GatewayClass
reason: Accepted
status: "True"
type: Accepted
gateways:
- kind: Gateway
metadata:
creationTimestamp: null
name: eg
namespace: envoy-gateway-system
spec:
gatewayClassName: eg
listeners:
- name: http
port: 80
protocol: HTTP
status:
listeners:
- attachedRoutes: 1
conditions:
- lastTransitionTime: null
message: Sending translated listener configuration to the data plane
reason: Programmed
status: "True"
type: Programmed
- lastTransitionTime: null
message: Listener has been successfully translated
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Listener references have been resolved
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
name: http
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
- group: gateway.networking.k8s.io
kind: GRPCRoute
httpRoutes:
- kind: HTTPRoute
metadata:
creationTimestamp: null
name: backend
namespace: envoy-gateway-system
spec:
hostnames:
- www.example.com
parentRefs:
- name: eg
rules:
- backendRefs:
- group: gateway.envoyproxy.io
kind: Backend
name: backend
matches:
- path:
type: PathPrefix
value: /
status:
parents:
- conditions:
- lastTransitionTime: null
message: Route is accepted
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Resolved all the Object references for the Route
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
controllerName: gateway.envoyproxy.io/gatewayclass-controller
parentRef:
name: eg
6 changes: 6 additions & 0 deletions internal/cmd/egctl/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ func TestTranslate(t *testing.T) {
expect: true,
extraArgs: []string{"--add-missing-resources"},
},
{
name: "backend-endpoint",
from: "gateway-api",
to: "gateway-api",
expect: true,
},
}

flag.Parse()
Expand Down
14 changes: 13 additions & 1 deletion internal/gatewayapi/resource/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func LoadResourcesFromYAMLBytes(yamlBytes []byte, addMissingResources bool) (*Re

// loadKubernetesYAMLToResources converts a Kubernetes YAML string into GatewayAPI Resources.
// TODO: add support for kind:
// - Backend (gateway.envoyproxy.io/v1alpha1)
// - EnvoyExtensionPolicy (gateway.envoyproxy.io/v1alpha1)
// - HTTPRouteFilter (gateway.envoyproxy.io/v1alpha1)
// - BackendLPPolicy (gateway.networking.k8s.io/v1alpha2)
Expand Down Expand Up @@ -295,6 +294,19 @@ func loadKubernetesYAMLToResources(input []byte, addMissingResources bool) (*Res
Spec: typedSpec.(egv1a1.HTTPRouteFilterSpec),
}
resources.HTTPRouteFilters = append(resources.HTTPRouteFilters, httpRouteFilter)
case KindBackend:
typedSpec := spec.Interface()
backend := &egv1a1.Backend{
TypeMeta: metav1.TypeMeta{
Kind: KindBackend,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: typedSpec.(egv1a1.BackendSpec),
}
resources.Backends = append(resources.Backends, backend)
}

return nil
Expand Down

0 comments on commit a9f383d

Please sign in to comment.