nginxinc / nginx-gateway-fabric

NGINX Gateway Fabric provides an implementation for the Gateway API using NGINX as the data plane.
Apache License 2.0
511 stars 96 forks source link

update observability policy API to have minimum one target ref #2802

Closed salonichf5 closed 1 week ago

salonichf5 commented 1 week ago

Proposed changes

Write a clear and concise description that helps reviewers understand the purpose and impact of your changes. Use the following format:

Problem: User wants ObservabilityPolicy CRD should require a minimum of 1 TargetRef.

Solution: Add validation to have minimum one target ref for the ObservabilityPolicy CRDs.

Testing:

Tested manually using the example. Installed observabilityPolicy with on branch main, a target ref and ensuring everything works as expected.

Tested with specifying no target refs

kubectl apply -f - <<EOF
apiVersion: gateway.nginx.org/v1alpha1
kind: ObservabilityPolicy
metadata:
  name: coffee
spec:
  targetRefs: []
  tracing:
    strategy: ratio
    ratio: 75
    spanAttributes:
    - key: coffee-key
      value: coffee-value
EOF
The ObservabilityPolicy "coffee" is invalid:
* spec.targetRefs: Invalid value: 0: spec.targetRefs in body should have at least 1 items
* spec.targetRefs: Invalid value: "array": TargetRef Kind must be: HTTPRoute or GRPCRoute

Please focus on (optional): If you any specific areas where you would like reviewers to focus their attention or provide specific feedback, add them here.

Closes #2524

Checklist

Before creating a PR, run through this checklist and mark each as complete.

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes, please add a brief note that summarizes the change.

ObservabilityPolicy API requires minimum one target ref specified when creating a policy.