Skip to content

api/avic: add certificateAuthorityData, CEL validation rules, and envtest suite - #71

Open
wfangchi wants to merge 2 commits into
vmware-tanzu:masterfrom
wfangchi:topic/fw035545/avilbc-cel
Open

wfangchi wants to merge 2 commits into
vmware-tanzu:masterfrom
wfangchi:topic/fw035545/avilbc-cel

Conversation

@wfangchi

@wfangchi wfangchi commented Aug 27, 2026

Copy link
Copy Markdown

Summary

This PR introduces the certificateAuthorityData field to AviLoadBalancerConfigSpec along with admission-time validation markers and an envtest CEL test suite for AviLoadBalancerConfig.

API changes

AviLoadBalancerConfigSpec

  • certificateAuthorityData (new field) — Added optional string field (json:"certificateAuthorityData,omitempty") containing PEM-encoded CA certificates used to verify the Avi Controller's TLS certificate.
    • Enables synchronous certificate format validation in downstream validating webhooks (net-operator) on both Create and Update operations without depending on external Secret lifecycles or ordering guarantees.
    • Serves as public identity material directly visible in the CR.
    • Maintains backward compatibility: when omitted or empty, downstream controllers and services fall back to the CA certificate stored in the Secret referenced by credentialSecretRef.
  • cloudName — Added +kubebuilder:validation:MinLength=1 constraint to reject explicitly-empty strings while preserving the Default-Cloud default when omitted or zero-valued via typed Go clients (omitempty).
  • server — Intentionally left without MinLength=1 to ensure backward compatibility with existing running configurations; runtime validation remains guarded by controller and VAPI layers.

ClientSecretReference

  • name — Added canonical Kubernetes DNS-1123 subdomain validation markers (+kubebuilder:validation:MinLength=1, MaxLength=253, and Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$). Ensures secret references conform to standard Kubernetes resource naming requirements.

Tests

  • 7 envtest integration test cases added in test/cel/aviloadbalancerconfig_test.go covering all validation rules and defaulting behavior:
    • Valid AviLoadBalancerConfig admission.
    • Admission of empty spec.server (backward-compatibility preservation).
    • spec.cloudName defaulting to "Default-Cloud" when omitted or zero-valued via typed Go client (omitempty behavior).
    • spec.cloudName rejection by MinLength=1 when sent explicitly as "" via unstructured JSON payload.
    • Admission of valid DNS-1123 dot-separated spec.credentialSecretRef.name (e.g. avi.creds.v1).
    • Table-driven rejection of invalid spec.credentialSecretRef.name patterns (uppercase characters, leading/trailing hyphens, consecutive dots, and empty strings).
  • make generate — clean regeneration of deepcopy and CRD YAML manifests.
  • make test-unit & make test-cel — all unit tests and CEL integration tests passing.

1. AviLoadBalancerConfig validation markers:
   - spec.cloudName: add MinLength=1 constraint (+kubebuilder:validation:MinLength=1)
   - spec.credentialSecretRef.name: add canonical DNS-1123 subdomain validation
     (+kubebuilder:validation:MinLength=1, MaxLength=253, Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)

2. envtest test suite:
   - add test/cel/aviloadbalancerconfig_test.go covering valid admission, empty server admission,
     cloudName defaulting vs. MinLength=1 rejection, and credentialSecretRef.name pattern validation.

Testing Done:
- make generate — regenerated CRD manifests and client code cleanly
- make test-cel — all CEL envtest cases pass against kube-apiserver
- make test-unit — all unit tests pass

Signed-off-by: Fangchi Wang <fangchi.wang@broadcom.com>
@wfangchi
wfangchi marked this pull request as ready for review August 27, 2026 03:04
- Add optional CertificateAuthorityData field to AviLoadBalancerConfigSpec
  to store PEM-encoded CA certificates used to verify the Avi Controller's
  TLS certificate.
- Enables synchronous certificate format validation in admission webhooks
  on both Create and Update operations without depending on external Secret
  lifecycle timing.
- Maintains backward compatibility: if empty or omitted, controllers fall
  back to reading the CA certificate from the Secret referenced by
  CredentialSecretRef.

Testing Done:
- make generate — regenerated CRD manifests and deepcopy stubs
- make test-unit — unit tests pass

Signed-off-by: Fangchi Wang <fangchi.wang@broadcom.com>
@wfangchi wfangchi changed the title api/avic: add CEL validation rules and envtest suite api/avic: add certificateAuthorityData, CEL validation rules, and envtest suite Sep 8, 2026
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.

1 participant