Skip to content

WIP: [IGNORE] test add v1beta2 API version#6209

Open
willie-yao wants to merge 7 commits intokubernetes-sigs:mainfrom
willie-yao:v1beta2-controllers
Open

WIP: [IGNORE] test add v1beta2 API version#6209
willie-yao wants to merge 7 commits intokubernetes-sigs:mainfrom
willie-yao:v1beta2-controllers

Conversation

@willie-yao
Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind api-change

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests
  • cherry-pick candidate

Release note:

Add v1beta2 API

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Apr 7, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jont828 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested a review from jackfrancis April 7, 2026 07:12
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 7, 2026
@k8s-ci-robot k8s-ci-robot requested a review from jsturtevant April 7, 2026 07:12
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 7, 2026
@willie-yao willie-yao force-pushed the v1beta2-controllers branch 3 times, most recently from 61b422f to 5c0e317 Compare April 7, 2026 16:54
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 3.79947% with 1823 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.23%. Comparing base (55fe6f4) to head (42abc3c).

Files with missing lines Patch % Lines
api/v1alpha1/zz_generated.conversion.go 0.00% 648 Missing ⚠️
api/v1beta1/conversion.go 0.00% 279 Missing ⚠️
api/v1alpha1/conversion.go 0.00% 68 Missing ⚠️
azure/mock_azure/azure_mock.go 0.00% 60 Missing ⚠️
azure/scope/cluster.go 18.75% 51 Missing and 1 partial ⚠️
api/v1beta2/tags.go 0.00% 40 Missing ⚠️
azure/scope/machine.go 2.43% 40 Missing ⚠️
azure/scope/machinepoolmachine.go 11.90% 37 Missing ⚠️
api/v1beta2/types.go 0.00% 36 Missing ⚠️
azure/scope/managedcontrolplane.go 2.70% 36 Missing ⚠️
... and 71 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6209      +/-   ##
==========================================
- Coverage   43.85%   36.23%   -7.62%     
==========================================
  Files         289      344      +55     
  Lines       25341    30697    +5356     
==========================================
+ Hits        11113    11124      +11     
- Misses      13450    18791    +5341     
- Partials      778      782       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@willie-yao willie-yao force-pushed the v1beta2-controllers branch 3 times, most recently from c4ee9d4 to 5cce3bc Compare April 8, 2026 23:20
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 9, 2026
Create api/v1beta2/ and exp/api/v1beta2/ packages with all CAPZ
type definitions updated for the CAPI v1beta2 contract.

Key changes from v1beta1 types:
- status.ready (bool) → status.initialization.provisioned (*bool)
  One-time signal that must never revert to false once set.
- status.conditions (clusterv1beta1.Conditions) → status.conditions ([]metav1.Condition)
  Standard Kubernetes condition type, placed at status.conditions (Stage 2).
- status.failureDomains (map[string]FailureDomainSpec) → status.failureDomains ([]FailureDomain)
  Slice with Name field instead of map key.
- status.failureReason/failureMessage → status.deprecated.v1beta1.failureReason/failureMessage
- New status.deprecated.v1beta1 struct for backward compat fields.
- AzureManagedControlPlane uses Available condition (not Ready) per CP contract.
- ControlPlaneEndpoint uses omitzero to prevent empty struct validation failures.
- spec.providerID changed from *string to string on AzureMachine.

All shared types (NetworkSpec, SubnetSpec, etc.) are duplicated per
version, consistent with CAPZ's v1alpha3/v1alpha4 precedent.

This commit is purely additive — no existing code is modified.
Implement ConvertTo/ConvertFrom on all v1beta1 spoke types for
conversion to/from the v1beta2 hub. Also add v1alpha1→v1beta2
conversion for the ASO managed types.

Manual conversion functions handle fields that changed shape:
- Ready (bool) ↔ Initialization.Provisioned (*bool)
- Initialized (bool) ↔ Initialization.ControlPlaneInitialized (*bool)
- FailureDomains map ↔ slice (with Name field)
- FailureReason/FailureMessage ↔ Deprecated.V1Beta1 location
- Conditions: v1beta1 conditions go to Deprecated.V1Beta1.Conditions

Critical fix: CAPI's Convert_v1beta1_Condition_To_v1_Condition and
Convert_v1_Condition_To_v1beta1_Condition are intentional no-ops that
produce zero-valued conditions ({type:"",status:""}). To prevent these
from corrupting data during roundtrips (v1beta2→v1beta1→v1beta2 caused
by CAPI controllers doing SSA at v1beta1), we:
1. Clear out.Conditions = nil after every autoConvert call in BOTH
   directions (13 functions total)
2. Use hasNonEmptyConditions() helper instead of len(in.Conditions)>0
   to filter out zero-valued artifacts before creating Deprecated structs

