Skip to content

Commit

Permalink
Allow policy target namespace to be optional (#1926)
Browse files Browse the repository at this point in the history
* Defaults to the policy namespace as
recommend by upstream
https://github.com/kubernetes-sigs/gateway-api/blob/d38e6c81ba3d3f137012ceeec8262ab40ad0cd81/apis/v1alpha2/policy_types.go#L47

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Oct 4, 2023
1 parent 28a9f16 commit 8c04553
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
12 changes: 3 additions & 9 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/utils/ptr"
)

const (
Expand Down Expand Up @@ -170,16 +171,9 @@ func ProcessClientTrafficPolicies(clientTrafficPolicies []*egv1a1.ClientTrafficP

func getGatewayTargetRef(policy *egv1a1.ClientTrafficPolicy, gateways []*GatewayContext) *GatewayContext {
targetNs := policy.Spec.TargetRef.Namespace

// Ensure Namespace is set
// If empty, default to namespace of policy
if targetNs == nil {
status.SetClientTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonInvalid,
"TargetRef.Namespace must be set",
)
return nil
targetNs = ptr.To(gwv1b1.Namespace(policy.Namespace))
}

// Ensure policy can only target a Gateway
Expand Down
15 changes: 4 additions & 11 deletions internal/gatewayapi/envoypatchpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/ir"
"github.com/envoyproxy/gateway/internal/status"
"github.com/envoyproxy/gateway/internal/utils/ptr"
)

func (t *Translator) ProcessEnvoyPatchPolicies(envoyPatchPolicies []*egv1a1.EnvoyPatchPolicy, xdsIR XdsIRMap) {
Expand All @@ -27,18 +28,10 @@ func (t *Translator) ProcessEnvoyPatchPolicies(envoyPatchPolicies []*egv1a1.Envo
for _, policy := range envoyPatchPolicies {
policy := policy.DeepCopy()
targetNs := policy.Spec.TargetRef.Namespace
if targetNs == nil {
// This status condition will not get updated in the resource because
// we dont have access to the IR yet, but it has been kept here in case we publish
// the status from this layer instead of the xds layer.

status.SetEnvoyPatchPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonInvalid,
"TargetRef.Namespace must be set",
)
continue
// If empty, default to namespace of policy
if targetNs == nil {
targetNs = ptr.To(gwv1b1.Namespace(policy.Namespace))
}

// Get the IR
Expand Down

0 comments on commit 8c04553

Please sign in to comment.