Skip to content

Commit

Permalink
Adds Initial Support for Infra IR Metadata
Browse files Browse the repository at this point in the history
Signed-off-by: danehans <daneyonhansen@gmail.com>
  • Loading branch information
danehans committed Sep 7, 2022
1 parent b0920a6 commit 4ce5d79
Show file tree
Hide file tree
Showing 33 changed files with 189 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ xdsIR:
port: 80
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ httpRoutes:
xdsIR: {}
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ xdsIR:
weight: 3
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ xdsIR:
destinations:
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ xdsIR:
- "*.envoyproxy.io"
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ xdsIR:
weight: 1
infraIR:
proxy:
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway-class
image: envoyproxy/envoy:v1.23-latest
listeners:
Expand Down
24 changes: 24 additions & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const (
KindHTTPRoute = "HTTPRoute"
KindService = "Service"
KindSecret = "Secret"

// OwningGatewayNameLabel is the owner reference label used for managed infra.
// The value should be the name of the Gateway used to CRUD the Service.
OwningGatewayNameLabel = "gateway.envoyproxy.io/owning-gateway-name"
// OwningGatewayNamespaceLabel is the owner reference label used for managed infra.
// The value should be the namespace of the Gateway used to CRUD the Service.
OwningGatewayNamespaceLabel = "gateway.envoyproxy.io/owning-gateway-namespace"
)

// Resources holds the Gateway API and related
Expand Down Expand Up @@ -98,6 +105,15 @@ func (t *Translator) Translate(resources *Resources) *TranslateResult {
infraIR := ir.NewInfra()
infraIR.Proxy.Name = string(t.GatewayClassName)

// Apply Infra IR metadata.
if resources != nil {
for i := range resources.Gateways {
if resources.Gateways[i] != nil {
infraIR.Proxy.Metadata.Labels = GatewayOwnerLabels(resources.Gateways[i])
}
}
}

// Get Gateways belonging to our GatewayClass.
gateways := t.GetRelevantGateways(resources.Gateways)

Expand Down Expand Up @@ -966,3 +982,11 @@ func irTLSConfig(tlsSecret *v1.Secret) *ir.TLSListenerConfig {
PrivateKey: tlsSecret.Data[v1.TLSPrivateKeyKey],
}
}

// GatewayOwnerLabels returns owner labels for the provided Gateway.
func GatewayOwnerLabels(gw *v1beta1.Gateway) map[string]string {
return map[string]string{
OwningGatewayNameLabel: gw.Name,
OwningGatewayNamespaceLabel: gw.Namespace,
}
}
Loading

0 comments on commit 4ce5d79

Please sign in to comment.