Skip to content

Commit

Permalink
Create Ingress2gateway version annotation and attach it to Gateway (#187
Browse files Browse the repository at this point in the history
)

resources.

* Ingress2gateway annotation will track the current version of the
  ingress2gateway tool. The version is currently a string that needs to
  be updated manually before release.
* This annotation will be attached to the resulting Gateway resources
  during print since this is an output-only translation, and we can
  avoid interfering with existing Gateway translation tests.
  • Loading branch information
sawsa307 authored Sep 4, 2024
1 parent c626d14 commit 7556614
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ a PR. This must go through the regular PR review process and get merged into the
`main` branch. Approval of the PR indicates community consensus for a new
release.

### Update ingress2gateway version in annotation
1. Once the new release version is determined, update `CurrentVersion` in [pkg/i2gw/ingress2gateway.go](pkg/i2gw/ingress2gateway.go) so the translated Gateways will reflect the correct ingress2gateway tool version that generated them.

### Patch a release

1. Create a new branch in your fork named something like `<githubuser>/release-x.x.x`. Use the new branch
Expand Down
24 changes: 24 additions & 0 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.Gateways)
for _, gateway := range r.Gateways {
gateway := gateway
if gateway.Annotations == nil {
gateway.Annotations = make(map[string]string)
}
gateway.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&gateway, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s Gateway: %v\n", gateway.Name, err)
Expand All @@ -128,6 +132,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.HTTPRoutes)
for _, httpRoute := range r.HTTPRoutes {
httpRoute := httpRoute
if httpRoute.Annotations == nil {
httpRoute.Annotations = make(map[string]string)
}
httpRoute.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&httpRoute, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s HTTPRoute: %v\n", httpRoute.Name, err)
Expand All @@ -139,6 +147,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.TLSRoutes)
for _, tlsRoute := range r.TLSRoutes {
tlsRoute := tlsRoute
if tlsRoute.Annotations == nil {
tlsRoute.Annotations = make(map[string]string)
}
tlsRoute.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&tlsRoute, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s TLSRoute: %v\n", tlsRoute.Name, err)
Expand All @@ -150,6 +162,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.TCPRoutes)
for _, tcpRoute := range r.TCPRoutes {
tcpRoute := tcpRoute
if tcpRoute.Annotations == nil {
tcpRoute.Annotations = make(map[string]string)
}
tcpRoute.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&tcpRoute, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s TCPRoute: %v\n", tcpRoute.Name, err)
Expand All @@ -161,6 +177,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.UDPRoutes)
for _, udpRoute := range r.UDPRoutes {
udpRoute := udpRoute
if udpRoute.Annotations == nil {
udpRoute.Annotations = make(map[string]string)
}
udpRoute.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&udpRoute, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s UDPRoute: %v\n", udpRoute.Name, err)
Expand All @@ -172,6 +192,10 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
resourceCount += len(r.ReferenceGrants)
for _, referenceGrant := range r.ReferenceGrants {
referenceGrant := referenceGrant
if referenceGrant.Annotations == nil {
referenceGrant.Annotations = make(map[string]string)
}
referenceGrant.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.CurrentVersion)
err := pr.resourcePrinter.PrintObj(&referenceGrant, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s ReferenceGrant: %v\n", referenceGrant.Name, err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/i2gw/ingress2gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

const GeneratorAnnotationKey = "gateway.networking.k8s.io/generator"

var CurrentVersion = "0.3.0"

func ToGatewayAPIResources(ctx context.Context, namespace string, inputFile string, providers []string, providerSpecificFlags map[string]map[string]string) ([]GatewayResources, map[string]string, error) {
var clusterClient client.Client

Expand Down

0 comments on commit 7556614

Please sign in to comment.