Types with conversion (10 v1beta1 + 6 v1alpha1):
- AzureCluster, AzureMachine, AzureClusterTemplate, AzureMachineTemplate
- AzureClusterIdentity, AzureMachinePool, AzureMachinePoolMachine
- AzureManagedCluster, AzureManagedControlPlane, AzureManagedMachinePool
- AzureManagedClusterTemplate, AzureManagedControlPlaneTemplate,
  AzureManagedMachinePoolTemplate (new, were missing)
- AzureASOManagedCluster/ControlPlane/MachinePool (new, were missing)

Generated conversion: conversion-gen v0.34.0 with --extra-peer-dirs
for cross-package CAPI types. 23 manual Convert_ functions override
the auto-generated ones for fields that changed shape.
Configure all CRDs for dual-version serving with v1beta2 as storage:
- +kubebuilder:storageversion on v1beta2, removed from v1beta1
- cluster.x-k8s.io/v1beta2: v1beta2 label on all CRDs
- cluster.x-k8s.io/v1beta1: v1beta1 label retained for compat
- Conversion webhook patches enabled for ALL 19 multi-version CRDs
  (previously only 7 had them; managed types, templates, and ASO
  types were missing because they only had one version before)
- CA injection patches created for 9 types that were missing them
- contract: v1beta2 in metadata.yaml and e2e test config

The conversion webhook patches point all CRDs to /convert on the
capz-webhook-service. controller-runtime automatically registers
this handler when SetupWebhookWithManager is called on a hub type.
Mechanical change: update all import paths from api/v1beta1 to
api/v1beta2 (aliased as infrav1) and exp/api/v1beta1 to
exp/api/v1beta2 (aliased as infrav1exp). The old versions are
now aliased as infrav1beta1/infrav1expbeta1 where still needed.

This touches ~228 files across:
- azure/services/* (all Azure service implementations)
- azure/converters/* (type converters)
- controllers/ (all reconcilers)
- exp/controllers/ (experimental reconcilers)
- internal/webhooks/ (all webhook implementations)
- internal/api/v1beta1/ (defaulting logic)
- pkg/, util/ (shared utilities)
- main.go (scheme registration, webhook setup)
- test/e2e/ (e2e test helpers)

Import alias rules updated in .golangci.yml:
- infrav1 → api/v1beta2
- infrav1beta1 → api/v1beta1
- infrav1exp → exp/api/v1beta2
- infrav1expbeta1 → exp/api/v1beta1

No behavioral changes — just import paths and type references.
Update all 6 scope PatchObject methods for the v1beta2 contract:

1. Conditions migration (Stage 2):
   - Use conditions.SetSummaryCondition() for v1beta2 Ready/Available
     summary conditions at status.conditions ([]metav1.Condition)
   - AzureCluster/Machine/Pool: Ready condition
   - AzureManagedControlPlane: Available condition (per CP contract)

2. V1beta1 dual-write for backward compatibility:
   - New setV1Beta1ConditionsFromV1Beta2() helper converts v1beta2
     []metav1.Condition to clusterv1.Conditions and stores them in
     Deprecated.V1Beta1.Conditions via SetV1Beta1Conditions()
   - This ensures v1beta1 clients see conditions when the
     v1beta2→v1beta1 conversion webhook runs
   - patch.WithOwnedV1Beta1Conditions declares ownership to prevent
     merge conflicts when the Ready condition changes

This approach is simpler than CAPD's pattern of individual
MarkTrue/MarkFalse at every code path (~50-100 sites). Instead,
we convert all v1beta2 conditions in one shot at PatchObject time,
which automatically covers all conditions without risk of missing one.
- Add WithStatusSubresource to fake client builders in 5 tests.
  Required because the CAPI patch helper now uses Status().Patch()
  for condition handling, which needs the status subresource enabled
  on the fake client.
- Update TestConditions expectations to include the new Ready summary
  condition alongside individual conditions (VMRunning etc.)
- Fix type references from v1beta1 to v1beta2 in test code.
Run make generate to update all generated files:
- GoMock files in azure/services/*/mock_*/
- azure/mock_azure/azure_mock.go
- api/v1beta1 and exp/api/v1beta1 type markers (hub → spoke)
- api/v1alpha1 groupversion registration updates
- Makefile conversion-gen target updates
- exp/api/v1beta1 webhook and default function signature updates

No hand-written changes — purely generated output and marker updates.
@willie-yao willie-yao force-pushed the v1beta2-controllers branch from 497fa14 to 42abc3c Compare April 9, 2026 22:35
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@willie-yao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-apidiff 42abc3c link false /test pull-cluster-api-provider-azure-apidiff
pull-cluster-api-provider-azure-e2e-workload-upgrade 42abc3c link true /test pull-cluster-api-provider-azure-e2e-workload-upgrade
pull-cluster-api-provider-azure-apiversion-upgrade 42abc3c link true /test pull-cluster-api-provider-azure-apiversion-upgrade
pull-cluster-api-provider-azure-e2e-aks 42abc3c link true /test pull-cluster-api-provider-azure-e2e-aks

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants