Skip to content

Conversation

@AlinsRan
Copy link
Contributor

@AlinsRan AlinsRan commented Apr 15, 2025

Type of change:

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches
  • Documentation
  • Refactor
  • Chore
  • CI/CD or Tests

What this PR does / why we need it:

Only a portion of the conversion logic has been implemented.

TODO:

  • HTTPRoute support BackendTrafficPolicy
  • Ingress support BackendTrafficPolicy

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@github-actions
Copy link
Contributor

github-actions bot commented Apr 15, 2025

conformance test report

apiVersion: gateway.networking.k8s.io/v1
date: "2025-04-16T08:44:19Z"
gatewayAPIChannel: standard
gatewayAPIVersion: v1.2.0
implementation:
  contact: null
  organization: API7
  project: api7-ingress-controller
  url: https://github.com/api7/api7-ingress-controller.git
  version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
    failedTests:
    - HTTPRoutePathMatchOrder
    - HTTPRouteSimpleSameNamespace
    result: failure
    skippedTests:
    - GatewayInvalidTLSConfiguration
    - GatewaySecretInvalidReferenceGrant
    - GatewaySecretMissingReferenceGrant
    - GatewaySecretReferenceGrantAllInNamespace
    - GatewaySecretReferenceGrantSpecific
    - HTTPRouteExactPathMatching
    - HTTPRouteHTTPSListener
    - HTTPRouteHeaderMatching
    - HTTPRouteHostnameIntersection
    - HTTPRouteInvalidBackendRefUnknownKind
    - HTTPRouteInvalidCrossNamespaceBackendRef
    - HTTPRouteInvalidCrossNamespaceParentRef
    - HTTPRouteInvalidNonExistentBackendRef
    - HTTPRouteInvalidParentRefNotMatchingSectionName
    - HTTPRouteInvalidReferenceGrant
    - HTTPRouteListenerHostnameMatching
    - HTTPRouteMatching
    - HTTPRouteMatchingAcrossRoutes
    - HTTPRoutePartiallyInvalidViaInvalidReferenceGrant
    - HTTPRouteReferenceGrant
    - HTTPRouteRequestHeaderModifier
    - HTTPRouteWeight
    statistics:
      Failed: 2
      Passed: 9
      Skipped: 22
  name: GATEWAY-HTTP
  summary: Core tests failed with 2 test failures.

@AlinsRan AlinsRan marked this pull request as ready for review April 15, 2025 00:25
@AlinsRan AlinsRan requested review from Copilot and dspo April 15, 2025 09:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for translating the new BackendTrafficPolicy CRD within the ingress controller by extending the translation context, translator, and controller logic while also updating the CRD definitions and associated types.

  • Changes to the TranslateContext to encapsulate context and include BackendTrafficPolicies and StatusUpdaters.
  • Enhancements in translator and controller logic to attach BackendTrafficPolicy configurations and update indexers.
  • Updates to CRD YAML defaults and deepcopy functions to support the new CRD.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/provider/provider.go Updated TranslateContext and constructor to accept a context and initialize maps.
internal/provider/adc/translator/policies.go Added functions to attach BackendTrafficPolicy to upstreams.
internal/provider/adc/translator/ingress.go & httproute.go Updated to invoke attachBackendTrafficPolicyToUpstream in translation routines.
internal/controller/* Propagated context usage in status, policies, and ingress reconciler logic.
internal/controller/indexer/indexer.go Added indexer support for BackendTrafficPolicy target references.
CRD YAML and api files Updated CRD defaults, deep copy functions, and type definitions for Back......
Comments suppressed due to low confidence (1)

internal/provider/adc/translator/policies.go:31

  • Consider using a lower log level (e.g. Info or Debug) here since attaching a BackendTrafficPolicy appears to be a normal operation; using an error log might mislead monitoring systems.
log.Errorw("attach backend traffic policy to upstream", zap.String("policy", policy.Name))

@AlinsRan AlinsRan requested a review from Copilot April 15, 2025 09:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

internal/provider/adc/translator/ingress.go:112

  • Calling attachBackendTrafficPolicyToUpstream with a nil policy results in a no-op. Consider adding a conditional to only invoke this function when a valid policy exists, or document the rationale for this call.
t.attachBackendTrafficPolicyToUpstream(nil, upstream)

internal/provider/adc/translator/httproute.go:293

  • Using a nil policy in attachBackendTrafficPolicyToUpstream may be redundant. Review whether this call is necessary or if it should be conditioned on a non-nil policy.
t.attachBackendTrafficPolicyToUpstream(nil, upstream)

Copy link
Contributor

@dspo dspo left a comment

Choose a reason for hiding this comment

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

x-kubernetes-list-map-keys:
- group
- kind
- name
x-kubernetes-list-type: map

这里会以这些字段为 key,也就不能出现同样的 group kind name 组合,符合期望吗?

SecretIndexRef = "secretRefs"
IngressClassRef = "ingressClassRef"
ConsumerGatewayRef = "consumerGatewayRef"
PolicyTargetRefs = "targetRefs"
Copy link
Contributor

@dspo dspo Apr 16, 2025

Choose a reason for hiding this comment

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

Can it be renamed to BackendTrafficPolicyTargetRefs or BTPolicyTargetRefs to distinguish it from HTTPRoutePolicyTargetRefs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to distinguish? This index key is for resources with targetrefs.

backendTrafficPolicyList := &v1alpha1.BackendTrafficPolicyList{}
if err := c.List(tctx, backendTrafficPolicyList,
client.MatchingFields{
indexer.PolicyTargetRefs: indexer.GenIndexKeyWithGK("", "Service", service.Namespace, service.Name),
Copy link
Contributor

@dspo dspo Apr 16, 2025

Choose a reason for hiding this comment

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

Why is empty string for group ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The group of the service is an empty string.

condition := NewPolicyCondition(policy.Generation, true, "Policy has been accepted")
if sectionName != nil && !portNameExist[string(*sectionName)] {
condition = NewPolicyCondition(policy.Generation, false, fmt.Sprintf("SectionName %s not found in Service %s/%s", *sectionName, service.Namespace, service.Name))
goto record_status
Copy link
Contributor

@dspo dspo Apr 16, 2025

Choose a reason for hiding this comment

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

Can the use of goto be avoided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 44 to 46
Connect: policy.Spec.Timeout.Connect.Duration.Milliseconds(),
Read: policy.Spec.Timeout.Read.Duration.Milliseconds(),
Send: policy.Spec.Timeout.Send.Duration.Milliseconds(),
Copy link
Contributor

@dspo dspo Apr 16, 2025

Choose a reason for hiding this comment

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

In dashboard API, the unit is second. It is millsecond in adc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@AlinsRan AlinsRan requested a review from dspo April 16, 2025 09:02
@AlinsRan AlinsRan merged commit 9e4e35b into release-v2-dev Apr 16, 2025
8 checks passed
@AlinsRan AlinsRan deleted the feat/support-backendtrafficpolicy-translate branch April 16, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants