Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip the ReasonTargetNotFound for all policies #2802

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

// Translate
// 1. First translate Policies targeting xRoutes
// 2.. Finally, the policies targeting Gateways
// 2. Finally, the policies targeting Gateways

// Process the policies targeting xRoutes
for _, policy := range backendTrafficPolicies {
Expand Down Expand Up @@ -167,9 +167,9 @@

// Ensure Policy and target are in the same namespace
if policy.Namespace != string(*targetNs) {

message := fmt.Sprintf("Namespace:%s TargetRef.Namespace:%s, BackendTrafficPolicy can only target a resource in the same namespace.",
policy.Namespace, *targetNs)

Check warning on line 172 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L172

Added line #L172 was not covered by tests
status.SetBackendTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
Expand All @@ -188,14 +188,6 @@

// Gateway not found
if !ok {
message := fmt.Sprintf("Gateway:%s not found.", policy.Spec.TargetRef.Name)

status.SetBackendTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}

Expand Down Expand Up @@ -228,9 +220,9 @@

// Ensure Policy and target are in the same namespace
if policy.Namespace != string(*targetNs) {

message := fmt.Sprintf("Namespace:%s TargetRef.Namespace:%s, BackendTrafficPolicy can only target a resource in the same namespace.",
policy.Namespace, *targetNs)

Check warning on line 225 in internal/gatewayapi/backendtrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/backendtrafficpolicy.go#L225

Added line #L225 was not covered by tests
status.SetBackendTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
Expand All @@ -250,14 +242,6 @@

// Route not found
if !ok {
message := fmt.Sprintf("%s/%s/%s not found.", policy.Spec.TargetRef.Kind, string(*targetNs), policy.Spec.TargetRef.Name)

status.SetBackendTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}

Expand Down
18 changes: 1 addition & 17 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
)

continue

}

// Check if another policy targeting the same Gateway exists
Expand Down Expand Up @@ -227,9 +226,9 @@

// Ensure Policy and target Gateway are in the same namespace
if policy.Namespace != string(*targetNs) {

message := fmt.Sprintf("Namespace:%s TargetRef.Namespace:%s, ClientTrafficPolicy can only target a Gateway in the same namespace.",
policy.Namespace, *targetNs)

Check warning on line 231 in internal/gatewayapi/clienttrafficpolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/clienttrafficpolicy.go#L231

Added line #L231 was not covered by tests
status.SetClientTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
Expand All @@ -250,14 +249,6 @@

// Gateway not found
if gateway == nil {
message := fmt.Sprintf("Gateway:%s not found.", policy.Spec.TargetRef.Name)

status.SetClientTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}

Expand All @@ -271,13 +262,6 @@
}
}
if !found {
message := fmt.Sprintf("SectionName(Listener):%s not found.", *(policy.Spec.TargetRef.SectionName))
status.SetClientTrafficPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}
}
Expand Down
11 changes: 0 additions & 11 deletions internal/gatewayapi/envoypatchpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ func (t *Translator) ProcessEnvoyPatchPolicies(envoyPatchPolicies []*egv1a1.Envo

gwXdsIR, ok := xdsIR[irKey]
if !ok {
// This status condition will not get updated in the resource because
// the IR is missing, but it has been kept here in case we publish
// the status from this layer instead of the xds layer.
message := fmt.Sprintf("%s:%s not found.", targetKind, policy.Spec.TargetRef.Name)

status.SetEnvoyPatchPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
continue
}

Expand Down
23 changes: 2 additions & 21 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@

// Ensure Policy and target are in the same namespace
if policy.Namespace != string(*targetNs) {

message := fmt.Sprintf(
"Namespace:%s TargetRef.Namespace:%s, SecurityPolicy can only target a resource in the same namespace.",
policy.Namespace, *targetNs)

Check warning on line 188 in internal/gatewayapi/securitypolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/securitypolicy.go#L188

Added line #L188 was not covered by tests
status.SetSecurityPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
Expand All @@ -204,14 +204,6 @@

// Gateway not found
if !ok {
message := fmt.Sprintf("Gateway:%s not found.", policy.Spec.TargetRef.Name)

status.SetSecurityPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}

Expand Down Expand Up @@ -246,10 +238,10 @@

// Ensure Policy and target are in the same namespace
if policy.Namespace != string(*targetNs) {

message := fmt.Sprintf(
"Namespace:%s TargetRef.Namespace:%s, SecurityPolicy can only target a resource in the same namespace.",
policy.Namespace, *targetNs)

Check warning on line 244 in internal/gatewayapi/securitypolicy.go

View check run for this annotation

Codecov / codecov/patch

internal/gatewayapi/securitypolicy.go#L244

Added line #L244 was not covered by tests
status.SetSecurityPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
Expand All @@ -269,17 +261,6 @@

// Route not found
if !ok {
message := fmt.Sprintf(
"%s/%s/%s not found.",
policy.Spec.TargetRef.Kind,
string(*targetNs), policy.Spec.TargetRef.Name)

status.SetSecurityPolicyCondition(policy,
gwv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwv1a2.PolicyReasonTargetNotFound,
message,
)
return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-httproute
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: unknown-httproute
namespace: envoy-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
creationTimestamp: null
name: target-unknown-httproute
namespace: envoy-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: unknown-httproute
namespace: envoy-gateway
status: {}
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
creationTimestamp: null
name: target-unknown-gateway
namespace: envoy-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
status: {}
infraIR: {}
xdsIR: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
clientTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
creationTimestamp: null
name: target-unknown-gateway
namespace: envoy-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
status: {}
infraIR: {}
xdsIR: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
envoyPatchPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyPatchPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-gateway
spec:
type: "JSONPatch"
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
infraIR: {}
xdsIR: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
securityPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
namespace: envoy-gateway
name: target-unknown-httproute
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: unknown-httproute
namespace: envoy-gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
infraIR: {}
securityPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
creationTimestamp: null
name: target-unknown-httproute
namespace: envoy-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: unknown-httproute
namespace: envoy-gateway
status: {}
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
creationTimestamp: null
name: target-unknown-gateway
namespace: envoy-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: unknown-gateway
namespace: envoy-gateway
status: {}
xdsIR: {}
8 changes: 6 additions & 2 deletions internal/gatewayapi/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ func TestTranslate(t *testing.T) {
want := &TranslateResult{}
mustUnmarshal(t, output, want)

opts := cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")
require.Empty(t, cmp.Diff(want, got, opts))
opts := []cmp.Option{
cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime"),
cmpopts.EquateEmpty(),
}

require.Empty(t, cmp.Diff(want, got, opts...))
})
}
}
Expand Down