Skip to content

Commit

Permalink
move to gwv1api
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Oct 19, 2023
1 parent 1d621ca commit f593c80
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- name: http
port: 80
Expand Down Expand Up @@ -44,6 +45,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- name: http
port: 80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ gateways:
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-2
port: 8888
protocol: HTTP
- name: http-3
hostname: example.com
port: 8888
protocol: HTTP
allowedRoutes:
namespaces:
from: All
- name: http-2
port: 8888
protocol: HTTP
- name: http-3
hostname: example.com
port: 8888
protocol: HTTP
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- allowedRoutes:
namespaces:
Expand Down Expand Up @@ -48,6 +49,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- name: http-2
port: 8888
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- allowedRoutes:
namespaces:
Expand Down Expand Up @@ -47,6 +48,7 @@ gateways:
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
infrastructure: {}
listeners:
- allowedRoutes:
namespaces:
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (t *Translator) InitIRs(gateways []*GatewayContext, resources *Resources) (
}

// XdsIR and InfraIR map keys by default are {GatewayNamespace}/{GatewayName}, but if mergeGateways is set, they are merged under {GatewayClassName} key.
func (t *Translator) getIRKey(gateway *v1beta1.Gateway) string {
func (t *Translator) getIRKey(gateway *gwapiv1.Gateway) string {
irKey := irStringKey(gateway.Namespace, gateway.Name)
if t.MergeGateways {
return string(t.GatewayClassName)
Expand Down
6 changes: 3 additions & 3 deletions internal/gatewayapi/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,16 @@ func (t *Translator) validateConflictedMergedListeners(gateways []*GatewayContex
listenerSets := sets.Set[string]{}
for _, gateway := range gateways {
for _, listener := range gateway.listeners {
hostname := new(v1beta1.Hostname)
hostname := new(gwapiv1.Hostname)
if listener.Hostname != nil {
hostname = listener.Hostname
}
portProtocolHostname := fmt.Sprintf("%s:%s:%d", listener.Protocol, *hostname, listener.Port)
if listenerSets.Has(portProtocolHostname) {
listener.SetCondition(
v1beta1.ListenerConditionConflicted,
gwapiv1.ListenerConditionConflicted,
metav1.ConditionTrue,
v1beta1.ListenerReasonHostnameConflict,
gwapiv1.ListenerReasonHostnameConflict,
"Port, protocol and hostname tuple must be unique for every listener",
)
}
Expand Down
15 changes: 8 additions & 7 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type gatewayAPIReconciler struct {
namespace string
namespaceLabels []string
envoyGateway *egv1a1.EnvoyGateway
mergeGateways bool

resources *message.ProviderResources
extGVKs []schema.GroupVersionKind
Expand Down Expand Up @@ -334,6 +335,10 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques
}
}

if resourceTree.EnvoyProxy != nil && resourceTree.EnvoyProxy.Spec.MergeGateways != nil {
r.mergeGateways = *resourceTree.EnvoyProxy.Spec.MergeGateways
}

Check warning on line 340 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L339-L340

Added lines #L339 - L340 were not covered by tests

if err := r.gatewayClassUpdater(ctx, acceptedGC, true, string(gwapiv1.GatewayClassReasonAccepted), status.MsgValidGatewayClass); err != nil {
r.log.Error(err, "unable to update GatewayClass status")
return reconcile.Result{}, err
Expand Down Expand Up @@ -407,20 +412,16 @@ func (r *gatewayAPIReconciler) statusUpdateForGateway(ctx context.Context, gtw *
if r.statusUpdater == nil {
return
}
var merged bool
res, _ := r.resources.GatewayAPIResources.Load(string(gtw.Spec.GatewayClassName))
if res.EnvoyProxy != nil && res.EnvoyProxy.Spec.MergeGateways != nil && *res.EnvoyProxy.Spec.MergeGateways {
merged = true
}

// Get deployment
deploy, err := r.envoyDeploymentForGateway(ctx, gtw, merged)
deploy, err := r.envoyDeploymentForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Deployment for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
}

// Get service
svc, err := r.envoyServiceForGateway(ctx, gtw, merged)
svc, err := r.envoyServiceForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Service for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func refsSecret(ref *gwapiv1.SecretObjectReference) bool {
// infraName returns expected name for the EnvoyProxy infra resources.
// By default it returns hashed string from {GatewayNamespace}/{GatewayName},
// but if mergeGateways is set, it will return hashed string of {GatewayClassName}.
func infraName(gateway *gwapiv1b1.Gateway, merged bool) string {
func infraName(gateway *gwapiv1.Gateway, merged bool) string {
if merged {
return proxy.ExpectedResourceHashedName(string(gateway.Spec.GatewayClassName))
}

Check warning on line 205 in internal/provider/kubernetes/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/helpers.go#L204-L205

Added lines #L204 - L205 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (r *gatewayAPIReconciler) filterHTTPRoutesByNamespaceLabels(httpRoutes []gw
}

// envoyDeploymentForGateway returns the Envoy Deployment, returning nil if the Deployment doesn't exist.
func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway) (*appsv1.Deployment, error) {
func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, gateway *gwapiv1.Gateway) (*appsv1.Deployment, error) {
key := types.NamespacedName{
Namespace: r.namespace,
Name: infraName(gateway, r.mergeGateways),
Expand All @@ -414,7 +414,7 @@ func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, ga
}

// envoyServiceForGateway returns the Envoy service, returning nil if the service doesn't exist.
func (r *gatewayAPIReconciler) envoyServiceForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway) (*corev1.Service, error) {
func (r *gatewayAPIReconciler) envoyServiceForGateway(ctx context.Context, gateway *gwapiv1.Gateway) (*corev1.Service, error) {
key := types.NamespacedName{
Namespace: r.namespace,
Name: infraName(gateway, r.mergeGateways),
Expand Down

0 comments on commit f593c80

Please sign in to comment.