Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable load backend resources #4535

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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 @@
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)

Check warning on line 309 in internal/gatewayapi/resource/load.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/resource/load.go#L297-L309

Added lines #L297 - L309 were not covered by tests
}

return nil
Expand Down
Loading