Skip to content

Add GatewayPolicy to generate-manifests and rewrite targetRef group v1beta1 to v1 - #5604

Open
binilvrgs wants to merge 14 commits into
mainfrom
feature/binilvrgs/generate_manifest_job_upgrading_gateway_policy
Open

Add GatewayPolicy to generate-manifests and rewrite targetRef group v1beta1 to v1#5604
binilvrgs wants to merge 14 commits into
mainfrom
feature/binilvrgs/generate_manifest_job_upgrading_gateway_policy

Conversation

@binilvrgs

@binilvrgs binilvrgs commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Changes proposed in this PR

  • Add GatewayPolicy to the generate-manifests pre-upgrade snapshot job which was previously missing, causing GatewayPolicy resources to be silently lost during Consul Helm upgrades
  • Add convertGatewayPolicyTargetRef() to rewrite spec.targetRef.group from gateway.networking.k8s.io/v1beta1 to gateway.networking.k8s.io/v1 in both the gatewayapi and consulapi snapshot paths, to match the graduated Gateway API version
  • Update gatewayForGatewayPolicy() index function to accept both v1 and v1beta1 group strings for backward compatibility during transition
  • Add kindGatewayPolicy constant and GatewayPolicyList case in extractItems() following existing patterns

How I've tested this PR

Tested against a live EKS cluster (v1.34.9-eks-b3f9404, us-east-1):

  • Test 1: Created a GatewayPolicy in the cluster with spec.targetRef.group: gateway.networking.k8s.io/v1beta1 to simulate pre-upgrade customer state
  • Test 2: Built the old binary (before fix), ran generate-manifests — confirmed gatewaypolicies/ folder was absent from snapshot (bug proven)
  • Test 3: Built the new binary (after fix), ran generate-manifests — confirmed gatewaypolicies/ folder present in both gatewayapi/ and consulapi/ snapshot paths
  • Test 4: Inspected generated YAML — confirmed spec.targetRef.group was correctly rewritten from v1beta1 to v1

Unit tests:
ok github.com/hashicorp/consul-k8s/control-plane/subcommand/generate-manifests 2.907s
ok github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1 1.620s

How I expect reviewers to test this PR

  1. Create a GatewayPolicy with spec.targetRef.group: gateway.networking.k8s.io/v1beta1 in a test cluster
  2. Run generate-manifests with the new binary
  3. Verify gatewaypolicies/ folder is created under the output directory
  4. Verify spec.targetRef.group in the generated YAML is gateway.networking.k8s.io/v1

Checklist

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

@binilvrgs
binilvrgs requested review from a team as code owners August 22, 2026 15:07
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown

Go Test Coverage: 61.5%

Patch coverage: 100.0% (36/36 changed lines covered)

See the workflow run for the full per-package breakdown and downloadable HTML report.

@codecov-commenter

codecov-commenter commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.67%. Comparing base (cb007b6) to head (bde7dfd).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5604      +/-   ##
==========================================
+ Coverage   58.62%   58.67%   +0.05%     
==========================================
  Files         298      298              
  Lines       36767    36796      +29     
==========================================
+ Hits        21554    21590      +36     
+ Misses      13268    13263       -5     
+ Partials     1945     1943       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@binilvrgs binilvrgs added backport/1.8.x Backport to release/1.8.x branch backport/1.9.x Backport to release/1.9.x branch backport/2.0.x Backport to release/2.0.x branch labels Aug 22, 2026
convertToConsulRoute(raw)

case kindGatewayPolicy:
convertGatewayPolicyTargetRef(raw)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you enforcing the gateway.networking.k8s.io in here?

Instead it should be the consul.hashicorp.com/v1beta1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enforceConsulApiVersion() is the /consulapi/ path where the Gateway is already converted to consul.hashicorp.com. So GatewayPolicy.spec.targetRef.group must also point to consul.hashicorp.com in that path, not gateway.networking.k8s.io/v1.

Proposed fix:

// Replace convertGatewayPolicyTargetRef(raw) with a new helper:
case kindGatewayPolicy:
    convertToConsulGatewayPolicy(raw)
func convertToConsulGatewayPolicy(raw map[string]interface{}) {
    raw["apiVersion"] = consulAPIGroup + "/" + "v1alpha1"
    spec := getSpec(raw)
    if spec == nil {
        return
    }
    targetRef, ok := spec["targetRef"].(map[string]interface{})
    if !ok {
        return
    }
    // rewrite targetRef.group to consul.hashicorp.com
    // so it references the consul-managed gateway
    if targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1Beta1 ||
        targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1 {
        targetRef["group"] = consulAPIGroup
    }
}

Does this look correct to you?

@vdinesh4738 vdinesh4738 removed the backport/1.9.x Backport to release/1.9.x branch label Aug 25, 2026
Comment thread .changelog/5604.txt Outdated
@@ -0,0 +1,3 @@
```release-note:bug
control-plane: add GatewayPolicy to generate-manifests snapshot and rewrite targetRef group from gateway.networking.k8s.io/v1beta1 to v1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the change log to "api-gateway: Fix generate-manifest to correctly generate GatewayPolicy manifests."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the changelog

// and updates the targetRef group to consul.hashicorp.com so the policy correctly
// references the consul-managed Gateway in the consulapi snapshot path.
func convertToConsulGatewayPolicy(raw map[string]interface{}) {
raw["apiVersion"] = consulAPIGroup + "/" + "v1alpha1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gateway policies are already under the apiVersion consul.hashicorp.com/v1alpha1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed redundant apiVersion set in convertToConsulGatewayPolicy

}
if targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1Beta1 ||
targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1 {
targetRef["group"] = consulAPIGroup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be targetRef["group"] = consulAPIGroup+"/" +consulAPIVersionV1Alpha2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The group field in spec.targetRef is an API group — it is consul.hashicorp.com, never consul.hashicorp.com/v1alpha2. API groups never carry a version suffix. The version lives in apiVersion (group/version) but group alone is just consul.hashicorp.com.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiVersion: consul.hashicorp.com/v1alpha1 kind: GatewayPolicy metadata: name: my-gateway-policy namespace: default spec: targetRef: group: "gateway.networking.k8s.io/v1beta1" # must match hardcoded check in webhook kind: Gateway name: my-gateway namespace: default sectionName: "https-listener"

this is the sample for GatewayPolicy.

the example you are telling is for Gateway not for GatewayPolicy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied the changed mentioned,
But it should be consulAPIGroup+"/" + consulAPIVersionV1Alpha1 not ...V1Alpha2

{
name: "v1 group (already rewritten) rewritten to consul",
inputGroup: "gateway.networking.k8s.io/v1",
wantTargetRef: "consul.hashicorp.com",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be consul.hashicorp.com/v1alpha2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetRef.group is an API group identifier, not an apiVersion — it never carries a version suffix.

{
name: "v1beta1 group rewritten to consul",
inputGroup: "gateway.networking.k8s.io/v1beta1",
wantTargetRef: "consul.hashicorp.com",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be consul.hashicorp.com/v1alpha2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetRef.group is an API group identifier, not an apiVersion — it never carries a version suffix.

@binilvrgs
binilvrgs force-pushed the feature/binilvrgs/generate_manifest_job_upgrading_gateway_policy branch from 901cecc to a13c724 Compare August 27, 2026 07:11
…oConsulGatewayPolicy for consistency with group/version convention
@binilvrgs
binilvrgs force-pushed the feature/binilvrgs/generate_manifest_job_upgrading_gateway_policy branch from 15d9fe8 to aa711d9 Compare August 27, 2026 13:59
@binilvrgs binilvrgs changed the title Add GatewayPolicy to generate-manifests snapshot and rewrite targetRef group v1beta1 to v1 Add GatewayPolicy to generate-manifests and rewrite targetRef group v1beta1 to v1 Aug 27, 2026
{"UDPRoute", "UDPRoute", "gateway.networking.k8s.io/v1alpha2", "gateway.networking.k8s.io/v1alpha2"},
{"TLSRoute", "TLSRoute", "gateway.networking.k8s.io/v1alpha2", "gateway.networking.k8s.io/v1alpha2"},
{"TCPRoute", "TCPRoute", "gateway.networking.k8s.io/v1alpha2", "gateway.networking.k8s.io/v1alpha2"},
{"GatewayPolicy", "GatewayPolicy", "gateway.networking.k8s.io/v1beta1", "gateway.networking.k8s.io/v1beta1"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GatewayPolicy API group is "consul.hashicorp.com/v1alpha1". Please update it. Also add a test case for the GatewayPolicy check at targetRef level.

…nsul apiVersion and assert targetRef group rewrite
"kind": tc.kind,
"apiVersion": tc.APIGroup,
"spec": map[string]interface{}{
"targetRef": map[string]interface{}{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be there only for gatewayPolicy. Though it is a test case we should not enforce it on all the objects. Have a kind check for "gatewayPolicy" and have the targetRef only for GatewayPolicy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/1.8.x Backport to release/1.8.x branch backport/2.0.x Backport to release/2.0.x branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants