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

refactor: reuse xPolicy status methods for backendTLSPolicy #2950

Merged
merged 3 commits into from
Mar 20, 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
45 changes: 19 additions & 26 deletions internal/gatewayapi/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
Expand All @@ -30,19 +29,17 @@ func (t *Translator) processBackendTLSPolicy(

policy := getBackendTLSPolicy(resources.BackendTLSPolicies, backendRef, backendNamespace)

ancestor := gwapiv1a2.PolicyAncestorStatus{
AncestorRef: parent,
ControllerName: gwapiv1.GatewayController(t.GatewayControllerName),
ancestorRefs := []gwapiv1a2.ParentReference{
parent,
}

if err != nil {
status.SetBackendTLSPolicyCondition(
policy,
ancestor,
gwapiv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwapiv1a2.PolicyReasonInvalid,
status.Error2ConditionMsg(err))
status.SetTranslationErrorForPolicyAncestors(&policy.Status,
ancestorRefs,
t.GatewayControllerName,
policy.Generation,
status.Error2ConditionMsg(err),
)
return nil
}

Expand All @@ -67,25 +64,21 @@ func (t *Translator) processBackendTLSPolicy(
},
resources.ReferenceGrants,
) {
status.SetBackendTLSPolicyCondition(
policy,
ancestor,
gwapiv1a2.PolicyConditionAccepted,
metav1.ConditionFalse,
gwapiv1a2.PolicyReasonInvalid,
fmt.Sprintf("target ref to %s %s/%s not permitted by any ReferenceGrant",
backendRefKind, backendNamespace, backendRef.Name))
err = fmt.Errorf("target ref to %s %s/%s not permitted by any ReferenceGrant",
backendRefKind, backendNamespace, backendRef.Name)

status.SetTranslationErrorForPolicyAncestors(&policy.Status,
ancestorRefs,
t.GatewayControllerName,
policy.Generation,
status.Error2ConditionMsg(err),
)
return nil
}
}

status.SetBackendTLSPolicyCondition(
policy,
ancestor,
gwapiv1a2.PolicyConditionAccepted,
metav1.ConditionTrue,
gwapiv1a2.PolicyReasonAccepted,
"BackendTLSPolicy is Accepted")
status.SetAcceptedForPolicyAncestors(&policy.Status, ancestorRefs, t.GatewayControllerName)

return tlsBundle
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ backendTLSPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: BackendTLSPolicy is Accepted
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ backendTLSPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: BackendTLSPolicy is Accepted
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ backendTLSPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: BackendTLSPolicy is Accepted
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ backendTLSPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: target ref to Service backends/http-backend not permitted by any
message: Target ref to Service backends/http-backend not permitted by any
ReferenceGrant
reason: Invalid
status: "False"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ backendTLSPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: BackendTLSPolicy is Accepted
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
Expand Down Expand Up @@ -59,7 +59,7 @@ backendTLSPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: BackendTLSPolicy is Accepted
message: Policy has been accepted.
reason: Accepted
status: "True"
type: Accepted
Expand Down
32 changes: 0 additions & 32 deletions internal/status/backendtlspolicy.go

This file was deleted.

Loading