Add GatewayPolicy to generate-manifests and rewrite targetRef group v1beta1 to v1 - #5604
Add GatewayPolicy to generate-manifests and rewrite targetRef group v1beta1 to v1#5604binilvrgs wants to merge 14 commits into
Conversation
…f group v1beta1 to v1
… for gatewayapi snapshot path
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| convertToConsulRoute(raw) | ||
|
|
||
| case kindGatewayPolicy: | ||
| convertGatewayPolicyTargetRef(raw) |
There was a problem hiding this comment.
Why are you enforcing the gateway.networking.k8s.io in here?
Instead it should be the consul.hashicorp.com/v1beta1
There was a problem hiding this comment.
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?
…rom v1beta1 to v1
…ading_gateway_policy
| @@ -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 | |||
There was a problem hiding this comment.
please update the change log to "api-gateway: Fix generate-manifest to correctly generate GatewayPolicy manifests."
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
gateway policies are already under the apiVersion consul.hashicorp.com/v1alpha1
There was a problem hiding this comment.
Removed redundant apiVersion set in convertToConsulGatewayPolicy
| } | ||
| if targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1Beta1 || | ||
| targetRef["group"] == K8sGatewayAPIGroup+"/"+K8sGatewayAPIVersionV1 { | ||
| targetRef["group"] = consulAPIGroup |
There was a problem hiding this comment.
shouldn't this be targetRef["group"] = consulAPIGroup+"/" +consulAPIVersionV1Alpha2
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
It should be consul.hashicorp.com/v1alpha2
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
It should be consul.hashicorp.com/v1alpha2
There was a problem hiding this comment.
targetRef.group is an API group identifier, not an apiVersion — it never carries a version suffix.
901cecc to
a13c724
Compare
…oConsulGatewayPolicy for consistency with group/version convention
15d9fe8 to
aa711d9
Compare
…ConsulGatewayPolicy to match converted Gateway apiVersion
…ading_gateway_policy
| {"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"}, |
There was a problem hiding this comment.
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{}{ |
There was a problem hiding this comment.
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

Changes proposed in this PR
GatewayPolicyto thegenerate-manifestspre-upgrade snapshot job which was previously missing, causingGatewayPolicyresources to be silently lost during Consul Helm upgradesconvertGatewayPolicyTargetRef()to rewritespec.targetRef.groupfromgateway.networking.k8s.io/v1beta1togateway.networking.k8s.io/v1in both thegatewayapiandconsulapisnapshot paths, to match the graduated Gateway API versiongatewayForGatewayPolicy()index function to accept bothv1andv1beta1group strings for backward compatibility during transitionkindGatewayPolicyconstant andGatewayPolicyListcase inextractItems()following existing patternsHow I've tested this PR
Tested against a live EKS cluster (
v1.34.9-eks-b3f9404,us-east-1):GatewayPolicyin the cluster withspec.targetRef.group: gateway.networking.k8s.io/v1beta1to simulate pre-upgrade customer stategenerate-manifests— confirmedgatewaypolicies/folder was absent from snapshot (bug proven)generate-manifests— confirmedgatewaypolicies/folder present in bothgatewayapi/andconsulapi/snapshot pathsspec.targetRef.groupwas correctly rewritten fromv1beta1tov1Unit 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
GatewayPolicywithspec.targetRef.group: gateway.networking.k8s.io/v1beta1in a test clustergenerate-manifestswith the new binarygatewaypolicies/folder is created under the output directoryspec.targetRef.groupin the generated YAML isgateway.networking.k8s.io/v1Checklist
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.