Skip to content

Commit 0e7ad52

Browse files
committed
Merge branch 'main' into feature/nginxingress-implement-header-manipulation
2 parents 925d85f + f17b513 commit 0e7ad52

82 files changed

Lines changed: 1060 additions & 1155 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ issues:
4444
- gocyclo
4545
- errcheck
4646
- dupl
47+
# Allow underscores in emitter package names
48+
- path: pkg/i2gw/emitters/
49+
linters:
50+
- revive
51+
text: "var-naming: don't use an underscore in package name"
4752
exclude:
4853
- Using the variable on range scope `tc` in function literal

PROVIDER.md

Lines changed: 0 additions & 207 deletions
This file was deleted.

cmd/print.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ import (
4242

4343
// Call init for notifications
4444
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications"
45+
46+
// Call init for emitters
47+
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/emitters/gce"
48+
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/emitters/standard"
4549
)
4650

4751
type PrintRunner struct {
@@ -72,6 +76,10 @@ type PrintRunner struct {
7276

7377
// Provider specific flags --<provider>-<flag>.
7478
providerSpecificFlags map[string]*string
79+
80+
// emitter indicates which emitter is used to generate the Gateway API resources.
81+
// Defaults to "standard".
82+
emitter string
7583
}
7684

7785
// PrintGatewayAPIObjects performs necessary steps to digest and print
@@ -88,7 +96,7 @@ func (pr *PrintRunner) PrintGatewayAPIObjects(cmd *cobra.Command, _ []string) er
8896
return fmt.Errorf("failed to initialize namespace filter: %w", err)
8997
}
9098

91-
gatewayResources, notificationTablesMap, err := i2gw.ToGatewayAPIResources(cmd.Context(), pr.namespaceFilter, pr.inputFile, pr.providers, pr.getProviderSpecificFlags())
99+
gatewayResources, notificationTablesMap, err := i2gw.ToGatewayAPIResources(cmd.Context(), pr.namespaceFilter, pr.inputFile, pr.providers, pr.emitter, pr.getProviderSpecificFlags())
92100
if err != nil {
93101
return err
94102
}
@@ -314,11 +322,23 @@ func newPrintCommand() *cobra.Command {
314322
Use: "print",
315323
Short: "Prints Gateway API objects generated from ingress and provider-specific resources.",
316324
RunE: pr.PrintGatewayAPIObjects,
317-
PreRunE: func(_ *cobra.Command, _ []string) error {
325+
PreRunE: func(cmd *cobra.Command, _ []string) error {
318326
openAPIExist := slices.Contains(pr.providers, "openapi3")
319327
if openAPIExist && len(pr.providers) != 1 {
320328
return fmt.Errorf("openapi3 must be the only provider when specified")
321329
}
330+
331+
// Auto-set emitter for GCE provider
332+
gceProviderUsed := slices.Contains(pr.providers, "gce")
333+
emitterFlagChanged := cmd.Flags().Changed("emitter")
334+
335+
if gceProviderUsed {
336+
if emitterFlagChanged && pr.emitter != "gce" {
337+
return fmt.Errorf("when using the gce provider, the emitter must be 'gce' (got '%s')", pr.emitter)
338+
}
339+
pr.emitter = "gce"
340+
}
341+
322342
return nil
323343
},
324344
}
@@ -336,6 +356,9 @@ func newPrintCommand() *cobra.Command {
336356
`If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even
337357
if specified with --namespace.`)
338358

359+
cmd.Flags().StringVar(&pr.emitter, "emitter", "standard",
360+
fmt.Sprintf("If present, the tool will try to use the specified emitter to generate the Gateway API resources, supported values are %v. The `standard` emitter will only output Gateway API", i2gw.GetSupportedEmitters()))
361+
339362
cmd.Flags().StringSliceVar(&pr.providers, "providers", []string{},
340363
fmt.Sprintf("If present, the tool will try to convert only resources related to the specified providers, supported values are %v.", i2gw.GetSupportedProviders()))
341364

pkg/i2gw/emitter.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package i2gw
18+
19+
import (
20+
emitterir "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/emitter_intermediate"
21+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
22+
"k8s.io/apimachinery/pkg/types"
23+
"k8s.io/apimachinery/pkg/util/validation/field"
24+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
25+
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
26+
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
27+
)
28+
29+
type Emitter interface {
30+
// Emit converts stored IR with the Provider into
31+
// Gateway API resources and extensions
32+
Emit(emitterir.EmitterIR) (GatewayResources, field.ErrorList)
33+
}
34+
35+
// GatewayResources contains all Gateway-API objects and provider Gateway
36+
// extensions.
37+
type GatewayResources struct {
38+
Gateways map[types.NamespacedName]gatewayv1.Gateway
39+
GatewayClasses map[types.NamespacedName]gatewayv1.GatewayClass
40+
41+
HTTPRoutes map[types.NamespacedName]gatewayv1.HTTPRoute
42+
GRPCRoutes map[types.NamespacedName]gatewayv1.GRPCRoute
43+
TLSRoutes map[types.NamespacedName]gatewayv1alpha2.TLSRoute
44+
TCPRoutes map[types.NamespacedName]gatewayv1alpha2.TCPRoute
45+
UDPRoutes map[types.NamespacedName]gatewayv1alpha2.UDPRoute
46+
47+
BackendTLSPolicies map[types.NamespacedName]gatewayv1.BackendTLSPolicy
48+
ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant
49+
50+
GatewayExtensions []unstructured.Unstructured
51+
}
52+
53+
// EmitterConstructorByName is a map of EmitterConstructor functions by a
54+
// emitter name. Different Emitter implementations should add their construction
55+
// func at startup.
56+
var EmitterConstructorByName = map[EmitterName]EmitterConstructor{}
57+
58+
type EmitterName string
59+
60+
type EmitterConstructor func(conf *EmitterConf) Emitter
61+
62+
type EmitterConf struct {
63+
// TODO: add fields as needed.
64+
}
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package intermediate
17+
package gce
1818

19-
type GceGatewayIR struct {
19+
type GatewayIR struct {
2020
EnableHTTPSRedirect bool
2121
SslPolicy *SslPolicyConfig
2222
}
2323
type SslPolicyConfig struct {
2424
Name string
2525
}
26-
type GceHTTPRouteIR struct{}
27-
type GceServiceIR struct {
26+
type HTTPRouteIR struct{}
27+
type ServiceIR struct {
2828
SessionAffinity *SessionAffinityConfig
2929
SecurityPolicy *SecurityPolicyConfig
3030
HealthCheck *HealthCheckConfig
@@ -45,18 +45,3 @@ type HealthCheckConfig struct {
4545
Port *int64
4646
RequestPath *string
4747
}
48-
49-
func mergeGceGatewayIR(current, existing *GceGatewayIR) *GceGatewayIR {
50-
// If either GceGatewayIR is nil, return the other one as the merged result.
51-
if current == nil {
52-
return existing
53-
}
54-
if existing == nil {
55-
return current
56-
}
57-
58-
// If both GceGatewayIRs are not nil, merge their fields.
59-
var mergedGatewayIR GceGatewayIR
60-
mergedGatewayIR.EnableHTTPSRedirect = current.EnableHTTPSRedirect || existing.EnableHTTPSRedirect
61-
return &mergedGatewayIR
62-
}

0 commit comments

Comments
 (0)